From 83ae2d0b75dc3ee5fbae0032457f53ba69b91314 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 23 Jun 2020 16:25:34 +0200 Subject: [PATCH 01/12] debug --- primitives/runtime/src/generic/unchecked_extrinsic.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/primitives/runtime/src/generic/unchecked_extrinsic.rs b/primitives/runtime/src/generic/unchecked_extrinsic.rs index 41ff2609fc8cc..fb4151dc37187 100644 --- a/primitives/runtime/src/generic/unchecked_extrinsic.rs +++ b/primitives/runtime/src/generic/unchecked_extrinsic.rs @@ -232,7 +232,12 @@ where let is_signed = version & 0b1000_0000 != 0; let version = version & 0b0111_1111; + #[cfg(feature = "std")] + { + println!("versions: {:?} vs {:?}", version, TRANSACTION_VERSION); + } if version != TRANSACTION_VERSION { + panic!("boo"); return Err("Invalid transaction version".into()); } From 720e37163999ba021bf1a0de3d97f2cd37bea439 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 25 Jun 2020 12:27:49 +0200 Subject: [PATCH 02/12] test impl without Arc --- test-utils/client/src/client_ext.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index 706a7b6e95a85..f254669b60cf4 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -82,9 +82,10 @@ impl ClientExt for Client } } +use std::sync::Arc; /// This implementation is required, because of the weird api requirements around `BlockImport`. -impl ClientBlockImportExt for std::sync::Arc - where for<'r> &'r T: BlockImport +impl ClientBlockImportExt for T + where T: BlockImport { fn import(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); @@ -92,7 +93,7 @@ impl ClientBlockImportExt for std::sync::A import.body = Some(extrinsics); import.fork_choice = Some(ForkChoiceStrategy::LongestChain); - BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) + self.import_block(import, HashMap::new()).map(|_| ()) } fn import_as_best(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { @@ -101,7 +102,7 @@ impl ClientBlockImportExt for std::sync::A import.body = Some(extrinsics); import.fork_choice = Some(ForkChoiceStrategy::Custom(true)); - BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) + self.import_block(import, HashMap::new()).map(|_| ()) } fn import_as_final(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { @@ -111,7 +112,7 @@ impl ClientBlockImportExt for std::sync::A import.finalized = true; import.fork_choice = Some(ForkChoiceStrategy::Custom(true)); - BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) + self.import_block(import, HashMap::new()).map(|_| ()) } fn import_justified( @@ -127,10 +128,11 @@ impl ClientBlockImportExt for std::sync::A import.finalized = true; import.fork_choice = Some(ForkChoiceStrategy::LongestChain); - BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) + self.import_block(import, HashMap::new()).map(|_| ()) } } +/* impl ClientBlockImportExt for Client where Self: BlockImport, @@ -179,3 +181,4 @@ impl ClientBlockImportExt for Client Date: Thu, 25 Jun 2020 14:07:36 +0200 Subject: [PATCH 03/12] Revert "test impl without Arc" This reverts commit 720e37163999ba021bf1a0de3d97f2cd37bea439. --- test-utils/client/src/client_ext.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index f254669b60cf4..706a7b6e95a85 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -82,10 +82,9 @@ impl ClientExt for Client } } -use std::sync::Arc; /// This implementation is required, because of the weird api requirements around `BlockImport`. -impl ClientBlockImportExt for T - where T: BlockImport +impl ClientBlockImportExt for std::sync::Arc + where for<'r> &'r T: BlockImport { fn import(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); @@ -93,7 +92,7 @@ impl ClientBlockImportExt for T import.body = Some(extrinsics); import.fork_choice = Some(ForkChoiceStrategy::LongestChain); - self.import_block(import, HashMap::new()).map(|_| ()) + BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } fn import_as_best(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { @@ -102,7 +101,7 @@ impl ClientBlockImportExt for T import.body = Some(extrinsics); import.fork_choice = Some(ForkChoiceStrategy::Custom(true)); - self.import_block(import, HashMap::new()).map(|_| ()) + BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } fn import_as_final(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { @@ -112,7 +111,7 @@ impl ClientBlockImportExt for T import.finalized = true; import.fork_choice = Some(ForkChoiceStrategy::Custom(true)); - self.import_block(import, HashMap::new()).map(|_| ()) + BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } fn import_justified( @@ -128,11 +127,10 @@ impl ClientBlockImportExt for T import.finalized = true; import.fork_choice = Some(ForkChoiceStrategy::LongestChain); - self.import_block(import, HashMap::new()).map(|_| ()) + BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } } -/* impl ClientBlockImportExt for Client where Self: BlockImport, @@ -181,4 +179,3 @@ impl ClientBlockImportExt for Client Date: Thu, 25 Jun 2020 14:07:53 +0200 Subject: [PATCH 04/12] Revert "debug" This reverts commit 83ae2d0b75dc3ee5fbae0032457f53ba69b91314. --- primitives/runtime/src/generic/unchecked_extrinsic.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/primitives/runtime/src/generic/unchecked_extrinsic.rs b/primitives/runtime/src/generic/unchecked_extrinsic.rs index fb4151dc37187..41ff2609fc8cc 100644 --- a/primitives/runtime/src/generic/unchecked_extrinsic.rs +++ b/primitives/runtime/src/generic/unchecked_extrinsic.rs @@ -232,12 +232,7 @@ where let is_signed = version & 0b1000_0000 != 0; let version = version & 0b0111_1111; - #[cfg(feature = "std")] - { - println!("versions: {:?} vs {:?}", version, TRANSACTION_VERSION); - } if version != TRANSACTION_VERSION { - panic!("boo"); return Err("Invalid transaction version".into()); } From 5ac74b16a83cd9b2d1e698d49e6cde8de9f9d455 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 25 Jun 2020 16:19:23 +0200 Subject: [PATCH 05/12] WIP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- client/consensus/aura/src/lib.rs | 4 ++-- client/consensus/babe/src/lib.rs | 4 ++-- client/consensus/babe/src/tests.rs | 4 ++-- client/consensus/pow/src/lib.rs | 4 ++-- client/finality-grandpa/src/import.rs | 8 ++++---- client/finality-grandpa/src/light_import.rs | 14 +++++++------- client/network/test/src/lib.rs | 4 ++-- client/service/src/client/client.rs | 16 +++++++++------- primitives/consensus/common/src/block_import.rs | 12 ++++++------ 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 818bb563484be..f148825da9bf8 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -774,14 +774,14 @@ impl BlockImport for AuraBlockImport; fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.inner.check_block(block).map_err(Into::into) } fn import_block( - &mut self, + &self, block: BlockImportParams, new_cache: HashMap>, ) -> Result { diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 3d14f0a7bf08d..d5bcc62864834 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -966,7 +966,7 @@ impl BlockImport for BabeBlockImport; fn import_block( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -1199,7 +1199,7 @@ impl BlockImport for BabeBlockImport, ) -> Result { self.inner.check_block(block).map_err(Into::into) diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index ada1332295d46..4a1a9126f999d 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -181,7 +181,7 @@ impl> BlockImport for PanickingBlockImport< type Transaction = B::Transaction; fn import_block( - &mut self, + &self, block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -189,7 +189,7 @@ impl> BlockImport for PanickingBlockImport< } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { Ok(self.0.check_block(block).expect("checking block failed")) diff --git a/client/consensus/pow/src/lib.rs b/client/consensus/pow/src/lib.rs index 24a8b63281208..ac00424c95443 100644 --- a/client/consensus/pow/src/lib.rs +++ b/client/consensus/pow/src/lib.rs @@ -284,14 +284,14 @@ impl BlockImport for PowBlockImport; fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.inner.check_block(block).map_err(Into::into) } fn import_block( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { diff --git a/client/finality-grandpa/src/import.rs b/client/finality-grandpa/src/import.rs index b37ab7907a62e..4bc02f7db8f2b 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/finality-grandpa/src/import.rs @@ -414,7 +414,7 @@ impl BlockImport type Transaction = TransactionFor; fn import_block( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -437,7 +437,7 @@ impl BlockImport // we don't want to finalize on `inner.import_block` let mut justification = block.justification.take(); let enacts_consensus_change = !new_cache.is_empty(); - let import_result = (&*self.inner).import_block(block, new_cache); + let import_result = self.inner.import_block(block, new_cache); let mut imported_aux = { match import_result { @@ -545,7 +545,7 @@ impl BlockImport } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.inner.check_block(block) @@ -620,7 +620,7 @@ where /// If `enacts_change` is set to true, then finalizing this block *must* /// enact an authority set change, the function will panic otherwise. fn import_justification( - &mut self, + &self, hash: Block::Hash, number: NumberFor, justification: Justification, diff --git a/client/finality-grandpa/src/light_import.rs b/client/finality-grandpa/src/light_import.rs index b63c6f0bd7c1d..6d68ae7bdcb37 100644 --- a/client/finality-grandpa/src/light_import.rs +++ b/client/finality-grandpa/src/light_import.rs @@ -130,7 +130,7 @@ impl BlockImport type Transaction = TransactionFor; fn import_block( - &mut self, + &self, block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -140,7 +140,7 @@ impl BlockImport } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.client.check_block(block) @@ -152,7 +152,7 @@ impl FinalityProofImport NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, BE: Backend + 'static, - for<'a> &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -236,7 +236,7 @@ impl FinalityProofRequestBuilder for GrandpaFinalityProofRequestBu /// Try to import new block. fn do_import_block( - mut client: C, + client: C, data: &mut LightImportData, mut block: BlockImportParams>, new_cache: HashMap>, @@ -627,7 +627,7 @@ pub mod tests { type Transaction = TransactionFor; fn import_block( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -636,7 +636,7 @@ pub mod tests { } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.0.check_block(block) @@ -834,7 +834,7 @@ pub mod tests { let initial_set = vec![(AuthorityId::from_slice(&[1; 32]), 1)]; let updated_set = vec![(AuthorityId::from_slice(&[2; 32]), 2)]; let babe_set_signal = vec![AuthorityId::from_slice(&[42; 32])].encode(); - + // import block #1 without justification let mut cache = HashMap::new(); cache.insert(well_known_cache_keys::AUTHORITIES, babe_set_signal); diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index a3e644558b6e6..e097e4cb04f5d 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -466,7 +466,7 @@ impl BlockImport for BlockImportAdapter { type Transaction = Transaction; fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { match self { @@ -476,7 +476,7 @@ impl BlockImport for BlockImportAdapter { } fn import_block( - &mut self, + &self, block: BlockImportParams, cache: HashMap>, ) -> Result { diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 922f34b656813..0f0fc059214c9 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -1661,7 +1661,7 @@ impl CallApiAt for Client where /// NOTE: only use this implementation when you are sure there are NO consensus-level BlockImport /// objects. Otherwise, importing blocks directly into the client would be bypassing /// important verification work. -impl sp_consensus::BlockImport for &Client where +impl sp_consensus::BlockImport for Client where B: backend::Backend, E: CallExecutor + Send + Sync, Block: BlockT, @@ -1682,7 +1682,7 @@ impl sp_consensus::BlockImport for &Client>, new_cache: HashMap>, ) -> Result { @@ -1706,7 +1706,7 @@ impl sp_consensus::BlockImport for &Client, ) -> Result { let BlockCheckParams { hash, number, parent_hash, allow_missing_state, import_existing } = block; @@ -1761,6 +1761,7 @@ impl sp_consensus::BlockImport for &Client sp_consensus::BlockImport for Client where B: backend::Backend, E: CallExecutor + Send + Sync, @@ -1773,20 +1774,21 @@ impl sp_consensus::BlockImport for Client; fn import_block( - &mut self, + &self, import_block: BlockImportParams, new_cache: HashMap>, ) -> Result { - (&*self).import_block(import_block, new_cache) + self.import_block(import_block, new_cache) } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { - (&*self).check_block(block) + &Client::check_block(self, block) } } +*/ impl Finalizer for Client where B: backend::Backend, diff --git a/primitives/consensus/common/src/block_import.rs b/primitives/consensus/common/src/block_import.rs index 5e593da1163d7..32979676a7cde 100644 --- a/primitives/consensus/common/src/block_import.rs +++ b/primitives/consensus/common/src/block_import.rs @@ -269,7 +269,7 @@ pub trait BlockImport { /// Check block preconditions. fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result; @@ -277,7 +277,7 @@ pub trait BlockImport { /// /// Cached data can be accessed through the blockchain cache. fn import_block( - &mut self, + &self, block: BlockImportParams, cache: HashMap>, ) -> Result; @@ -289,7 +289,7 @@ impl BlockImport for crate::import_queue::BoxBlockImp /// Check block preconditions. fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { (**self).check_block(block) @@ -299,7 +299,7 @@ impl BlockImport for crate::import_queue::BoxBlockImp /// /// Cached data can be accessed through the blockchain cache. fn import_block( - &mut self, + &self, block: BlockImportParams, cache: HashMap>, ) -> Result { @@ -314,14 +314,14 @@ impl BlockImpo type Transaction = Transaction; fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { (&**self).check_block(block) } fn import_block( - &mut self, + &self, block: BlockImportParams, cache: HashMap>, ) -> Result { From 231f0032e1f2425458f073baae6d8b9d3cad94c5 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 25 Jun 2020 16:58:14 +0200 Subject: [PATCH 06/12] WIP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- client/finality-grandpa/src/import.rs | 13 ++++--- client/finality-grandpa/src/light_import.rs | 34 +++++++++---------- client/transaction-pool/src/testing/pool.rs | 2 +- .../consensus/common/src/block_import.rs | 2 ++ test-utils/client/src/client_ext.rs | 24 ++++++------- test-utils/runtime/client/src/trait_tests.rs | 6 ++-- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/client/finality-grandpa/src/import.rs b/client/finality-grandpa/src/import.rs index 4bc02f7db8f2b..954d6b03f650c 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/finality-grandpa/src/import.rs @@ -23,9 +23,9 @@ use parity_scale_codec::Encode; use parking_lot::RwLockWriteGuard; use sp_blockchain::{BlockStatus, well_known_cache_keys}; -use sc_client_api::{backend::Backend, utils::is_descendent_of}; +use sc_client_api::{backend::Backend, utils::is_descendent_of, TransactionFor}; use sp_utils::mpsc::TracingUnboundedSender; -use sp_api::{TransactionFor}; +//use sp_api::{TransactionFor}; use sp_consensus::{ BlockImport, Error as ConsensusError, @@ -255,7 +255,7 @@ where fn make_authorities_changes( &self, - block: &mut BlockImportParams>, + block: &mut BlockImportParams>, hash: Block::Hash, initial_sync: bool, ) -> Result, ConsensusError> { @@ -406,12 +406,11 @@ impl BlockImport NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, BE: Backend, - Client: crate::ClientForGrandpa, - for<'a> &'a Client: - BlockImport>, + Client: crate::ClientForGrandpa + + BlockImport>, { type Error = ConsensusError; - type Transaction = TransactionFor; + type Transaction = TransactionFor; fn import_block( &self, diff --git a/client/finality-grandpa/src/light_import.rs b/client/finality-grandpa/src/light_import.rs index 6d68ae7bdcb37..8416636829224 100644 --- a/client/finality-grandpa/src/light_import.rs +++ b/client/finality-grandpa/src/light_import.rs @@ -120,7 +120,7 @@ impl BlockImport NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, BE: Backend + 'static, - for<'a> &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -135,7 +135,7 @@ impl BlockImport new_cache: HashMap>, ) -> Result { do_import_block::<_, _, _, GrandpaJustification>( - &*self.client, &mut *self.data.write(), block, new_cache + self.client.clone(), &mut *self.data.write(), block, new_cache ) } @@ -184,7 +184,7 @@ impl FinalityProofImport verifier: &mut dyn Verifier, ) -> Result<(Block::Hash, NumberFor), Self::Error> { do_import_finality_proof::<_, _, _, GrandpaJustification>( - &*self.client, + self.client.clone(), self.backend.clone(), &*self.authority_set_provider, &mut *self.data.write(), @@ -236,7 +236,7 @@ impl FinalityProofRequestBuilder for GrandpaFinalityProofRequestBu /// Try to import new block. fn do_import_block( - client: C, + client: Arc, data: &mut LightImportData, mut block: BlockImportParams>, new_cache: HashMap>, @@ -245,8 +245,7 @@ fn do_import_block( C: HeaderBackend + AuxStore + Finalizer - + BlockImport> - + Clone, + + BlockImport>, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, @@ -295,7 +294,7 @@ fn do_import_block( /// Try to import finality proof. fn do_import_finality_proof( - client: C, + client: Arc, backend: Arc, authority_set_provider: &dyn AuthoritySetForFinalityChecker, data: &mut LightImportData, @@ -308,8 +307,8 @@ fn do_import_finality_proof( C: HeaderBackend + AuxStore + Finalizer - + BlockImport> - + Clone, + + BlockImport>, + //+ Clone, B: Backend + 'static, DigestFor: Encode, NumberFor: finality_grandpa::BlockNumberOps, @@ -372,7 +371,7 @@ fn do_import_finality_proof( // store new authorities set require_insert_aux( - &client, + &*client, LIGHT_AUTHORITY_SET_KEY, &data.authority_set, "authority set", @@ -383,7 +382,7 @@ fn do_import_finality_proof( /// Try to import justification. fn do_import_justification( - client: C, + client: Arc, data: &mut LightImportData, hash: Block::Hash, number: NumberFor, @@ -392,8 +391,7 @@ fn do_import_justification( where C: HeaderBackend + AuxStore - + Finalizer - + Clone, + + Finalizer, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, J: ProvableJustification, @@ -454,7 +452,7 @@ fn do_import_justification( /// Finalize the block. fn do_finalize_block( - client: C, + client: Arc, data: &mut LightImportData, hash: Block::Hash, number: NumberFor, @@ -463,8 +461,8 @@ fn do_finalize_block( where C: HeaderBackend + AuxStore - + Finalizer - + Clone, + + Finalizer, + //+ Clone, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, { @@ -478,11 +476,11 @@ fn do_finalize_block( let consensus_finalization_res = data.consensus_changes .finalize( (number, hash), - |at_height| canonical_at_height(&client, (hash, number), true, at_height) + |at_height| canonical_at_height(&*client, (hash, number), true, at_height) ); match consensus_finalization_res { Ok((true, _)) => require_insert_aux( - &client, + &*client, LIGHT_CONSENSUS_CHANGES_KEY, &data.consensus_changes, "consensus changes", diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 61aba5efe3bfa..3a28d7fb4c9cc 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -1041,7 +1041,7 @@ fn should_not_accept_old_signatures() { #[test] fn import_notification_to_pool_maintain_works() { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let:client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( BasicPool::new_test(Arc::new(FullChainApi::new(client.clone()))).0 diff --git a/primitives/consensus/common/src/block_import.rs b/primitives/consensus/common/src/block_import.rs index 32979676a7cde..d9d6deac4c47e 100644 --- a/primitives/consensus/common/src/block_import.rs +++ b/primitives/consensus/common/src/block_import.rs @@ -307,6 +307,7 @@ impl BlockImport for crate::import_queue::BoxBlockImp } } +/* impl BlockImport for Arc where for<'r> &'r T: BlockImport { @@ -328,6 +329,7 @@ impl BlockImpo (&**self).import_block(block, cache) } } +*/ /// Justification import trait pub trait JustificationImport { diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index 706a7b6e95a85..168a2cb7bb76e 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -44,18 +44,18 @@ pub trait ClientExt: Sized { /// Extension trait for a test client around block importing. pub trait ClientBlockImportExt: Sized { /// Import block to the chain. No finality. - fn import(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; + fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; /// Import a block and make it our best block if possible. - fn import_as_best(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; + fn import_as_best(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; /// Import a block and finalize it. - fn import_as_final(&mut self, origin: BlockOrigin, block: Block) + fn import_as_final(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; /// Import block with justification, finalizes block. fn import_justified( - &mut self, + &self, origin: BlockOrigin, block: Block, justification: Justification @@ -86,7 +86,7 @@ impl ClientExt for Client impl ClientBlockImportExt for std::sync::Arc where for<'r> &'r T: BlockImport { - fn import(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { + fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -95,7 +95,7 @@ impl ClientBlockImportExt for std::sync::A BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } - fn import_as_best(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { + fn import_as_best(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -104,7 +104,7 @@ impl ClientBlockImportExt for std::sync::A BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } - fn import_as_final(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { + fn import_as_final(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -115,7 +115,7 @@ impl ClientBlockImportExt for std::sync::A } fn import_justified( - &mut self, + &self, origin: BlockOrigin, block: Block, justification: Justification, @@ -135,7 +135,7 @@ impl ClientBlockImportExt for Client, { - fn import(&mut self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { + fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -144,7 +144,7 @@ impl ClientBlockImportExt for Client Result<(), ConsensusError> { + fn import_as_best(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -153,7 +153,7 @@ impl ClientBlockImportExt for Client Result<(), ConsensusError> { + fn import_as_final(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); let mut import = BlockImportParams::new(origin, header); import.body = Some(extrinsics); @@ -164,7 +164,7 @@ impl ClientBlockImportExt for Client(backend: Arc) where // B2 -> C3 // A1 -> D2 - let mut client = TestClientBuilder::with_backend(backend.clone()).build(); + let client = TestClientBuilder::with_backend(backend.clone()).build(); let blockchain = backend.blockchain(); let genesis_hash = client.chain_info().genesis_hash; @@ -215,7 +215,7 @@ pub fn test_children_for_backend(backend: Arc) where // B2 -> C3 // A1 -> D2 - let mut client = TestClientBuilder::with_backend(backend.clone()).build(); + let client = TestClientBuilder::with_backend(backend.clone()).build(); let blockchain = backend.blockchain(); // G -> A1 @@ -344,7 +344,7 @@ pub fn test_blockchain_query_by_number_gets_canonical(backend: Arc B2 -> B3 -> B4 // B2 -> C3 // A1 -> D2 - let mut client = TestClientBuilder::with_backend(backend.clone()).build(); + let client = TestClientBuilder::with_backend(backend.clone()).build(); let blockchain = backend.blockchain(); // G -> A1 From c63d5d2a1e0882797e4de4c6ff7bdffcd92c7975 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Thu, 25 Jun 2020 17:44:32 +0200 Subject: [PATCH 07/12] WIP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- client/finality-grandpa/src/light_import.rs | 12 ++++++------ client/finality-grandpa/src/tests.rs | 2 +- client/network/test/src/lib.rs | 3 +-- client/transaction-pool/src/testing/pool.rs | 2 +- primitives/consensus/common/src/block_import.rs | 4 +--- test-utils/client/src/client_ext.rs | 4 +++- test-utils/runtime/client/src/lib.rs | 6 +++--- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/client/finality-grandpa/src/light_import.rs b/client/finality-grandpa/src/light_import.rs index 8416636829224..85b8f27d8c863 100644 --- a/client/finality-grandpa/src/light_import.rs +++ b/client/finality-grandpa/src/light_import.rs @@ -613,7 +613,7 @@ pub mod tests { NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, BE: Backend + 'static, - for <'a > &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -646,7 +646,7 @@ pub mod tests { NumberFor: finality_grandpa::BlockNumberOps, BE: Backend + 'static, DigestFor: Encode, - for <'a > &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -689,7 +689,7 @@ pub mod tests { justification: Option, ) -> ( ImportResult, - substrate_test_runtime_client::client::Client, + Arc>, Arc, ) { let (client, backend) = substrate_test_runtime_client::new_light(); @@ -713,7 +713,7 @@ pub mod tests { ( do_import_block::<_, _, _, TestJustification>( - &client, + client.clone(), &mut import_data, block, new_cache, @@ -849,7 +849,7 @@ pub mod tests { // import finality proof do_import_finality_proof::<_, _, _, TestJustification>( - &client, + client.clone(), backend, &ClosureAuthoritySetForFinalityChecker( |_, _, _| Ok(updated_set.clone()) @@ -872,7 +872,7 @@ pub mod tests { ).unwrap(); // verify that new authorities set has been saved to the aux storage - let data = load_aux_import_data(Default::default(), &client, &TestApi::new(initial_set)).unwrap(); + let data = load_aux_import_data(Default::default(), &*client, &TestApi::new(initial_set)).unwrap(); assert_eq!(data.authority_set.authorities(), updated_set); } } diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index ffd8f1c8c642d..f6e97b5169536 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -151,7 +151,7 @@ impl TestNetFactory for GrandpaTestNet { ( BlockImportAdapter::new_light(import), None, - Some(proof_import), + Some(proof_import.clone()), Some(finality_proof_req_builder), Mutex::new(None), ) diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index e097e4cb04f5d..ecfec03c70483 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -669,8 +669,7 @@ pub trait TestNetFactory: Sized { /// Add a light peer. fn add_light_peer(&mut self) { - let (c, backend) = substrate_test_runtime_client::new_light(); - let client = Arc::new(c); + let (client, backend) = substrate_test_runtime_client::new_light(); let ( block_import, justification_import, diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 3a28d7fb4c9cc..59d7ddaa6dca1 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -1041,7 +1041,7 @@ fn should_not_accept_old_signatures() { #[test] fn import_notification_to_pool_maintain_works() { - let:client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let pool = Arc::new( BasicPool::new_test(Arc::new(FullChainApi::new(client.clone()))).0 diff --git a/primitives/consensus/common/src/block_import.rs b/primitives/consensus/common/src/block_import.rs index d9d6deac4c47e..e9f61a1acdf9f 100644 --- a/primitives/consensus/common/src/block_import.rs +++ b/primitives/consensus/common/src/block_import.rs @@ -307,9 +307,8 @@ impl BlockImport for crate::import_queue::BoxBlockImp } } -/* impl BlockImport for Arc - where for<'r> &'r T: BlockImport + where T: BlockImport { type Error = E; type Transaction = Transaction; @@ -329,7 +328,6 @@ impl BlockImpo (&**self).import_block(block, cache) } } -*/ /// Justification import trait pub trait JustificationImport { diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index 168a2cb7bb76e..ed7df24bc9c91 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -83,8 +83,9 @@ impl ClientExt for Client } /// This implementation is required, because of the weird api requirements around `BlockImport`. +/* impl ClientBlockImportExt for std::sync::Arc - where for<'r> &'r T: BlockImport + where T: BlockImport { fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { let (header, extrinsics) = block.deconstruct(); @@ -130,6 +131,7 @@ impl ClientBlockImportExt for std::sync::A BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } } +*/ impl ClientBlockImportExt for Client where diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 4e9034fb4d493..d580251d343e0 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -342,7 +342,7 @@ pub fn new() -> Client { /// Creates new light client instance used for tests. pub fn new_light() -> ( - client::Client, + Arc>, Arc, ) { @@ -357,9 +357,9 @@ pub fn new_light() -> ( ); ( - TestClientBuilder::with_backend(backend.clone()) + Arc::new(TestClientBuilder::with_backend(backend.clone()) .build_with_executor(call_executor) - .0, + .0), backend, ) } From 775c5372c16dacf4c55758ff02d7a1005d227fce Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 26 Jun 2020 08:26:30 +0200 Subject: [PATCH 08/12] WIP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- test-utils/client/src/client_ext.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index ed7df24bc9c91..cf15f1974e9f4 100644 --- a/test-utils/client/src/client_ext.rs +++ b/test-utils/client/src/client_ext.rs @@ -83,7 +83,6 @@ impl ClientExt for Client } /// This implementation is required, because of the weird api requirements around `BlockImport`. -/* impl ClientBlockImportExt for std::sync::Arc where T: BlockImport { @@ -131,7 +130,6 @@ impl ClientBlockImportExt for std::sync::A BlockImport::import_block(self, import, HashMap::new()).map(|_| ()) } } -*/ impl ClientBlockImportExt for Client where From f4ba14ff138a106c1217e49c7f10d42364738540 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 26 Jun 2020 09:25:54 +0200 Subject: [PATCH 09/12] CLEANUP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- client/finality-grandpa/src/import.rs | 1 - client/finality-grandpa/src/light_import.rs | 2 -- client/service/src/client/client.rs | 29 --------------------- 3 files changed, 32 deletions(-) diff --git a/client/finality-grandpa/src/import.rs b/client/finality-grandpa/src/import.rs index 954d6b03f650c..79a04cdfab3c2 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/finality-grandpa/src/import.rs @@ -25,7 +25,6 @@ use parking_lot::RwLockWriteGuard; use sp_blockchain::{BlockStatus, well_known_cache_keys}; use sc_client_api::{backend::Backend, utils::is_descendent_of, TransactionFor}; use sp_utils::mpsc::TracingUnboundedSender; -//use sp_api::{TransactionFor}; use sp_consensus::{ BlockImport, Error as ConsensusError, diff --git a/client/finality-grandpa/src/light_import.rs b/client/finality-grandpa/src/light_import.rs index 85b8f27d8c863..3e535f9cc7b72 100644 --- a/client/finality-grandpa/src/light_import.rs +++ b/client/finality-grandpa/src/light_import.rs @@ -308,7 +308,6 @@ fn do_import_finality_proof( + AuxStore + Finalizer + BlockImport>, - //+ Clone, B: Backend + 'static, DigestFor: Encode, NumberFor: finality_grandpa::BlockNumberOps, @@ -462,7 +461,6 @@ fn do_finalize_block( C: HeaderBackend + AuxStore + Finalizer, - //+ Clone, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, { diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 0f0fc059214c9..05d440f363e20 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -1761,35 +1761,6 @@ impl sp_consensus::BlockImport for Client sp_consensus::BlockImport for Client where - B: backend::Backend, - E: CallExecutor + Send + Sync, - Block: BlockT, - Self: ProvideRuntimeApi, - >::Api: CoreApi + - ApiExt, -{ - type Error = ConsensusError; - type Transaction = backend::TransactionFor; - - fn import_block( - &self, - import_block: BlockImportParams, - new_cache: HashMap>, - ) -> Result { - self.import_block(import_block, new_cache) - } - - fn check_block( - &self, - block: BlockCheckParams, - ) -> Result { - &Client::check_block(self, block) - } -} -*/ - impl Finalizer for Client where B: backend::Backend, E: CallExecutor, From c20a5e3f34893a1a406ff48da1e9771fe02c583f Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 26 Jun 2020 09:32:57 +0200 Subject: [PATCH 10/12] CLEANUP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- bin/node/executor/tests/basic.rs | 2 +- .../basic-authorship/src/basic_authorship.rs | 2 +- client/finality-grandpa/src/tests.rs | 6 ++-- client/network/test/src/block_import.rs | 2 +- client/rpc/src/chain/tests.rs | 12 +++---- client/rpc/src/state/tests.rs | 6 ++-- client/service/test/src/client/light.rs | 4 +-- client/service/test/src/client/mod.rs | 34 +++++++++---------- test-utils/runtime/src/lib.rs | 2 +- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/bin/node/executor/tests/basic.rs b/bin/node/executor/tests/basic.rs index 2bb444b47c9be..e3ff76bcb2fec 100644 --- a/bin/node/executor/tests/basic.rs +++ b/bin/node/executor/tests/basic.rs @@ -817,7 +817,7 @@ fn should_import_block_with_test_client() { sp_consensus::BlockOrigin, }; - let mut client = TestClientBuilder::new().build(); + let client = TestClientBuilder::new().build(); let block1 = changes_trie_block(); let block_data = block1.0; let block = node_primitives::Block::decode(&mut &block_data[..]).unwrap(); diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index 383d0ea6fcad4..b9506bb8d4be8 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/client/basic-authorship/src/basic_authorship.rs @@ -516,7 +516,7 @@ mod tests { #[test] fn should_not_remove_invalid_transactions_when_skipping() { // given - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let txpool = Arc::new( BasicPool::new( Default::default(), diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index f6e97b5169536..ccf770a71158a 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -913,7 +913,7 @@ fn allows_reimporting_change_blocks() { let mut net = GrandpaTestNet::new(api.clone(), 3); let client = net.peer(0).client().clone(); - let (mut block_import, ..) = net.make_block_import::< + let (block_import, ..) = net.make_block_import::< TransactionFor >( client.clone(), @@ -963,7 +963,7 @@ fn test_bad_justification() { let mut net = GrandpaTestNet::new(api.clone(), 3); let client = net.peer(0).client().clone(); - let (mut block_import, ..) = net.make_block_import::< + let (block_import, ..) = net.make_block_import::< TransactionFor >( client.clone(), @@ -1660,7 +1660,7 @@ fn imports_justification_for_regular_blocks_on_import() { let mut net = GrandpaTestNet::new(api.clone(), 1); let client = net.peer(0).client().clone(); - let (mut block_import, ..) = net.make_block_import::< + let (block_import, ..) = net.make_block_import::< TransactionFor >(client.clone()); diff --git a/client/network/test/src/block_import.rs b/client/network/test/src/block_import.rs index 46a395700c54d..00d2646c18141 100644 --- a/client/network/test/src/block_import.rs +++ b/client/network/test/src/block_import.rs @@ -29,7 +29,7 @@ use sc_block_builder::BlockBuilderProvider; use super::*; fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock) { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); let block = client.new_block(Default::default()).unwrap().build().unwrap().block; client.import(BlockOrigin::File, block).unwrap(); diff --git a/client/rpc/src/chain/tests.rs b/client/rpc/src/chain/tests.rs index b36fc4eab1d86..42ff2511624e4 100644 --- a/client/rpc/src/chain/tests.rs +++ b/client/rpc/src/chain/tests.rs @@ -62,7 +62,7 @@ fn should_return_header() { #[test] fn should_return_a_block() { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); let block = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -113,7 +113,7 @@ fn should_return_a_block() { #[test] fn should_return_block_hash() { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); assert_matches!( @@ -157,7 +157,7 @@ fn should_return_block_hash() { #[test] fn should_return_finalized_hash() { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); assert_matches!( @@ -187,7 +187,7 @@ fn should_notify_about_latest_block() { let (subscriber, id, transport) = Subscriber::new_test("test"); { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); api.subscribe_all_heads(Default::default(), subscriber); @@ -217,7 +217,7 @@ fn should_notify_about_best_block() { let (subscriber, id, transport) = Subscriber::new_test("test"); { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); api.subscribe_new_heads(Default::default(), subscriber); @@ -247,7 +247,7 @@ fn should_notify_about_finalized_block() { let (subscriber, id, transport) = Subscriber::new_test("test"); { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); api.subscribe_finalized_heads(Default::default(), subscriber); diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 0cc16ce8d5e92..0f36b3ac0291b 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -138,7 +138,7 @@ fn should_notify_about_storage_changes() { let (subscriber, id, transport) = Subscriber::new_test("test"); { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let (api, _child) = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); api.subscribe_storage(Default::default(), subscriber, None.into()); @@ -172,7 +172,7 @@ fn should_send_initial_storage_changes_and_notifications() { let (subscriber, id, transport) = Subscriber::new_test("test"); { - let mut client = Arc::new(substrate_test_runtime_client::new()); + let client = Arc::new(substrate_test_runtime_client::new()); let (api, _child) = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into())); @@ -210,7 +210,7 @@ fn should_send_initial_storage_changes_and_notifications() { #[test] fn should_query_storage() { - fn run_tests(mut client: Arc, has_changes_trie_config: bool) { + fn run_tests(client: Arc, has_changes_trie_config: bool) { let (api, _child) = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); let mut add_block = |nonce| { diff --git a/client/service/test/src/client/light.rs b/client/service/test/src/client/light.rs index 994d846c6a088..45a5fe4760cad 100644 --- a/client/service/test/src/client/light.rs +++ b/client/service/test/src/client/light.rs @@ -363,7 +363,7 @@ fn execution_proof_is_generated_and_checked() { } // prepare remote client - let mut remote_client = substrate_test_runtime_client::new(); + let remote_client = substrate_test_runtime_client::new(); for i in 1u32..3u32 { let mut digest = Digest::default(); digest.push(sp_runtime::generic::DigestItem::Other::(i.to_le_bytes().to_vec())); @@ -528,7 +528,7 @@ fn prepare_for_read_child_proof_check() -> (TestChecker, Header, StorageProof, V fn prepare_for_header_proof_check(insert_cht: bool) -> (TestChecker, Hash, Header, StorageProof) { // prepare remote client - let mut remote_client = substrate_test_runtime_client::new(); + let remote_client = substrate_test_runtime_client::new(); let mut local_headers_hashes = Vec::new(); for i in 0..4 { let block = remote_client.new_block(Default::default()).unwrap().build().unwrap().block; diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index 2124f0ced4122..69ea561a2e888 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -91,7 +91,7 @@ pub fn prepare_client_with_key_changes() -> ( // prepare client ang import blocks let mut local_roots = Vec::new(); let config = Some(ChangesTrieConfiguration::new(4, 2)); - let mut remote_client = TestClientBuilder::new().changes_trie_config(config).build(); + let remote_client = TestClientBuilder::new().changes_trie_config(config).build(); let mut nonces: HashMap<_, u64> = Default::default(); for (i, block_transfers) in blocks_transfers.into_iter().enumerate() { let mut builder = remote_client.new_block(Default::default()).unwrap(); @@ -364,7 +364,7 @@ fn client_initializes_from_genesis_ok() { #[test] fn block_builder_works_with_no_transactions() { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); let block = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -375,7 +375,7 @@ fn block_builder_works_with_no_transactions() { #[test] fn block_builder_works_with_transactions() { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); let mut builder = client.new_block(Default::default()).unwrap(); @@ -412,7 +412,7 @@ fn block_builder_works_with_transactions() { #[test] fn block_builder_does_not_include_invalid() { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); let mut builder = client.new_block(Default::default()).unwrap(); @@ -477,7 +477,7 @@ fn best_containing_with_hash_not_found() { fn uncles_with_only_ancestors() { // block tree: // G -> A1 -> A2 - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -497,7 +497,7 @@ fn uncles_with_multiple_forks() { // A1 -> B2 -> B3 -> B4 // B2 -> C3 // A1 -> D2 - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -625,7 +625,7 @@ fn best_containing_on_longest_chain_with_single_chain_3_blocks() { // block tree: // G -> A1 -> A2 - let (mut client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -649,7 +649,7 @@ fn best_containing_on_longest_chain_with_multiple_forks() { // A1 -> B2 -> B3 -> B4 // B2 -> C3 // A1 -> D2 - let (mut client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -969,7 +969,7 @@ fn best_containing_on_longest_chain_with_max_depth_higher_than_best() { // block tree: // G -> A1 -> A2 - let (mut client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -1006,7 +1006,7 @@ fn key_changes_works() { #[test] fn import_with_justification() { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); // G -> A1 let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block; @@ -1052,7 +1052,7 @@ fn import_with_justification() { #[test] fn importing_diverged_finalized_block_should_trigger_reorg() { - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); // G -> A1 -> A2 // \ @@ -1109,7 +1109,7 @@ fn importing_diverged_finalized_block_should_trigger_reorg() { #[test] fn finalizing_diverged_block_should_trigger_reorg() { - let (mut client, select_chain) = TestClientBuilder::new().build_with_longest_chain(); + let (client, select_chain) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 -> A2 // \ @@ -1207,7 +1207,7 @@ fn get_header_by_block_number_doesnt_panic() { #[test] fn state_reverted_on_reorg() { let _ = env_logger::try_init(); - let mut client = substrate_test_runtime_client::new(); + let client = substrate_test_runtime_client::new(); let current_balance = |client: &substrate_test_runtime_client::TestClient| client.runtime_api().balance_of( @@ -1284,7 +1284,7 @@ fn doesnt_import_blocks_that_revert_finality() { u64::max_value(), ).unwrap()); - let mut client = TestClientBuilder::with_backend(backend).build(); + let client = TestClientBuilder::with_backend(backend).build(); // -> C1 // / @@ -1373,7 +1373,7 @@ fn respects_block_rules() { known_bad: &mut HashSet, fork_rules: &mut Vec<(u64, H256)>, ) { - let mut client = if record_only { + let client = if record_only { TestClientBuilder::new().build() } else { TestClientBuilder::new() @@ -1485,7 +1485,7 @@ fn returns_status_for_pruned_blocks() { u64::max_value(), ).unwrap()); - let mut client = TestClientBuilder::with_backend(backend).build(); + let client = TestClientBuilder::with_backend(backend).build(); let a1 = client.new_block_at(&BlockId::Number(0), Default::default(), false) .unwrap().build().unwrap().block; @@ -1571,7 +1571,7 @@ fn returns_status_for_pruned_blocks() { #[test] fn imports_blocks_with_changes_tries_config_change() { // create client with initial 4^2 configuration - let mut client = TestClientBuilder::with_default_backend() + let client = TestClientBuilder::with_default_backend() .changes_trie_config(Some(ChangesTrieConfiguration { digest_interval: 4, digest_levels: 2, diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index bf6c7450c5086..3083a365d577e 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -1034,7 +1034,7 @@ mod tests { // This tests that the on-chain HEAP_PAGES parameter is respected. // Create a client devoting only 8 pages of wasm memory. This gives us ~512k of heap memory. - let mut client = TestClientBuilder::new() + let client = TestClientBuilder::new() .set_execution_strategy(ExecutionStrategy::AlwaysWasm) .set_heap_pages(8) .build(); From c9fa900f8d4ce0b23a35cb174e5268332708fc1c Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 26 Jun 2020 09:42:10 +0200 Subject: [PATCH 11/12] CLEANUP Forked at: 606c56d2e2f69f68f3947551224be6a3515dff60 Parent branch: origin/master --- client/rpc/src/state/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 0f36b3ac0291b..5b7e834791368 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -213,7 +213,7 @@ fn should_query_storage() { fn run_tests(client: Arc, has_changes_trie_config: bool) { let (api, _child) = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor))); - let mut add_block = |nonce| { + let add_block = |nonce| { let mut builder = client.new_block(Default::default()).unwrap(); // fake change: None -> None -> None builder.push_storage_change(vec![1], None).unwrap(); From c85d56ad9a13a03ecd7f8774935aa8060c79433a Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Fri, 26 Jun 2020 12:14:58 +0200 Subject: [PATCH 12/12] fix line width --- client/finality-grandpa/src/light_import.rs | 7 ++++++- test-utils/runtime/client/src/lib.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/client/finality-grandpa/src/light_import.rs b/client/finality-grandpa/src/light_import.rs index 3e535f9cc7b72..6566f89c3a155 100644 --- a/client/finality-grandpa/src/light_import.rs +++ b/client/finality-grandpa/src/light_import.rs @@ -687,7 +687,12 @@ pub mod tests { justification: Option, ) -> ( ImportResult, - Arc>, + Arc>, Arc, ) { let (client, backend) = substrate_test_runtime_client::new_light(); diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index d580251d343e0..ee8aa98226294 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -342,7 +342,12 @@ pub fn new() -> Client { /// Creates new light client instance used for tests. pub fn new_light() -> ( - Arc>, + Arc>, Arc, ) {