Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ where
let wait_to_announce = self.wait_to_announce.clone();

Box::pin(async move {
let parent_state_root = *last_head.header.state_root();

let proposer = proposer_future.await.map_err(|e| {
error!(
target: "cumulus-collator",
Expand Down Expand Up @@ -251,7 +249,6 @@ where
header.clone(),
extrinsics,
proof.iter_nodes().collect(),
parent_state_root,
);

let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, header);
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,18 @@ pub struct ParachainBlockData<B: BlockT> {
extrinsics: Vec<<B as BlockT>::Extrinsic>,
/// The data that is required to emulate the storage accesses executed by all extrinsics.
witness_data: WitnessData,
/// The storage root of the witness data.
witness_data_storage_root: <B as BlockT>::Hash,
}

impl<B: BlockT> ParachainBlockData<B> {
pub fn new(
header: <B as BlockT>::Header,
extrinsics: Vec<<B as BlockT>::Extrinsic>,
witness_data: WitnessData,
witness_data_storage_root: <B as BlockT>::Hash,
) -> Self {
Self {
header,
extrinsics,
witness_data,
witness_data_storage_root,
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -

let storage_inner = WitnessStorage::<B>::new(
block_data.witness_data,
block_data.witness_data_storage_root,
parent_head.state_root().clone(),
validation_function_params,
)
.expect("Witness data and storage root always match; qed");
Expand Down
47 changes: 17 additions & 30 deletions runtime/src/validate_block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use crate::{ParachainBlockData, WitnessData};

use parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
use sc_block_builder::BlockBuilderProvider;
use sc_executor::{
error::Result, WasmExecutionMethod, WasmExecutor, sp_wasm_interface::HostFunctions,
error::Result, sp_wasm_interface::HostFunctions, WasmExecutionMethod, WasmExecutor,
};
use sc_block_builder::BlockBuilderProvider;
use sp_blockchain::HeaderBackend;
use sp_consensus::SelectChain;
use sp_core::traits::CallInWasm;
Expand Down Expand Up @@ -60,17 +60,18 @@ fn call_validate_block(
1,
);

executor.call_in_wasm(
&WASM_BINARY,
None,
"validate_block",
&params,
&mut ext_ext,
sp_core::traits::MissingHostFunctions::Disallow,
)
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data.0[..]).expect("Decode `Header`."))
.map_err(|err| err.into())
executor
.call_in_wasm(
&WASM_BINARY,
None,
"validate_block",
&params,
&mut ext_ext,
sp_core::traits::MissingHostFunctions::Disallow,
)
.map(|v| ValidationResult::decode(&mut &v[..]).expect("Decode `ValidationResult`."))
.map(|v| Header::decode(&mut &v.head_data.0[..]).expect("Decode `Header`."))
.map_err(|err| err.into())
}

fn create_extrinsics() -> Vec<<Block as BlockT>::Extrinsic> {
Expand Down Expand Up @@ -139,16 +140,10 @@ fn build_block_with_proof(
fn validate_block_with_no_extrinsics() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (header, extrinsics) = block.deconstruct();

let block_data = ParachainBlockData::new(
header.clone(),
extrinsics,
witness_data,
witness_data_storage_root,
);
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);

let res_header = call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
assert_eq!(header, res_header);
Expand All @@ -158,16 +153,10 @@ fn validate_block_with_no_extrinsics() {
fn validate_block_with_extrinsics() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, create_extrinsics());
let (header, extrinsics) = block.deconstruct();

let block_data = ParachainBlockData::new(
header.clone(),
extrinsics,
witness_data,
witness_data_storage_root,
);
let block_data = ParachainBlockData::new(header.clone(), extrinsics, witness_data);

let res_header = call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
assert_eq!(header, res_header);
Expand All @@ -178,12 +167,10 @@ fn validate_block_with_extrinsics() {
fn validate_block_invalid_parent_hash() {
let (client, longest_chain) = create_test_client();
let parent_head = longest_chain.best_chain().expect("Best block exists");
let witness_data_storage_root = *parent_head.state_root();
let (block, witness_data) = build_block_with_proof(&client, Vec::new());
let (mut header, extrinsics) = block.deconstruct();
header.set_parent_hash(Hash::from_low_u64_be(1));

let block_data =
ParachainBlockData::new(header, extrinsics, witness_data, witness_data_storage_root);
let block_data = ParachainBlockData::new(header, extrinsics, witness_data);
call_validate_block(parent_head, block_data).expect("Calls `validate_block`");
}