diff --git a/bin/node/executor/tests/basic.rs b/bin/node/executor/tests/basic.rs index e4de98d90e94d..04302a2ab7f5c 100644 --- a/bin/node/executor/tests/basic.rs +++ b/bin/node/executor/tests/basic.rs @@ -810,7 +810,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/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 8b30720d0b130..681a86c9fa183 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 961b0382c5858..4872496d2f637 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 1caed18c1781e..37cd4b5d2936d 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -192,7 +192,7 @@ impl> BlockImport for PanickingBlockImport< type Transaction = B::Transaction; fn import_block( - &mut self, + &self, block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -200,7 +200,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 8c15528795c55..fd9f7b59f0820 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..79a04cdfab3c2 100644 --- a/client/finality-grandpa/src/import.rs +++ b/client/finality-grandpa/src/import.rs @@ -23,9 +23,8 @@ 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_consensus::{ BlockImport, Error as ConsensusError, @@ -255,7 +254,7 @@ where fn make_authorities_changes( &self, - block: &mut BlockImportParams>, + block: &mut BlockImportParams>, hash: Block::Hash, initial_sync: bool, ) -> Result, ConsensusError> { @@ -406,15 +405,14 @@ 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( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -437,7 +435,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 +543,7 @@ impl BlockImport } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.inner.check_block(block) @@ -620,7 +618,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..6566f89c3a155 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 @@ -130,17 +130,17 @@ impl BlockImport type Transaction = TransactionFor; fn import_block( - &mut self, + &self, block: BlockImportParams, 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 ) } 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 @@ -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( - mut 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,7 @@ fn do_import_finality_proof( C: HeaderBackend + AuxStore + Finalizer - + BlockImport> - + Clone, + + BlockImport>, B: Backend + 'static, DigestFor: Encode, NumberFor: finality_grandpa::BlockNumberOps, @@ -372,7 +370,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 +381,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 +390,7 @@ fn do_import_justification( where C: HeaderBackend + AuxStore - + Finalizer - + Clone, + + Finalizer, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, J: ProvableJustification, @@ -454,7 +451,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 +460,7 @@ fn do_finalize_block( where C: HeaderBackend + AuxStore - + Finalizer - + Clone, + + Finalizer, B: Backend + 'static, NumberFor: finality_grandpa::BlockNumberOps, { @@ -478,11 +474,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", @@ -615,7 +611,7 @@ pub mod tests { NumberFor: finality_grandpa::BlockNumberOps, DigestFor: Encode, BE: Backend + 'static, - for <'a > &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -627,7 +623,7 @@ pub mod tests { type Transaction = TransactionFor; fn import_block( - &mut self, + &self, mut block: BlockImportParams, new_cache: HashMap>, ) -> Result { @@ -636,7 +632,7 @@ pub mod tests { } fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { self.0.check_block(block) @@ -648,7 +644,7 @@ pub mod tests { NumberFor: finality_grandpa::BlockNumberOps, BE: Backend + 'static, DigestFor: Encode, - for <'a > &'a Client: + Client: HeaderBackend + BlockImport> + Finalizer @@ -691,7 +687,12 @@ pub mod tests { justification: Option, ) -> ( ImportResult, - substrate_test_runtime_client::client::Client, + Arc>, Arc, ) { let (client, backend) = substrate_test_runtime_client::new_light(); @@ -715,7 +716,7 @@ pub mod tests { ( do_import_block::<_, _, _, TestJustification>( - &client, + client.clone(), &mut import_data, block, new_cache, @@ -834,7 +835,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); @@ -851,7 +852,7 @@ pub mod tests { // import finality proof do_import_finality_proof::<_, _, _, TestJustification>( - &client, + client.clone(), backend, &ClosureAuthoritySetForFinalityChecker( |_, _, _| Ok(updated_set.clone()) @@ -874,7 +875,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..ccf770a71158a 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), ) @@ -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/network/test/src/lib.rs b/client/network/test/src/lib.rs index a3e644558b6e6..ecfec03c70483 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 { @@ -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/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..5b7e834791368 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,10 +210,10 @@ 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| { + 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(); diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 922f34b656813..05d440f363e20 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,33 +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( - &mut self, - import_block: BlockImportParams, - new_cache: HashMap>, - ) -> Result { - (&*self).import_block(import_block, new_cache) - } - - fn check_block( - &mut self, - block: BlockCheckParams, - ) -> Result { - (&*self).check_block(block) - } -} - impl Finalizer for Client where B: backend::Backend, E: CallExecutor, 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/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 61aba5efe3bfa..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 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 5e593da1163d7..e9f61a1acdf9f 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 { @@ -308,20 +308,20 @@ 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; fn check_block( - &mut self, + &self, block: BlockCheckParams, ) -> Result { (&**self).check_block(block) } fn import_block( - &mut self, + &self, block: BlockImportParams, cache: HashMap>, ) -> Result { diff --git a/test-utils/client/src/client_ext.rs b/test-utils/client/src/client_ext.rs index 706a7b6e95a85..cf15f1974e9f4 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 @@ -84,9 +84,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(&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 Client { /// Creates new light client instance used for tests. pub fn new_light() -> ( - client::Client, + Arc>, Arc, ) { @@ -357,9 +362,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, ) } diff --git a/test-utils/runtime/client/src/trait_tests.rs b/test-utils/runtime/client/src/trait_tests.rs index 537ff1197e7ef..7540c9a86ff37 100644 --- a/test-utils/runtime/client/src/trait_tests.rs +++ b/test-utils/runtime/client/src/trait_tests.rs @@ -46,7 +46,7 @@ pub fn test_leaves_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(); 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 diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 1d376a0940bbe..aaf6710c23b82 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -1051,7 +1051,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();