Skip to content

Commit 6d64746

Browse files
Lazy decode block extrinsics (#9480)
Related to #4255 Addresses #7902 (review) This PR enables us to lazily decode the block extrinsics when needed. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2bbc58f commit 6d64746

File tree

76 files changed

+634
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+634
-273
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/client/consensus/aura/src/collators/slot_based/block_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
let block = Block::new(params.header.clone(), params.body.clone().unwrap_or_default());
117117

118118
runtime_api
119-
.execute_block(parent_hash, block.clone())
119+
.execute_block(parent_hash, block.clone().into())
120120
.map_err(|e| Box::new(e) as Box<_>)?;
121121

122122
let storage_proof =

cumulus/client/service/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ where
628628
runtime_api.record_proof_with_recorder(storage_proof_recorder);
629629

630630
runtime_api
631-
.execute_block(*block.header().parent_hash(), block)
631+
.execute_block(*block.header().parent_hash(), block.into())
632632
.map_err(Into::into)
633633
}
634634
}

cumulus/pallets/aura-ext/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
use frame_support::traits::{ExecuteBlock, FindAuthor};
3737
use sp_application_crypto::RuntimeAppPublic;
3838
use sp_consensus_aura::{digests::CompatibleDigestItem, Slot};
39-
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
39+
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, LazyBlock};
4040

4141
pub mod consensus_hook;
4242
pub mod migration;
@@ -124,8 +124,8 @@ where
124124
T: Config,
125125
I: ExecuteBlock<Block>,
126126
{
127-
fn execute_block(block: Block) {
128-
let (mut header, extrinsics) = block.deconstruct();
127+
fn execute_block(mut block: Block::LazyBlock) {
128+
let header = block.header_mut();
129129
// We need to fetch the authorities before we execute the block, to get the authorities
130130
// before any potential update.
131131
let authorities = Authorities::<T>::get();
@@ -163,6 +163,6 @@ where
163163
panic!("Invalid AuRa seal");
164164
}
165165

166-
I::execute_block(Block::new(header, extrinsics));
166+
I::execute_block(block);
167167
}
168168
}

cumulus/pallets/parachain-system/src/validate_block/implementation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use sp_core::storage::{ChildInfo, StateVersion};
3232
use sp_externalities::{set_and_run_with_externalities, Externalities};
3333
use sp_io::{hashing::blake2_128, KillStorageResult};
3434
use sp_runtime::traits::{
35-
Block as BlockT, ExtrinsicCall, Hash as HashT, HashingFor, Header as HeaderT,
35+
Block as BlockT, ExtrinsicCall, Hash as HashT, HashingFor, Header as HeaderT, LazyBlock,
3636
};
3737
use sp_state_machine::OverlayedChanges;
3838
use sp_trie::{HashDBT, ProofSizeProvider, EMPTY_PREFIX};
@@ -124,11 +124,11 @@ where
124124
.replace_implementation(host_storage_proof_size),
125125
);
126126

127-
let block_data = codec::decode_from_bytes::<ParachainBlockData<B>>(block_data)
127+
let block_data = codec::decode_from_bytes::<ParachainBlockData<B::LazyBlock>>(block_data)
128128
.expect("Invalid parachain block data");
129129

130130
// Initialize hashmaps randomness.
131-
sp_trie::add_extra_randomness(build_seed_from_head_data(
131+
sp_trie::add_extra_randomness(build_seed_from_head_data::<B>(
132132
&block_data,
133133
relay_parent_storage_root,
134134
));
@@ -363,7 +363,7 @@ fn validate_validation_data(
363363
/// in the block data, to make sure the seed changes every block and that
364364
/// the user cannot find about it ahead of time.
365365
fn build_seed_from_head_data<B: BlockT>(
366-
block_data: &ParachainBlockData<B>,
366+
block_data: &ParachainBlockData<B::LazyBlock>,
367367
relay_parent_storage_root: crate::relay_chain::Hash,
368368
) -> [u8; 16] {
369369
let mut bytes_to_hash = Vec::with_capacity(

cumulus/pallets/parachain-system/src/validate_block/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn build_multiple_blocks_with_witness(
217217
let proof_recorder = ProofRecorder::<Block>::with_ignored_nodes(ignored_nodes.clone());
218218
api.record_proof_with_recorder(proof_recorder.clone());
219219
api.register_extension(ProofSizeExt::new(proof_recorder));
220-
api.execute_block(parent_hash, built_block.block.clone()).unwrap();
220+
api.execute_block(parent_hash, built_block.block.clone().into()).unwrap();
221221

222222
let (header, extrinsics) = built_block.block.clone().deconstruct();
223223

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ impl_runtime_apis! {
13721372
VERSION
13731373
}
13741374

1375-
fn execute_block(block: Block) {
1375+
fn execute_block(block: <Block as BlockT>::LazyBlock) {
13761376
Executive::execute_block(block)
13771377
}
13781378

@@ -1409,7 +1409,7 @@ impl_runtime_apis! {
14091409
}
14101410

14111411
fn check_inherents(
1412-
block: Block,
1412+
block: <Block as BlockT>::LazyBlock,
14131413
data: sp_inherents::InherentData,
14141414
) -> sp_inherents::CheckInherentsResult {
14151415
data.check_extrinsics(&block)
@@ -1623,7 +1623,7 @@ impl_runtime_apis! {
16231623
}
16241624

16251625
fn execute_block(
1626-
block: Block,
1626+
block: <Block as BlockT>::LazyBlock,
16271627
state_root_check: bool,
16281628
signature_check: bool,
16291629
select: frame_try_runtime::TryStateSelect,

cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(
17641764
VERSION
17651765
}
17661766

1767-
fn execute_block(block: Block) {
1767+
fn execute_block(block: <Block as BlockT>::LazyBlock) {
17681768
Executive::execute_block(block)
17691769
}
17701770

@@ -1801,7 +1801,7 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(
18011801
}
18021802

18031803
fn check_inherents(
1804-
block: Block,
1804+
block: <Block as BlockT>::LazyBlock,
18051805
data: sp_inherents::InherentData,
18061806
) -> sp_inherents::CheckInherentsResult {
18071807
data.check_extrinsics(&block)
@@ -2085,7 +2085,7 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(
20852085
}
20862086

20872087
fn execute_block(
2088-
block: Block,
2088+
block: <Block as BlockT>::LazyBlock,
20892089
state_root_check: bool,
20902090
signature_check: bool,
20912091
select: frame_try_runtime::TryStateSelect,

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl_runtime_apis! {
745745
VERSION
746746
}
747747

748-
fn execute_block(block: Block) {
748+
fn execute_block(block: <Block as BlockT>::LazyBlock) {
749749
Executive::execute_block(block)
750750
}
751751

@@ -782,7 +782,7 @@ impl_runtime_apis! {
782782
}
783783

784784
fn check_inherents(
785-
block: Block,
785+
block: <Block as BlockT>::LazyBlock,
786786
data: sp_inherents::InherentData,
787787
) -> sp_inherents::CheckInherentsResult {
788788
data.check_extrinsics(&block)
@@ -1038,7 +1038,7 @@ impl_runtime_apis! {
10381038
}
10391039

10401040
fn execute_block(
1041-
block: Block,
1041+
block: <Block as BlockT>::LazyBlock,
10421042
state_root_check: bool,
10431043
signature_check: bool,
10441044
select: frame_try_runtime::TryStateSelect,

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl_runtime_apis! {
696696
VERSION
697697
}
698698

699-
fn execute_block(block: Block) {
699+
fn execute_block(block: <Block as BlockT>::LazyBlock) {
700700
Executive::execute_block(block)
701701
}
702702

@@ -733,7 +733,7 @@ impl_runtime_apis! {
733733
}
734734

735735
fn check_inherents(
736-
block: Block,
736+
block: <Block as BlockT>::LazyBlock,
737737
data: sp_inherents::InherentData,
738738
) -> sp_inherents::CheckInherentsResult {
739739
data.check_extrinsics(&block)
@@ -981,7 +981,7 @@ impl_runtime_apis! {
981981
}
982982

983983
fn execute_block(
984-
block: Block,
984+
block: <Block as BlockT>::LazyBlock,
985985
state_root_check: bool,
986986
signature_check: bool,
987987
select: frame_try_runtime::TryStateSelect,

0 commit comments

Comments
 (0)