From 1f19ba3725324060c009592c60d4b400fc1a490e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 21 Sep 2022 13:05:18 +0200 Subject: [PATCH 1/2] Ensure that inherents are first and unsigned --- .../src/validate_block/implementation.rs | 5 +++ .../src/validate_block/tests.rs | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pallets/parachain-system/src/validate_block/implementation.rs b/pallets/parachain-system/src/validate_block/implementation.rs index f37622688de..8c03f012be2 100644 --- a/pallets/parachain-system/src/validate_block/implementation.rs +++ b/pallets/parachain-system/src/validate_block/implementation.rs @@ -118,6 +118,11 @@ where let inherent_data = block .extrinsics() .iter() + // Inherents are at the front of the block and are unsigned. + // + // If `is_signed` is returning `None`, we keep it safe and assume that it is "signed". + // We are searching for unsigned transactions anyway. + .take_while(|e| !e.is_signed().unwrap_or(true)) .filter_map(|e| e.call().is_sub_type()) .find_map(|c| match c { crate::Call::set_validation_data { data: validation_data } => diff --git a/pallets/parachain-system/src/validate_block/tests.rs b/pallets/parachain-system/src/validate_block/tests.rs index 6453b9cd394..fa0e1f1f57a 100644 --- a/pallets/parachain-system/src/validate_block/tests.rs +++ b/pallets/parachain-system/src/validate_block/tests.rs @@ -251,3 +251,40 @@ fn check_inherent_fails_on_validate_block_as_expected() { ); } } + +#[test] +fn check_inherents_are_unsigned_and_before_all_other_extrinsics() { + sp_tracing::try_init_simple(); + + if env::var("RUN_TEST").is_ok() { + let (client, parent_head) = create_test_client(); + + let TestBlockData { block, validation_data } = + build_block_with_witness(&client, Vec::new(), parent_head.clone(), Default::default()); + + let (header, mut extrinsics, proof) = block.deconstruct(); + + extrinsics.insert(0, transfer(&client, Alice, Bob, 69)); + + call_validate_block( + parent_head, + ParachainBlockData::new(header, extrinsics, proof), + validation_data.relay_parent_storage_root, + ) + .unwrap_err(); + } else { + let output = Command::new(env::current_exe().unwrap()) + .args(&[ + "check_inherents_are_unsigned_and_before_all_other_extrinsics", + "--", + "--nocapture", + ]) + .env("RUN_TEST", "1") + .output() + .expect("Runs the test"); + assert!(output.status.success()); + + assert!(dbg!(String::from_utf8(output.stderr).unwrap()) + .contains("Could not find `set_validation_data` inherent")); + } +} From 4be6de97d8b3f1787187e148dce5120864f0e98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 21 Sep 2022 13:26:50 +0200 Subject: [PATCH 2/2] Update pallets/parachain-system/src/validate_block/tests.rs Co-authored-by: Sergei Shulepov --- pallets/parachain-system/src/validate_block/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/parachain-system/src/validate_block/tests.rs b/pallets/parachain-system/src/validate_block/tests.rs index fa0e1f1f57a..e06c2cafdcf 100644 --- a/pallets/parachain-system/src/validate_block/tests.rs +++ b/pallets/parachain-system/src/validate_block/tests.rs @@ -284,7 +284,7 @@ fn check_inherents_are_unsigned_and_before_all_other_extrinsics() { .expect("Runs the test"); assert!(output.status.success()); - assert!(dbg!(String::from_utf8(output.stderr).unwrap()) + assert!(String::from_utf8(output.stderr).unwrap() .contains("Could not find `set_validation_data` inherent")); } }