diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index c8b9cbd11ce9f..893a899c7a8ff 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -37,7 +37,7 @@ use sp_runtime::{ Justification, BuildStorage, generic::{BlockId, SignedBlock, DigestItem}, traits::{ - Block as BlockT, Header as HeaderT, Zero, NumberFor, + Hash, Block as BlockT, Header as HeaderT, Zero, NumberFor, HashFor, SaturatedConversion, One, DigestFor, UniqueSaturatedInto, }, }; @@ -897,10 +897,19 @@ impl Client where let prev_header = self.backend.blockchain().header(BlockId::Hash(*parent_hash)).unwrap().unwrap(); header.set_extrinsics_root(*prev_header.extrinsics_root()); + + // temporarly shuffle extrinsics here as we cannot pass shuffling seed to + // runtime easily + let shuffled_extrinsics = extrinsic_shuffler::shuffle::(&runtime_api, &at, previous_block_extrinsics, seed); + // temporarly update extrinsics_root that stores hash of ordered extrinsics so it can be + // validated properly + let trie_root = HashFor::::ordered_trie_root(shuffled_extrinsics.iter().map(codec::Encode::encode).collect()); + header.set_extrinsics_root(trie_root); + runtime_api.execute_block_with_context( &at, execution_context, - Block::new(header, previous_block_extrinsics), + Block::new(header.clone(), shuffled_extrinsics), )?; } None => { diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 7bf9a095e3e90..959e7a48848be 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -297,7 +297,7 @@ where } /// Actually execute all transitions for `block`. - pub fn execute_block(block: Block, info: Vec>) { + pub fn execute_block(block: Block, _info: Vec>) { sp_io::init_tracing(); sp_tracing::within_span! { sp_tracing::info_span!( "execute_block", ?block); @@ -311,14 +311,20 @@ where // execute extrinsics let (header, extrinsics) = block.deconstruct(); - let extrinsics_with_author: Vec<(Option<_>,_)> = info.into_iter().zip(extrinsics.into_iter()).collect(); - - let mut seed: [u8;32] = Default::default(); - seed.copy_from_slice(header.seed().as_ref()); - let shuffled_extrinsics = shuffle_using_seed::(extrinsics_with_author, seed); - - Self::execute_extrinsics_with_book_keeping(shuffled_extrinsics, *header.number()); + // TODO: shuffling temporarly moved to native code. + // Motivation: + // There is no easy way to pass seed from native to wasm runtime. Shuffling at + // runtime can be reverted once we have fully working Header::seed field + // (including serialization & deserialization that is currently missing) + + // let extrinsics_with_author: Vec<(Option<_>,_)> = info.into_iter().zip(extrinsics.into_iter()).collect(); + // let mut seed: [u8;32] = Default::default(); + // seed.copy_from_slice(header.seed().as_ref()); + // let shuffled_extrinsics = shuffle_using_seed::(extrinsics_with_author, seed); + // Self::execute_extrinsics_with_book_keeping(shuffled_extrinsics, *header.number()); + + Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number()); if !signature_batching.verify() { panic!("Signature verification failed."); }