-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Accept only one block in validate_block when upgrading a runtime
#10280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be7f751
Accept only one block in `validate_block` when upgrading a runtime
bkchr 04a4dc8
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] e015ab2
Remove debug code
bkchr c4710ac
Merge remote-tracking branch 'refs/remotes/origin/bkchr-validation-on…
bkchr 44c6396
Merge branch 'master' into bkchr-validation-only-one-block-per-pov
bkchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,11 +16,12 @@ | |||||
|
|
||||||
| use crate::{validate_block::MemoryOptimizedValidationParams, *}; | ||||||
| use codec::{Decode, DecodeAll, Encode}; | ||||||
| use cumulus_primitives_core::{ParachainBlockData, PersistedValidationData}; | ||||||
| use cumulus_primitives_core::{relay_chain, ParachainBlockData, PersistedValidationData}; | ||||||
| use cumulus_test_client::{ | ||||||
| generate_extrinsic, generate_extrinsic_with_pair, | ||||||
| runtime::{ | ||||||
| self as test_runtime, Block, Hash, Header, TestPalletCall, UncheckedExtrinsic, WASM_BINARY, | ||||||
| self as test_runtime, Block, Hash, Header, SudoCall, SystemCall, TestPalletCall, | ||||||
| UncheckedExtrinsic, WASM_BINARY, | ||||||
| }, | ||||||
| seal_block, transfer, BlockData, BlockOrigin, BuildParachainBlockData, Client, | ||||||
| DefaultTestClientBuilderExt, HeadData, InitBlockBuilder, | ||||||
|
|
@@ -654,3 +655,91 @@ fn ensure_we_only_like_blockchains() { | |||||
| .contains("Not a valid chain of blocks :(")); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn rejects_multiple_blocks_per_pov_when_applying_runtime_upgrade() { | ||||||
| sp_tracing::try_init_simple(); | ||||||
|
|
||||||
| if env::var("RUN_TEST").is_ok() { | ||||||
| let (client, genesis_head) = create_elastic_scaling_test_client(); | ||||||
|
|
||||||
| let code = test_runtime::elastic_scaling_500ms::WASM_BINARY | ||||||
| .expect("You need to build the WASM binaries to run the tests!") | ||||||
| .to_vec(); | ||||||
| let code_len = code.len() as u32; | ||||||
|
|
||||||
| let mut proof_builder = | ||||||
| RelayStateSproofBuilder { current_slot: 1.into(), ..Default::default() }; | ||||||
| proof_builder.host_config.max_code_size = code_len * 2; | ||||||
|
|
||||||
| // Build the block that send the runtime upgrade. | ||||||
| let TestBlockData { block: initial_block_data, .. } = build_block_with_witness( | ||||||
| &client, | ||||||
| vec![generate_extrinsic_with_pair( | ||||||
| &client, | ||||||
| Alice.into(), | ||||||
| SudoCall::sudo { | ||||||
| call: Box::new(SystemCall::set_code_without_checks { code }.into()), | ||||||
| }, | ||||||
| Some(0), | ||||||
| )], | ||||||
| genesis_head.clone(), | ||||||
| proof_builder, | ||||||
| Vec::new(), | ||||||
| ); | ||||||
|
|
||||||
| let initial_block = initial_block_data.blocks()[0].clone(); | ||||||
| let (mut header, extrinsics) = initial_block.clone().deconstruct(); | ||||||
| let seal = header.digest.pop().unwrap(); | ||||||
|
|
||||||
| let mut import = BlockImportParams::new(BlockOrigin::Own, header.clone()); | ||||||
| import.body = Some(extrinsics); | ||||||
| import.post_digests.push(seal); | ||||||
| import.fork_choice = Some(ForkChoiceStrategy::Custom(true)); | ||||||
|
|
||||||
| futures::executor::block_on(BlockImport::import_block(&client, import)).unwrap(); | ||||||
| let initial_block_header = initial_block.header().clone(); | ||||||
|
|
||||||
| let mut proof_builder = RelayStateSproofBuilder { | ||||||
| current_slot: 2.into(), | ||||||
| upgrade_go_ahead: Some(relay_chain::UpgradeGoAhead::GoAhead), | ||||||
| ..Default::default() | ||||||
| }; | ||||||
| proof_builder.host_config.max_code_size = code_len * 2; | ||||||
|
|
||||||
| // 2. Build a PoV that consists of multiple blocks. | ||||||
| let TestBlockData { block: pov_block_data, validation_data: pov_validation_data } = | ||||||
| build_multiple_blocks_with_witness( | ||||||
| &client, | ||||||
| initial_block_header.clone(), // Start building PoV from the initial block's header | ||||||
| proof_builder, | ||||||
| 4, | ||||||
| |_| Vec::new(), | ||||||
| ); | ||||||
|
|
||||||
| // 3. Validate the PoV. | ||||||
| call_validate_block_elastic_scaling( | ||||||
| initial_block_header, // The parent is the head of the initial block before the PoV | ||||||
| pov_block_data, | ||||||
| pov_validation_data.relay_parent_storage_root, | ||||||
| ) | ||||||
| .unwrap_err(); | ||||||
| } else { | ||||||
| let output = Command::new(env::current_exe().unwrap()) | ||||||
| .args([ | ||||||
| "rejects_multiple_blocks_per_pov_when_applying_runtime_upgrade", | ||||||
| "--", | ||||||
| "--nocapture", | ||||||
| ]) | ||||||
| .env("RUN_TEST", "1") | ||||||
| .output() | ||||||
| .expect("Runs the test"); | ||||||
|
|
||||||
| assert!(dbg!(String::from_utf8(output.stderr).unwrap()) | ||||||
|
||||||
| assert!(dbg!(String::from_utf8(output.stderr).unwrap()) | |
| assert!(String::from_utf8(output.stderr).unwrap() |
Outdated
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
| // assert!(dbg!(String::from_utf8(output.stderr).unwrap()) | |
| // .contains("only one block per PoV is allowed")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| title: Accept only one block in `validate_block` when upgrading a runtime | ||
| doc: | ||
| - audience: Node Dev | ||
| description: |- | ||
| As the validation is running the entire time using the same validation code, we can not accept any other blocks after a runtime upgrade was applied. | ||
| crates: | ||
| - name: cumulus-pallet-parachain-system | ||
| bump: patch |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.