Wait for block import in parachain consensus (#271)

* Wait for block import in parachain consensus

There was a bug in the parachain consensus that when importing a relay
chain block that sets a new best parachain block, but the required
parachain block was not yet imported. This pr fixes this by waiting for
the block to be imported.

* Finish docs
This commit is contained in:
Bastian Köcher
2021-01-05 23:14:27 +01:00
committed by GitHub
parent ed8fc4f4a3
commit 9dc7cc5735
14 changed files with 812 additions and 316 deletions
-1
View File
@@ -28,7 +28,6 @@ sp-externalities = { git = "https://github.com/paritytech/substrate", default-fe
parachain = { package = "polkadot-parachain", git = "https://github.com/paritytech/polkadot", default-features = false, features = [ "wasm-api" ] , branch = "master" }
[dev-dependencies]
sc-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
+6 -14
View File
@@ -18,13 +18,11 @@ use crate::ParachainBlockData;
use cumulus_primitives::{PersistedValidationData, ValidationData};
use cumulus_test_client::{
generate_block_inherents,
runtime::{Block, Hash, Header, UncheckedExtrinsic, WASM_BINARY},
transfer, Client, DefaultTestClientBuilderExt, LongestChain, TestClientBuilder,
TestClientBuilderExt,
transfer, Client, DefaultTestClientBuilderExt, InitBlockBuilder, LongestChain,
TestClientBuilder, TestClientBuilderExt,
};
use parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
use sc_block_builder::BlockBuilderProvider;
use sc_executor::{
error::Result, sp_wasm_interface::HostFunctions, WasmExecutionMethod, WasmExecutor,
};
@@ -89,12 +87,8 @@ fn build_block_with_proof(
parent_head: Header,
) -> (Block, sp_trie::StorageProof) {
let block_id = BlockId::Hash(client.info().best_hash);
let mut builder = client
.new_block_at(&block_id, Default::default(), true)
.expect("Initializes new block");
generate_block_inherents(
client,
let mut builder = client.init_block_builder_at(
&block_id,
Some(ValidationData {
persisted: PersistedValidationData {
block_number: 1,
@@ -103,13 +97,11 @@ fn build_block_with_proof(
},
..Default::default()
}),
)
.into_iter()
.for_each(|e| builder.push(e).expect("Pushes an inherent"));
);
extra_extrinsics
.into_iter()
.for_each(|e| builder.push(e).expect("Pushes an extrinsic"));
.for_each(|e| builder.push(e).unwrap());
let built_block = builder.build().expect("Creates block");