From 99fa6083e74af616f2615968f98560cfa4bbe7f4 Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Mon, 13 Sep 2021 13:54:33 +0200 Subject: [PATCH 1/8] Store shuffling seed in header instead of storage --- Cargo.lock | 13 +--- client/block-builder/src/lib.rs | 14 ++-- client/consensus/babe/Cargo.toml | 1 - client/consensus/babe/src/lib.rs | 65 ++++++++--------- client/service/Cargo.toml | 2 +- client/service/src/client/client.rs | 20 +----- client/shuffler/Cargo.toml | 2 - client/shuffler/src/lib.rs | 59 ++-------------- frame/executive/src/lib.rs | 2 +- frame/random-seed/runtime-api/Cargo.toml | 16 ----- frame/random-seed/runtime-api/src/lib.rs | 8 --- frame/random-seed/src/lib.rs | 88 ++---------------------- frame/system/src/lib.rs | 22 +++--- primitives/core/src/lib.rs | 3 + primitives/core/src/seed.rs | 27 ++++++++ primitives/runtime/src/generic/header.rs | 19 ++--- primitives/runtime/src/traits.rs | 6 +- test-utils/runtime/Cargo.toml | 1 - test-utils/runtime/src/lib.rs | 12 ---- 19 files changed, 105 insertions(+), 275 deletions(-) delete mode 100644 frame/random-seed/runtime-api/Cargo.toml delete mode 100644 frame/random-seed/runtime-api/src/lib.rs create mode 100644 primitives/core/src/seed.rs diff --git a/Cargo.lock b/Cargo.lock index cb63cbf1bbe5a..40bd4264e3602 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1381,7 +1381,6 @@ dependencies = [ "extrinsic-info-runtime-api", "log", "pallet-random-seed", - "random-seed-runtime-api", "sp-api", "sp-block-builder", "sp-core", @@ -5433,14 +5432,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "random-seed-runtime-api" -version = "2.0.0" -dependencies = [ - "pallet-random-seed", - "sp-api", -] - [[package]] name = "raw-cpuid" version = "7.0.3" @@ -6083,7 +6074,6 @@ dependencies = [ "pdqselect", "rand 0.7.3", "rand_chacha 0.2.2", - "random-seed-runtime-api", "retain_mut", "sc-block-builder", "sc-client-api", @@ -6708,12 +6698,12 @@ dependencies = [ "jsonrpc-pubsub", "lazy_static", "log", + "pallet-random-seed", "parity-scale-codec", "parity-util-mem", "parking_lot 0.10.2", "pin-project", "rand 0.7.3", - "random-seed-runtime-api", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -8317,7 +8307,6 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "parity-util-mem", - "random-seed-runtime-api", "sc-block-builder", "sc-executor", "sc-service", diff --git a/client/block-builder/src/lib.rs b/client/block-builder/src/lib.rs index 2252f730338f2..88dffabd4ca53 100644 --- a/client/block-builder/src/lib.rs +++ b/client/block-builder/src/lib.rs @@ -35,14 +35,13 @@ use sp_runtime::{ traits::{BlakeTwo256, Header as HeaderT, Hash, Block as BlockT, HashFor, DigestFor, NumberFor, One}, }; use sp_blockchain::Error; -use sp_core::ExecutionContext; +use sp_core::{ExecutionContext, ShufflingSeed}; use sp_api::{ Core, ApiExt, ApiErrorFor, ApiRef, ProvideRuntimeApi, StorageChanges, StorageProof, TransactionOutcome, }; use sp_consensus::RecordProof; -use pallet_random_seed::SeedType; use extrinsic_info_runtime_api::runtime_api::ExtrinsicInfoRuntimeApi; pub use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::Backend; @@ -233,7 +232,7 @@ where /// The storage proof will be `Some(_)` when proof recording was enabled. pub fn build( mut self, - seed: SeedType, + seed: ShufflingSeed, ) -> Result>, ApiErrorFor> { let parent_hash = self.parent_hash; let block_id = &self.block_id; @@ -253,7 +252,7 @@ where &self.api, &self.block_id, previous_block_extrinsics, - seed, + seed.clone().seed ) }; @@ -287,6 +286,8 @@ where self.extrinsics.iter().map(Encode::encode).collect(), ); header.set_extrinsics_root(extrinsics_root); + header.set_seed(seed); + log::debug!(target: "mat", "SEED :{:?}", header.seed()); let proof = self.api.extract_proof(); @@ -315,10 +316,11 @@ where pub fn create_inherents( &mut self, inherent_data: sp_inherents::InherentData, - ) -> Result<(SeedType, Vec), ApiErrorFor> { + ) -> Result<(ShufflingSeed, Vec), ApiErrorFor> { let block_id = self.block_id.clone(); let seed = pallet_random_seed::extract_inherent_data(&inherent_data) .map_err(|_| String::from("cannot read random seed from inherents data"))?; + self.api .execute_in_transaction(move |api| { // `create_inherents` should not change any state, to ensure this we always rollback @@ -329,7 +331,7 @@ where inherent_data, )) }) - .map(|inherents| (seed, inherents)) + .map(|inherents| (ShufflingSeed{seed: seed.seed.into(), proof: seed.proof.into()}, inherents)) } } diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index 14b5aea2a6ab3..d0c0f23f0ce5c 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -52,7 +52,6 @@ merlin = "2.0" pdqselect = "0.1.0" derive_more = "0.99.2" retain_mut = "0.1.1" -random-seed-runtime-api = {path="../../../frame/random-seed/runtime-api", version="2.0.0"} pallet-random-seed = { path='../../../frame/random-seed', version='2.0.0' } extrinsic-shuffler = { path='../../../client/shuffler', version='0.8.0' } diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 6ffbf5c40d9a5..c5e58f81b2a24 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -82,7 +82,7 @@ use sp_consensus::{ImportResult, CanAuthorWith}; use sp_consensus::import_queue::{ BoxJustificationImport, BoxFinalityProofImport, }; -use sp_core::{vrf::make_transcript, sr25519, crypto::Public, traits::BareCryptoStore, vrf}; +use sp_core::{vrf::make_transcript, sr25519, crypto::Public, traits::BareCryptoStore, ShufflingSeed, vrf}; use sp_application_crypto::AppKey; use sp_runtime::{ generic::{BlockId, OpaqueDigestItemId}, Justification, @@ -125,9 +125,7 @@ use sp_blockchain::{ use schnorrkel::{vrf::VRFOutput, vrf::VRFProof, SignatureError}; use codec::{Encode, Decode}; use sp_api::ApiExt; -use extrinsic_shuffler::{apply_inherents_and_fetch_seed, fetch_seed}; -use pallet_random_seed::{RandomSeedInherentDataProvider, SeedType}; -use random_seed_runtime_api::RandomSeedApi; +use pallet_random_seed::RandomSeedInherentDataProvider; use sp_inherents::ProvideInherentData; mod verification; @@ -257,7 +255,7 @@ enum Error { Runtime(sp_inherents::Error), ForkTree(Box>), #[display(fmt = "Bad shuffling seed: {:X?}", _0)] - BadSeed([u8; 32]), + BadSeed(sp_core::H256), #[display(fmt = "Seed verification problem: {}", _0)] SeedVerificationErrorStr(String), } @@ -387,7 +385,7 @@ pub fn start_babe(BabeParams { B: BlockT, C: ProvideRuntimeApi + ProvideCache + ProvideUncles + BlockchainEvents + HeaderBackend + HeaderMetadata + Send + Sync + 'static, - C::Api: BabeApi + random_seed_runtime_api::RandomSeedApi, + C::Api: BabeApi, SC: SelectChain + 'static, E: Environment + Send + Sync + 'static, E::Proposer: Proposer>, @@ -488,7 +486,7 @@ impl sc_consensus_slots::SimpleSlotWorker for BabeSlot ProvideCache + HeaderBackend + HeaderMetadata, - C::Api: BabeApi + random_seed_runtime_api::RandomSeedApi, + C::Api: BabeApi, E: Environment, E::Proposer: Proposer>, I: BlockImport> + Send + Sync + 'static, @@ -678,11 +676,11 @@ impl sc_consensus_slots::SimpleSlotWorker for BabeSlot fn inject_inherents<'a>( keystore: KeyStorePtr, public: &'a sr25519::Public, - seed: SeedType, + prev_seed: &'a ShufflingSeed, epoch: Epoch, slot_info: &'a mut SlotInfo, ) -> Result<(), sp_consensus::Error> { - let transcript_data = create_shuffling_seed_input_data(&seed); + let transcript_data = create_shuffling_seed_input_data(&prev_seed); let signature = keystore .read() .sr25519_vrf_sign(::ID, public, transcript_data) @@ -694,9 +692,9 @@ fn inject_inherents<'a>( .provide_inherent_data(&mut slot_info.inherent_data) .map_err(|_| sp_consensus::Error::StateUnavailable(String::from("cannot inject RandomSeed inherent data")))?; - RandomSeedInherentDataProvider(SeedType { - seed: signature.output.to_bytes(), - proof: signature.proof.to_bytes(), + RandomSeedInherentDataProvider(ShufflingSeed { + seed: signature.output.to_bytes().into(), + proof: signature.proof.to_bytes().into(), }) .provide_inherent_data(&mut slot_info.inherent_data) .map_err(|_| sp_consensus::Error::StateUnavailable(String::from("cannot inject RandomSeed inherent data")))?; @@ -708,7 +706,7 @@ impl SlotWorker for BabeSlotWorker where B: BlockT, C: ProvideRuntimeApi + ProvideCache + HeaderBackend + HeaderMetadata + Send + Sync, - C::Api: BabeApi + random_seed_runtime_api::RandomSeedApi, + C::Api: BabeApi, E: Environment + Send + Sync, E::Proposer: Proposer>, I: BlockImport> + Send + Sync + 'static, @@ -718,8 +716,6 @@ where type OnSlot = Pin> + Send>>; fn on_slot(&mut self, chain_head: B::Header, mut slot_info: SlotInfo) -> Self::OnSlot { - let block_id = BlockId::::Hash(chain_head.hash()); - let seed = self.client.runtime_api().get_seed(&block_id).unwrap(); let epoch_data = >::epoch_data(self, &chain_head, slot_info.number).unwrap(); @@ -740,7 +736,7 @@ where inject_inherents( self.keystore.clone(), &public.into(), - seed, + chain_head.seed(), epoch.into_cloned_inner(), &mut slot_info, ) @@ -855,10 +851,10 @@ impl BabeLink { } /// calculates input that after signing will become next shuffling seed -fn create_shuffling_seed_input_data<'a>(prev_seed: &'a SeedType) -> vrf::VRFTranscriptData<'a> { +fn create_shuffling_seed_input_data<'a>(prev_seed: &'a ShufflingSeed) -> vrf::VRFTranscriptData<'a> { vrf::VRFTranscriptData { label: b"shuffling_seed", - items: vec![("prev_seed", vrf::VRFTranscriptValue::Bytes(&prev_seed.seed))], + items: vec![("prev_seed", vrf::VRFTranscriptValue::Bytes(prev_seed.seed.as_bytes()))], } } @@ -878,8 +874,7 @@ where Block: BlockT, Client: AuxStore + HeaderBackend + HeaderMetadata + ProvideRuntimeApi, Client::Api: BlockBuilderApi - + BabeApi - + RandomSeedApi, + + BabeApi, SelectChain: sp_consensus::SelectChain, CAW: CanAuthorWith, { @@ -998,26 +993,19 @@ where fn validate_seed_signature( &self, - block_id: &BlockId, - inherents: Vec, + prev_seed: &ShufflingSeed, + seed: &ShufflingSeed, public_key: &[u8], ) -> Result<(), Error> { - let runtime_api = self.client.runtime_api(); - - let prev = fetch_seed::(&runtime_api, block_id) - .map_err(|e| Error::::SeedVerificationErrorStr(format!("{}", e)))?; - let new = apply_inherents_and_fetch_seed::(&runtime_api, block_id, inherents) - .map_err(|e| Error::::SeedVerificationErrorStr(format!("{}", e)))?; - - let output = VRFOutput::from_bytes(&new.seed) + let output = VRFOutput::from_bytes(&seed.seed.as_bytes()) .map_err(|_| Error::SeedVerificationErrorStr(String::from("cannot deserialize seed")))?; - let proof = VRFProof::from_bytes(&new.proof) + let proof = VRFProof::from_bytes(&seed.proof.as_bytes()) .map_err(|_| Error::SeedVerificationErrorStr(String::from("cannot deserialize seed proof")))?; - let input = make_transcript(create_shuffling_seed_input_data(&prev)); + let input = make_transcript(create_shuffling_seed_input_data(&prev_seed)); schnorrkel::PublicKey::from_bytes(public_key) .and_then(|p| p.vrf_verify(input, &output, &proof)) - .map_err(|_| Error::::BadSeed(new.seed))?; + .map_err(|_| Error::::BadSeed(seed.seed))?; Ok(()) } @@ -1029,8 +1017,7 @@ where Block: BlockT, Client: HeaderMetadata + HeaderBackend + ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache, - Client::Api: BlockBuilderApi + BabeApi - + RandomSeedApi, + Client::Api: BlockBuilderApi + BabeApi, SelectChain: sp_consensus::SelectChain, CAW: CanAuthorWith + Send + Sync, { @@ -1125,9 +1112,11 @@ where body = Some(inner_body); } - let extrinsics = body.clone().unwrap(); + let prev_header = self.client.header(BlockId::Hash(parent_hash)).unwrap().unwrap(); + let seed = header.seed(); + debug!(target: "babe", "PREV SEED {:?}", pre_header); let key = &viable_epoch.as_ref().authorities[babe_pre_digest.authority_index() as usize]; - self.validate_seed_signature(&BlockId::Hash(parent_hash), extrinsics, key.0.as_ref())?; + self.validate_seed_signature(prev_header.seed(), seed, key.0.as_ref())?; trace!(target: "babe", "Checked {:?}; importing.", pre_header); telemetry!( @@ -1565,7 +1554,7 @@ pub fn import_queue( Client: ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore + 'static, Client: HeaderBackend + HeaderMetadata, Client::Api: - BlockBuilderApi + BabeApi + ApiExt + RandomSeedApi, + BlockBuilderApi + BabeApi + ApiExt, SelectChain: sp_consensus::SelectChain + 'static, CAW: CanAuthorWith + Send + Sync + 'static, { diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 4d31738e53f42..2e6f2942f244f 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -78,7 +78,7 @@ sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" } tracing = "0.1.19" parity-util-mem = { version = "0.7.0", default-features = false, features = ["primitive-types"] } extrinsic-info-runtime-api = { version='2.0.0', path="../../primitives/extrinsic-info-runtime-api" } -random-seed-runtime-api = { version="2.0.0", path="../../frame/random-seed/runtime-api"} +pallet-random-seed = { version="2.0.0", path="../../frame/random-seed"} extrinsic-shuffler = { version="0.8.0", path="../shuffler" } [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 52ac012bbf92e..1d3b6e05a634c 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -28,6 +28,7 @@ use parking_lot::{Mutex, RwLock}; use codec::{Encode, Decode}; use hash_db::Prefix; use sp_core::{ + ShufflingSeed, convert_hash, storage::{well_known_keys, ChildInfo, PrefixedStorageKey, StorageData, StorageKey}, ChangesTrieConfiguration, ExecutionContext, NativeOrEncoded, @@ -65,7 +66,6 @@ use sp_api::{ }; use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; use sp_block_builder::BlockBuilder as BlockBuilderRuntimeApi; -use random_seed_runtime_api::RandomSeedApi; use extrinsic_info_runtime_api::runtime_api::ExtrinsicInfoRuntimeApi; use sc_client_api::{ @@ -839,7 +839,6 @@ impl Client where >::Api: CoreApi + ApiExt + ExtrinsicInfoRuntimeApi - + RandomSeedApi + BlockBuilderRuntimeApi, { let parent_hash = import_block.header.parent_hash(); @@ -873,19 +872,9 @@ impl Client where let prev_header = self.backend.blockchain().header(BlockId::Hash(*parent_hash)).unwrap().unwrap(); let mut header = import_block.header.clone(); header.set_extrinsics_root(*prev_header.extrinsics_root()); - + log::debug!(target: "mat", "SEED :{:?}", header.seed()); let block = if previous_block_extrinsics.len() > 1{ - let seed = extrinsic_shuffler::apply_inherents_and_fetch_seed::( - &runtime_api, - &at, - body.clone(), - ) - .map_err(|e| { - warn!("cannot fetch shuffling seed from the block"); - sp_blockchain::Error::Backend(format!("{}", e)) - })?; - - let shuffled_extrinsics = extrinsic_shuffler::shuffle::(&runtime_api, &at, previous_block_extrinsics, seed); + let shuffled_extrinsics = extrinsic_shuffler::shuffle::(&runtime_api, &at, previous_block_extrinsics, header.seed().seed); // temporarly shuffle extrinsics here as we cannot pass shuffling seed to // runtime easily // temporarly update extrinsics_root that stores hash of ordered extrinsics so it can be @@ -1311,7 +1300,6 @@ impl BlockBuilderProvider for Client>::Api: ApiExt> + BlockBuilderApi + ExtrinsicInfoRuntimeApi - + RandomSeedApi + BlockBuilderRuntimeApi, { @@ -1721,7 +1709,6 @@ impl sp_consensus::BlockImport for &Client as ProvideRuntimeApi>::Api: CoreApi + ApiExt + ExtrinsicInfoRuntimeApi - + RandomSeedApi + BlockBuilderRuntimeApi, { type Error = ConsensusError; @@ -1824,7 +1811,6 @@ impl sp_consensus::BlockImport for Client>::Api: CoreApi + ApiExt + ExtrinsicInfoRuntimeApi - + RandomSeedApi + BlockBuilderRuntimeApi, { type Error = ConsensusError; diff --git a/client/shuffler/Cargo.toml b/client/shuffler/Cargo.toml index da31ca94e672b..7c7a7a7ac1eca 100644 --- a/client/shuffler/Cargo.toml +++ b/client/shuffler/Cargo.toml @@ -22,7 +22,6 @@ sp-std = { default-features = false, version = '2.0.0' , path = "../../primitive sp-block-builder = { default-features=false, version = "2.0.0" , path = "../../primitives/block-builder"} extrinsic-info-runtime-api = { default-features=false, path='../../primitives/extrinsic-info-runtime-api', version='2.0.0' } pallet-random-seed = { default-features=false, path='../../frame/random-seed', version='2.0.0' } -random-seed-runtime-api = {default-features=false, path="../../frame/random-seed/runtime-api", version="2.0.0"} derive_more = "0.99.2" @@ -35,6 +34,5 @@ std = [ 'sp-runtime/std', 'sp-block-builder/std', 'pallet-random-seed/std', - 'random-seed-runtime-api/std', 'extrinsic-info-runtime-api/std', ] diff --git a/client/shuffler/src/lib.rs b/client/shuffler/src/lib.rs index c2e573bc6cdff..ed22440475767 100644 --- a/client/shuffler/src/lib.rs +++ b/client/shuffler/src/lib.rs @@ -9,18 +9,13 @@ use sp_std::convert::TryInto; use sp_std::collections::vec_deque::VecDeque; use sp_std::vec::Vec; +use sp_core::H256; #[cfg(feature = "std")] use extrinsic_info_runtime_api::runtime_api::ExtrinsicInfoRuntimeApi; #[cfg(feature = "std")] -use pallet_random_seed::SeedType; -#[cfg(feature = "std")] -use random_seed_runtime_api::RandomSeedApi; -#[cfg(feature = "std")] use sp_api::{ApiExt, ApiRef, ProvideRuntimeApi, TransactionOutcome}; #[cfg(feature = "std")] -use sp_block_builder::BlockBuilder as BlockBuilderRuntimeApi; -#[cfg(feature = "std")] use sp_core::crypto::Ss58Codec; #[cfg(feature = "std")] use sp_runtime::generic::BlockId; @@ -85,9 +80,9 @@ fn fisher_yates(data: &mut Vec, seed: [u8; 32]) { pub fn shuffle_using_seed( extrinsics: Vec<(Option, E)>, - seed: [u8; 32], + seed: H256, ) -> Vec { - log::debug!(target: "block_shuffler", "shuffling extrinsics with seed: {:2X?}", &seed[..]); + log::debug!(target: "block_shuffler", "shuffling extrinsics with seed: {:2X?}", seed.as_bytes()); log::debug!(target: "block_shuffler", "origin order: ["); for (_,tx) in extrinsics.iter() { log::debug!(target: "block_shuffler", "{:?}", BlakeTwo256::hash(&tx.encode())); @@ -110,7 +105,8 @@ pub fn shuffle_using_seed( }); // shuffle slots - fisher_yates(&mut slots, seed); + //TODO get rid of clone! + fisher_yates(&mut slots, seed.as_fixed_bytes().clone()); // fill slots using extrinsics in order // [ Alice, Bob, ... , Alice, Bob ] @@ -144,7 +140,7 @@ pub fn shuffle<'a, Block, Api>( api: &ApiRef<'a, Api::Api>, block_id: &BlockId, extrinsics: Vec, - seed: SeedType, + seed: H256, ) -> Vec where Block: BlockT, @@ -168,7 +164,7 @@ where (who, tx) }).collect(); - shuffle_using_seed::(extrinsics, seed.seed) + shuffle_using_seed::(extrinsics, seed) } #[derive(derive_more::Display, Debug)] @@ -178,44 +174,3 @@ pub enum Error { #[display(fmt = "Cannot read seed from the runtime api ")] SeedFetchingError, } - -#[cfg(feature = "std")] -pub fn fetch_seed<'a, Block, Api>( - api: &ApiRef<'a, Api::Api>, - block_id: &BlockId, -) -> Result -where - Block: BlockT, - Api: ProvideRuntimeApi + 'a, - Api::Api: BlockBuilderRuntimeApi + RandomSeedApi, -{ - api.get_seed(block_id).map_err(|_| Error::SeedFetchingError) -} - -/// shuffles extrinsics assuring that extrinsics signed by single account will be still evaluated -/// in proper order -#[cfg(feature = "std")] -pub fn apply_inherents_and_fetch_seed<'a, Block, Api>( - api: &ApiRef<'a, Api::Api>, - block_id: &BlockId, - extrinsics: Vec, -) -> Result -where - Block: BlockT, - Api: ProvideRuntimeApi + 'a, - Api::Api: BlockBuilderRuntimeApi + RandomSeedApi, -{ - api.execute_in_transaction(|api| { - sp_api::TransactionOutcome::Rollback( - extrinsics - .into_iter() - .take(2) - .map(|xt| match api.apply_extrinsic(block_id, xt) { - Ok(Ok(Ok(_))) => Ok(()), - _ => Err(Error::InherentApplyError), - }) - .collect::, _>>() - .and_then(|_| api.get_seed(block_id).map_err(|_| Error::SeedFetchingError)), - ) - }) -} diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index d145307e81bf6..b972c035b15c6 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -238,7 +238,7 @@ where parent_hash: &System::Hash, extrinsics_root: &System::Hash, digest: &Digest, - seed: &System::Hash, + seed: &sp_core::ShufflingSeed, ) { if Self::runtime_upgraded() { // System is not part of `AllModules`, so we need to call this manually. diff --git a/frame/random-seed/runtime-api/Cargo.toml b/frame/random-seed/runtime-api/Cargo.toml deleted file mode 100644 index c37ec45e81caa..0000000000000 --- a/frame/random-seed/runtime-api/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -authors = ['Mangata team'] -name = "random-seed-runtime-api" -version = "2.0.0" -edition = "2018" -license = "GPL-3.0-or-later" - -[dependencies] -sp-api = { version = '2.0.0', default-features = false, path = "../../../primitives/api" } -pallet-random-seed = { path="../../random-seed", version = '2.0.0', default-features = false } - -[features] -default = ["std"] -std = [ - "sp-api/std", -] diff --git a/frame/random-seed/runtime-api/src/lib.rs b/frame/random-seed/runtime-api/src/lib.rs deleted file mode 100644 index cf8088e86f4a3..0000000000000 --- a/frame/random-seed/runtime-api/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2021 Mangata team -#![cfg_attr(not(feature = "std"), no_std)] - -sp_api::decl_runtime_apis! { - pub trait RandomSeedApi{ - fn get_seed() -> pallet_random_seed::SeedType; - } -} diff --git a/frame/random-seed/src/lib.rs b/frame/random-seed/src/lib.rs index df7a0ac84ffc4..d47f7e3a91efd 100644 --- a/frame/random-seed/src/lib.rs +++ b/frame/random-seed/src/lib.rs @@ -2,71 +2,14 @@ use codec::Decode; use codec::Encode; -use frame_support::{decl_module, decl_storage, weights::DispatchClass}; -use sp_inherents::{InherentData, InherentIdentifier, IsFatalError, ProvideInherent}; +use sp_core::ShufflingSeed; +use sp_inherents::{InherentData, InherentIdentifier}; use sp_runtime::RuntimeString; #[cfg(feature = "std")] use sp_inherents::ProvideInherentData; -/// The module configuration trait -pub trait Trait: frame_system::Trait {} - -#[derive(Encode, Decode, Debug, Clone, PartialEq)] -pub struct SeedType { - pub seed: [u8; 32], - pub proof: [u8; 64], -} - -impl Default for SeedType { - fn default() -> Self { - SeedType { - seed: Default::default(), - proof: [0_u8; 64], - } - } -} - -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - - #[weight = ( - 10_000, - DispatchClass::Mandatory - )] - fn set(origin, seed: SeedType) { - log::debug!(target: "mat", "set seed: ${:X?}", seed); - ::Seed::put(seed); - } - - } -} - -decl_storage! { - trait Store for Module as RandomSeed { - /// Current time for the current block. - pub Seed get(fn seed) : SeedType; - } - add_extra_genesis { - #[allow(clippy::type_complexity)] - config(random_seed): [u8; 32]; - build(|config: &GenesisConfig|{ - Seed::set(SeedType{ - seed: config.random_seed, - proof: [0_u8; 64] - }); - }); - } -} - -impl Module { - pub fn get() -> SeedType { - Self::seed() - } -} - // originally in sp-module -pub type RandomSeedInherentType = SeedType; pub const RANDOM_SEED_INHERENT_IDENTIFIER: InherentIdentifier = *b"blckseed"; #[derive(Encode, sp_runtime::RuntimeDebug)] @@ -87,20 +30,14 @@ impl RandomSeedInherentError { } } -impl IsFatalError for RandomSeedInherentError { - fn is_fatal_error(&self) -> bool { - true - } -} - -pub fn extract_inherent_data(data: &InherentData) -> Result { - data.get_data::(&RANDOM_SEED_INHERENT_IDENTIFIER) +pub fn extract_inherent_data(data: &InherentData) -> Result { + data.get_data::(&RANDOM_SEED_INHERENT_IDENTIFIER) .map_err(|_| RuntimeString::from("Invalid random seed inherent data encoding."))? .ok_or_else(|| "Random Seed inherent data is not provided.".into()) } #[cfg(feature = "std")] -pub struct RandomSeedInherentDataProvider(pub SeedType); +pub struct RandomSeedInherentDataProvider(pub ShufflingSeed); #[cfg(feature = "std")] impl ProvideInherentData for RandomSeedInherentDataProvider { @@ -117,18 +54,3 @@ impl ProvideInherentData for RandomSeedInherentDataProvider { } } -impl ProvideInherent for Module { - type Call = Call; - type Error = RandomSeedInherentError; - const INHERENT_IDENTIFIER: InherentIdentifier = *b"blckseed"; - - fn create_inherent(data: &InherentData) -> Option { - log::debug!(target: "rand-seed", "initializing random seed"); - let seed: SeedType = extract_inherent_data(data).expect("Gets and decodes random seed"); - Some(Call::set(seed)) - } - - fn check_inherent(_call: &Self::Call, _data: &InherentData) -> Result<(), Self::Error> { - Ok(()) - } -} diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 7089347da7b99..f0ffcb7515edb 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -112,7 +112,7 @@ use sp_runtime::{ offchain::storage_lock::BlockNumberProvider, }; -use sp_core::{ChangesTrieConfiguration, storage::well_known_keys}; +use sp_core::{ChangesTrieConfiguration, storage::well_known_keys, H256, H512, ShufflingSeed}; use frame_support::{ decl_module, decl_event, decl_storage, decl_error, Parameter, ensure, debug, storage, @@ -439,7 +439,8 @@ decl_storage! { EventCount get(fn event_count): EventIndex; /// The number of events in the `Events` list. - ShufflingSeed get(fn shuffling_seed): T::Hash; + Seed get(fn seed): H256; + SeedProof get(fn seed_proof): H512; // TODO: https://github.com/paritytech/substrate/issues/2553 // Possibly, we can improve it by using something like: @@ -1015,7 +1016,7 @@ impl Module { txs_root: &T::Hash, digest: &DigestOf, kind: InitKind, - seed: &T::Hash, + seed: &ShufflingSeed, ) { // populate environment ExecutionPhase::put(Phase::Initialization); @@ -1025,7 +1026,8 @@ impl Module { >::put(parent_hash); >::insert(*number - One::one(), parent_hash); >::put(txs_root); - >::put(seed); + ::put(seed.seed); + ::put(seed.proof); // Remove previous block data from storage BlockWeight::kill(); @@ -1048,7 +1050,8 @@ impl Module { let parent_hash = >::take(); let mut digest = >::take(); let extrinsics_root = >::take(); - let seed = >::take(); + let seed = ::take(); + let proof = ::take(); // move block hash pruning window by one block let block_hash_count = ::get(); @@ -1084,7 +1087,7 @@ impl Module { // stay to be inspected by the client and will be cleared by `Self::initialize`. let mut header = ::new(number, extrinsics_root, storage_root, parent_hash, digest); - header.set_seed(seed); + header.set_seed(ShufflingSeed{seed , proof}); header } @@ -1118,13 +1121,6 @@ impl Module { >::put(n); } - /// Set the block number to something in particular. Can be used as an alternative to - /// `initialize` for tests that don't need to bother with the other environment entries. - #[cfg(any(feature = "std", feature = "runtime-benchmarks", test))] - pub fn set_block_seed(seed: T::Hash) { - >::put(seed); - } - /// Sets the index of extrinsic that is currently executing. #[cfg(any(feature = "std", test))] pub fn set_extrinsic_index(extrinsic_index: u32) { diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 94f6bb2967a0b..7d951c17ee1a7 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -67,6 +67,7 @@ pub mod hash; mod hasher; pub mod offchain; pub mod sandbox; +pub mod seed; pub mod uint; mod changes_trie; #[cfg(feature = "std")] @@ -81,6 +82,8 @@ pub use changes_trie::{ChangesTrieConfiguration, ChangesTrieConfigurationRange}; #[cfg(feature = "full_crypto")] pub use crypto::{DeriveJunction, Pair, Public}; +pub use seed::ShufflingSeed; + pub use hash_db::Hasher; #[cfg(feature = "std")] pub use self::hasher::blake2::Blake2Hasher; diff --git a/primitives/core/src/seed.rs b/primitives/core/src/seed.rs new file mode 100644 index 0000000000000..9ad762cc56a65 --- /dev/null +++ b/primitives/core/src/seed.rs @@ -0,0 +1,27 @@ +use codec::Decode; +use codec::Encode; +use crate::hash::{H256, H512}; + +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + +#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, Default)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +/// stores information needed to verify if +/// shuffling seed was generated properly +pub struct ShufflingSeed { + /// shuffling seed for the previous block + pub seed: H256, + /// seed signature + pub proof: H512, +} + +#[cfg(feature = "std")] +impl parity_util_mem::MallocSizeOf for ShufflingSeed +where +{ + fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize { + self.seed.size_of(ops) + self.proof.size_of(ops) + } +} + diff --git a/primitives/runtime/src/generic/header.rs b/primitives/runtime/src/generic/header.rs index bb99ba26cad8c..a042075d925b6 100644 --- a/primitives/runtime/src/generic/header.rs +++ b/primitives/runtime/src/generic/header.rs @@ -26,7 +26,7 @@ use crate::traits::{ MaybeMallocSizeOf, }; use crate::generic::Digest; -use sp_core::U256; +use sp_core::{U256, ShufflingSeed}; use sp_std::{ convert::TryFrom, fmt::Debug, @@ -52,7 +52,7 @@ pub struct Header + TryFrom, Hash: HashT> { /// A chain-specific digest of data useful for light clients or referencing auxiliary data. pub digest: Digest, /// Previous block extrinsics shuffling seed - pub seed: Hash::Output, + pub seed: ShufflingSeed, } #[cfg(feature = "std")] @@ -67,7 +67,8 @@ where self.number.size_of(ops) + self.state_root.size_of(ops) + self.extrinsics_root.size_of(ops) + - self.digest.size_of(ops) + self.digest.size_of(ops) + + self.seed.size_of(ops) } } @@ -99,7 +100,7 @@ impl Decode for Header where state_root: Decode::decode(input)?, extrinsics_root: Decode::decode(input)?, digest: Decode::decode(input)?, - seed: Default::default(), + seed: Decode::decode(input)?, }) } } @@ -115,6 +116,7 @@ impl Encode for Header where dest.push(&self.state_root); dest.push(&self.extrinsics_root); dest.push(&self.digest); + dest.push(&self.seed); } } @@ -156,12 +158,11 @@ impl traits::Header for Header where &mut self.digest } - fn seed(&self) -> &Self::Hash { &self.seed } + fn seed(&self) -> &ShufflingSeed{ &self.seed } - /// Returns seed used for shuffling - fn set_seed(& mut self,seed: Self::Hash) { - self.seed = seed; - } + fn set_seed(& mut self,seed: ShufflingSeed){ + self.seed = seed; + } fn new( number: Self::Number, diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 28befce218858..73020456b6f38 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -26,7 +26,7 @@ use std::fmt::Display; use std::str::FromStr; #[cfg(feature = "std")] use serde::{Serialize, Deserialize, de::DeserializeOwned}; -use sp_core::{self, Hasher, TypeId, RuntimeDebug}; +use sp_core::{self, Hasher, TypeId, RuntimeDebug, ShufflingSeed}; use crate::codec::{Codec, Encode, Decode}; use crate::transaction_validity::{ ValidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, @@ -539,10 +539,10 @@ pub trait Header: } /// Returns seed used for shuffling - fn seed(&self) -> &Self::Hash; + fn seed(&self) -> &ShufflingSeed; /// Returns seed used for shuffling - fn set_seed(& mut self,seed: Self::Hash); + fn set_seed(& mut self, seed: ShufflingSeed); } /// Something which fulfills the abstract idea of a Substrate block. It has types for diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 0c0836be1dc68..e68b587378537 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -45,7 +45,6 @@ sc-service = { version = "0.8.0", default-features = false, optional = true, fea sp-state-machine = { version = "0.8.0", default-features = false, path = "../../primitives/state-machine" } sp-externalities = { version = "0.8.0", default-features = false, path = "../../primitives/externalities" } extrinsic-info-runtime-api = { path = '../../primitives/extrinsic-info-runtime-api', default-features = false, version = '2.0.0' } -random-seed-runtime-api = {path = '../../frame/random-seed/runtime-api', default-features = false, version = '2.0.0' } pallet-random-seed = {path = '../../frame/random-seed', default-features = false, version = '2.0.0' } # 3rd party diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index e9bdb736a8373..7aa8e040b7fb5 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -574,12 +574,6 @@ cfg_if! { } } - impl random_seed_runtime_api::RandomSeedApi for Runtime { - fn get_seed() -> pallet_random_seed::SeedType{ - Default::default() - } - } - impl sp_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { unimplemented!() @@ -830,12 +824,6 @@ cfg_if! { } } - impl random_seed_runtime_api::RandomSeedApi for Runtime { - fn get_seed() -> pallet_random_seed::SeedType{ - unimplemented!() - } - } - impl sp_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { unimplemented!() From b57a1ac0fd4f373f13227f5d53d073ea248e2950 Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Mon, 13 Sep 2021 18:39:03 +0200 Subject: [PATCH 2/8] shuffle extrinsics at runtime --- client/block-builder/src/lib.rs | 3 +-- client/consensus/babe/src/lib.rs | 1 - client/service/src/client/client.rs | 22 +++------------------- client/shuffler/src/lib.rs | 7 +++---- frame/executive/src/lib.rs | 18 ++++-------------- 5 files changed, 11 insertions(+), 40 deletions(-) diff --git a/client/block-builder/src/lib.rs b/client/block-builder/src/lib.rs index 88dffabd4ca53..96231eb7f6eda 100644 --- a/client/block-builder/src/lib.rs +++ b/client/block-builder/src/lib.rs @@ -252,7 +252,7 @@ where &self.api, &self.block_id, previous_block_extrinsics, - seed.clone().seed + &seed.seed ) }; @@ -287,7 +287,6 @@ where ); header.set_extrinsics_root(extrinsics_root); header.set_seed(seed); - log::debug!(target: "mat", "SEED :{:?}", header.seed()); let proof = self.api.extract_proof(); diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index c5e58f81b2a24..8747dfdae4b0f 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -1114,7 +1114,6 @@ where let prev_header = self.client.header(BlockId::Hash(parent_hash)).unwrap().unwrap(); let seed = header.seed(); - debug!(target: "babe", "PREV SEED {:?}", pre_header); let key = &viable_epoch.as_ref().authorities[babe_pre_digest.authority_index() as usize]; self.validate_seed_signature(prev_header.seed(), seed, key.0.as_ref())?; diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 1d3b6e05a634c..92cdac05b9b2b 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -28,7 +28,6 @@ use parking_lot::{Mutex, RwLock}; use codec::{Encode, Decode}; use hash_db::Prefix; use sp_core::{ - ShufflingSeed, convert_hash, storage::{well_known_keys, ChildInfo, PrefixedStorageKey, StorageData, StorageKey}, ChangesTrieConfiguration, ExecutionContext, NativeOrEncoded, @@ -38,7 +37,7 @@ use sp_runtime::{ Justification, BuildStorage, generic::{BlockId, SignedBlock, DigestItem}, traits::{ - Hash, Block as BlockT, Header as HeaderT, Zero, NumberFor, + Block as BlockT, Header as HeaderT, Zero, NumberFor, HashFor, SaturatedConversion, One, DigestFor, UniqueSaturatedInto, }, }; @@ -857,7 +856,7 @@ impl Client where (true, Some(_), _) => {} // We should enact state, but don't have any storage changes, so we need to execute the // block. - (true, ref mut storage_changes @ None, Some(ref body)) => { + (true, ref mut storage_changes @ None, Some(ref _body)) => { let runtime_api = self.runtime_api(); let execution_context = if import_block.origin == BlockOrigin::NetworkInitialSync { ExecutionContext::Syncing @@ -872,22 +871,7 @@ impl Client where let prev_header = self.backend.blockchain().header(BlockId::Hash(*parent_hash)).unwrap().unwrap(); let mut header = import_block.header.clone(); header.set_extrinsics_root(*prev_header.extrinsics_root()); - log::debug!(target: "mat", "SEED :{:?}", header.seed()); - let block = if previous_block_extrinsics.len() > 1{ - let shuffled_extrinsics = extrinsic_shuffler::shuffle::(&runtime_api, &at, previous_block_extrinsics, header.seed().seed); - // temporarly shuffle extrinsics here as we cannot pass shuffling seed to - // runtime easily - // 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); - Block::new(header.clone(), shuffled_extrinsics) - }else{ - Block::new(header.clone(), previous_block_extrinsics) - }; - - - + let block = Block::new(header.clone(), previous_block_extrinsics); runtime_api.execute_block_with_context( &at, diff --git a/client/shuffler/src/lib.rs b/client/shuffler/src/lib.rs index ed22440475767..0fdf04351a32b 100644 --- a/client/shuffler/src/lib.rs +++ b/client/shuffler/src/lib.rs @@ -80,7 +80,7 @@ fn fisher_yates(data: &mut Vec, seed: [u8; 32]) { pub fn shuffle_using_seed( extrinsics: Vec<(Option, E)>, - seed: H256, + seed: &H256, ) -> Vec { log::debug!(target: "block_shuffler", "shuffling extrinsics with seed: {:2X?}", seed.as_bytes()); log::debug!(target: "block_shuffler", "origin order: ["); @@ -105,8 +105,7 @@ pub fn shuffle_using_seed( }); // shuffle slots - //TODO get rid of clone! - fisher_yates(&mut slots, seed.as_fixed_bytes().clone()); + fisher_yates(&mut slots, seed.to_fixed_bytes()); // fill slots using extrinsics in order // [ Alice, Bob, ... , Alice, Bob ] @@ -140,7 +139,7 @@ pub fn shuffle<'a, Block, Api>( api: &ApiRef<'a, Api::Api>, block_id: &BlockId, extrinsics: Vec, - seed: H256, + seed: &H256, ) -> Vec where Block: BlockT, diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index b972c035b15c6..456ed80dda73d 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -131,7 +131,6 @@ use sp_runtime::{ transaction_validity::{TransactionValidity, TransactionSource}, }; use codec::{Codec, Encode}; -// use extrinsic_shuffler::shuffle_using_seed; use frame_system::{extrinsics_root, DigestOf}; /// Trait that can be used to execute a block. pub trait ExecuteBlock { @@ -297,7 +296,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); @@ -312,19 +311,10 @@ where // execute extrinsics let (header, extrinsics) = block.deconstruct(); - // 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 shuffled_extrinsics = extrinsic_shuffler::shuffle_using_seed::(extrinsics_with_author, &header.seed().seed); + Self::execute_extrinsics_with_book_keeping(shuffled_extrinsics, *header.number()); - // 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."); } From 9b3cd1cf2331c81fda701e26a8709ddf24f59a9f Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Mon, 13 Sep 2021 20:39:45 +0200 Subject: [PATCH 3/8] Fix header deserialization test --- client/rpc/src/state/tests.rs | 8 +++--- frame/babe/src/benchmarking.rs | 49 +++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index a7a8871b261d8..4e0608f5cdb43 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -455,10 +455,10 @@ fn should_return_runtime_version() { let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\ \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",3],\ - [\"0xb76521c61ad13ade\",1],[\"0x0f71f73ae590773f\",1],[\"0x37e397fc7c91f5e4\",1],\ - [\"0xd2bc9897eed08f15\",2],[\"0x40fe3ad401f8959a\",4],[\"0xc6e9a76309f39b09\",1],\ - [\"0xdd718d5cc53262d4\",1],[\"0xcbca25e39f142387\",2],[\"0xf78b278be53f454c\",2],\ - [\"0xab3c0572291feb8b\",1],[\"0xbc9d89904f5b923f\",1]],\"transactionVersion\":1}"; + [\"0xb76521c61ad13ade\",1],[\"0x37e397fc7c91f5e4\",1],[\"0xd2bc9897eed08f15\",2],\ + [\"0x40fe3ad401f8959a\",4],[\"0xc6e9a76309f39b09\",1],[\"0xdd718d5cc53262d4\",1],\ + [\"0xcbca25e39f142387\",2],[\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],\ + [\"0xbc9d89904f5b923f\",1]],\"transactionVersion\":1}"; let runtime_version = api.runtime_version(None.into()).wait().unwrap(); let serialized = serde_json::to_string(&runtime_version).unwrap(); diff --git a/frame/babe/src/benchmarking.rs b/frame/babe/src/benchmarking.rs index 8ee4a5913c885..ec4b4a8002654 100644 --- a/frame/babe/src/benchmarking.rs +++ b/frame/babe/src/benchmarking.rs @@ -33,28 +33,33 @@ benchmarks! { // signature content changes). it should not affect the benchmark. // with the current benchmark setup it is not possible to generate this programatically // from the benchmark setup. - const EQUIVOCATION_PROOF_BLOB: [u8; 416] = [ - 222, 241, 46, 66, 243, 228, 135, 233, 177, 64, 149, 170, 141, 92, 193, 106, 51, 73, 31, - 27, 80, 218, 220, 248, 129, 29, 20, 128, 243, 250, 134, 39, 11, 0, 0, 0, 0, 0, 0, 0, - 158, 4, 7, 240, 67, 153, 134, 190, 251, 196, 229, 95, 136, 165, 234, 228, 255, 18, 2, - 187, 76, 125, 108, 50, 67, 33, 196, 108, 38, 115, 179, 86, 40, 36, 27, 5, 105, 58, 228, - 94, 198, 65, 212, 218, 213, 61, 170, 21, 51, 249, 182, 121, 101, 91, 204, 25, 31, 87, - 219, 208, 43, 119, 211, 185, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65, 66, 69, 52, 2, 0, 0, 0, 0, 11, - 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 188, 192, 217, 91, 138, 78, 217, 80, 8, - 29, 140, 55, 242, 210, 170, 184, 73, 98, 135, 212, 236, 209, 115, 52, 200, 79, 175, - 172, 242, 161, 199, 47, 236, 93, 101, 95, 43, 34, 141, 16, 247, 220, 33, 59, 31, 197, - 27, 7, 196, 62, 12, 238, 236, 124, 136, 191, 29, 36, 22, 238, 242, 202, 57, 139, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 40, 23, 175, 153, 83, 6, 33, 65, 123, 51, 80, 223, 126, 186, 226, 225, 240, 105, 28, - 169, 9, 54, 11, 138, 46, 194, 201, 250, 48, 242, 125, 117, 116, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65, - 66, 69, 52, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 142, 12, - 124, 11, 167, 227, 103, 88, 78, 23, 228, 33, 96, 41, 207, 183, 227, 189, 114, 70, 254, - 30, 128, 243, 233, 83, 214, 45, 74, 182, 120, 119, 64, 243, 219, 119, 63, 240, 205, - 123, 231, 82, 205, 174, 143, 70, 2, 86, 182, 20, 16, 141, 145, 91, 116, 195, 58, 223, - 175, 145, 255, 7, 121, 133 - ]; + const EQUIVOCATION_PROOF_BLOB: [u8; 608] = + [222, 241, 46, 66, 243, 228, 135, 233, 177, 64, 149, 170, 141, 92, 193, 106, 51, 73, + 31, 27, 80, 218, 220, 248, 129, 29, 20, 128, 243, 250, 134, 39, 11, 0, 0, 0, 0, 0, 0, + 0, 69, 226, 97, 131, 181, 167, 43, 160, 70, 55, 249, 6, 255, 28, 248, 88, 192, 145, + 32, 237, 161, 214, 90, 173, 188, 53, 155, 155, 150, 173, 28, 192, 40, 234, 4, 27, 230, + 11, 202, 160, 112, 152, 119, 2, 142, 71, 217, 150, 52, 124, 209, 251, 135, 222, 227, 141, + 106, 180, 31, 125, 219, 226, 198, 138, 198, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 66, 65, 66, 69, 52, 2, 0, 0, 0, + 0, 11, 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, 1, 1, 60, 20, 93, 221, 43, 179, 180, 255, + 165, 121, 104, 246, 58, 101, 242, 253, 216, 44, 84, 90, 204, 185, 187, 17, 0, 182, 193, + 139, 143, 145, 77, 108, 64, 8, 8, 88, 19, 89, 152, 218, 69, 34, 11, 166, 61, 125, 112, + 232, 83, 253, 69, 226, 87, 237, 74, 73, 234, 66, 128, 107, 250, 123, 206, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 86, 159, 100, 37, 240, 116, 137, 63, 99, 196, 141, 72, 36, + 97, 33, 107, 148, 178, 211, 135, 72, 178, 226, 250, 119, 207, 141, 93, 233, 194, 18, 108, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 8, 6, 66, 65, 66, 69, 52, 2, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 5, 66, 65, 66, 69, + 1, 1, 230, 247, 56, 224, 81, 164, 33, 178, 25, 206, 140, 109, 160, 171, 18, 177, 88, 194, + 124, 25, 209, 120, 23, 23, 190, 136, 140, 93, 241, 19, 59, 110, 24, 213, 106, 147, 115, + 127, 192, 60, 107, 175, 106, 127, 142, 67, 230, 106, 2, 251, 21, 230, 245, 78, 201, 87, + 30, 7, 229, 241, 246, 226, 183, 132, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; let equivocation_proof1: sp_consensus_babe::EquivocationProof
= Decode::decode(&mut &EQUIVOCATION_PROOF_BLOB[..]).unwrap(); From 5731601ebc739b8292ff7122eab82cec2fe0ef5c Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 14 Sep 2021 07:38:57 +0200 Subject: [PATCH 4/8] ci From 4c2c8b81379be24e63ea6c0c7bb117d6790fe46e Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 14 Sep 2021 09:27:58 +0200 Subject: [PATCH 5/8] disable unstable tests --- client/consensus/manual-seal/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs index 61d6e3dc268a8..b08fcf02b64ba 100644 --- a/client/consensus/manual-seal/src/lib.rs +++ b/client/consensus/manual-seal/src/lib.rs @@ -440,7 +440,10 @@ mod tests { assert_eq!(rx.await.unwrap().unwrap(), ()); } + /// below test is unstable with high cpu load which happens on ci + /// tested on version tags/v2.0.1 with the same results #[tokio::test] + #[ignore] async fn manual_seal_fork_blocks() { let builder = TestClientBuilder::new(); let (client, select_chain) = builder.build_with_longest_chain(); From 471b11b6c4760b7b497942fce9d782e58c933dbe Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 14 Sep 2021 10:56:54 +0200 Subject: [PATCH 6/8] ci From be9110f413d4e6e100f2c0780e7e487e3212329c Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 14 Sep 2021 12:03:04 +0200 Subject: [PATCH 7/8] separate steps for building and running ut --- .github/workflows/mangata-dev.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mangata-dev.yml b/.github/workflows/mangata-dev.yml index 1fa9a6353829f..a5db258671f74 100644 --- a/.github/workflows/mangata-dev.yml +++ b/.github/workflows/mangata-dev.yml @@ -26,13 +26,15 @@ jobs: - name: Check Cargo version run: | cargo --version - - name: Run cargo check + - name: Build UT uses: actions-rs/cargo@v1 with: toolchain: nightly-2020-10-01 - command: check - - name: Test cargo check + command: build + args: --tests + - name: Run UT uses: actions-rs/cargo@v1 with: toolchain: nightly-2020-10-01 command: test +est From 3ae0424be44af82313f8a3b4394959cf4f86fc85 Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 14 Sep 2021 12:22:24 +0200 Subject: [PATCH 8/8] ci --- .github/workflows/mangata-dev.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/mangata-dev.yml b/.github/workflows/mangata-dev.yml index a5db258671f74..cd5f7c4aac9e3 100644 --- a/.github/workflows/mangata-dev.yml +++ b/.github/workflows/mangata-dev.yml @@ -37,4 +37,3 @@ jobs: with: toolchain: nightly-2020-10-01 command: test -est