diff --git a/bin/node/cli/benches/block_production.rs b/bin/node/cli/benches/block_production.rs index 4fcebb123d9e3..64ea03f58289a 100644 --- a/bin/node/cli/benches/block_production.rs +++ b/bin/node/cli/benches/block_production.rs @@ -37,7 +37,6 @@ use sp_blockchain::{ApplyExtrinsicFailed::Validity, Error::ApplyExtrinsicFailed} use sp_consensus::BlockOrigin; use sp_keyring::Sr25519Keyring; use sp_runtime::{ - generic::BlockId, transaction_validity::{InvalidTransaction, TransactionValidityError}, AccountId32, MultiAddress, OpaqueExtrinsic, }; @@ -206,14 +205,14 @@ fn block_production(c: &mut Criterion) { group.sample_size(10); group.throughput(Throughput::Elements(max_transfer_count as u64)); - let block_id = BlockId::Hash(client.chain_info().best_hash); + let best_hash = client.chain_info().best_hash; group.bench_function(format!("{} transfers (no proof)", max_transfer_count), |b| { b.iter_batched( || extrinsics.clone(), |extrinsics| { let mut block_builder = - client.new_block_at(&block_id, Default::default(), RecordProof::No).unwrap(); + client.new_block_at(best_hash, Default::default(), RecordProof::No).unwrap(); for extrinsic in extrinsics { block_builder.push(extrinsic).unwrap(); } @@ -228,7 +227,7 @@ fn block_production(c: &mut Criterion) { || extrinsics.clone(), |extrinsics| { let mut block_builder = - client.new_block_at(&block_id, Default::default(), RecordProof::Yes).unwrap(); + client.new_block_at(best_hash, Default::default(), RecordProof::Yes).unwrap(); for extrinsic in extrinsics { block_builder.push(extrinsic).unwrap(); } diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index 9ab7ef55fb03a..f68a86ef12a39 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/client/basic-authorship/src/basic_authorship.rs @@ -38,7 +38,6 @@ use sp_consensus::{DisableProofRecording, EnableProofRecording, ProofRecording, use sp_core::traits::SpawnNamed; use sp_inherents::InherentData; use sp_runtime::{ - generic::BlockId, traits::{BlakeTwo256, Block as BlockT, Hash as HashT, Header as HeaderT}, Digest, Percent, SaturatedConversion, }; @@ -196,14 +195,12 @@ where ) -> Proposer { let parent_hash = parent_header.hash(); - let id = BlockId::hash(parent_hash); - info!("🙌 Starting consensus session on top of parent {:?}", parent_hash); let proposer = Proposer::<_, _, _, _, PR> { spawn_handle: self.spawn_handle.clone(), client: self.client.clone(), - parent_id: id, + parent_hash, parent_number: *parent_header.number(), transaction_pool: self.transaction_pool.clone(), now, @@ -247,7 +244,7 @@ where pub struct Proposer { spawn_handle: Box, client: Arc, - parent_id: BlockId, + parent_hash: Block::Hash, parent_number: <::Header as HeaderT>::Number, transaction_pool: Arc, now: Box time::Instant + Send + Sync>, @@ -344,7 +341,7 @@ where { let propose_with_start = time::Instant::now(); let mut block_builder = - self.client.new_block_at(&self.parent_id, inherent_digests, PR::ENABLED)?; + self.client.new_block_at(self.parent_hash, inherent_digests, PR::ENABLED)?; let create_inherents_start = time::Instant::now(); let inherents = block_builder.create_inherents(inherent_data)?; @@ -559,7 +556,7 @@ mod tests { use sp_blockchain::HeaderBackend; use sp_consensus::{BlockOrigin, Environment, Proposer}; use sp_core::Pair; - use sp_runtime::traits::NumberFor; + use sp_runtime::{generic::BlockId, traits::NumberFor}; use substrate_test_runtime_client::{ prelude::*, runtime::{Extrinsic, Transfer}, diff --git a/client/beefy/src/tests.rs b/client/beefy/src/tests.rs index f17a42f2045a5..d8afc5465eaad 100644 --- a/client/beefy/src/tests.rs +++ b/client/beefy/src/tests.rs @@ -58,7 +58,6 @@ use sp_keystore::{testing::KeyStore as TestKeystore, SyncCryptoStore, SyncCrypto use sp_mmr_primitives::{Error as MmrError, MmrApi}; use sp_runtime::{ codec::Encode, - generic::BlockId, traits::{Header as HeaderT, NumberFor}, BuildStorage, DigestItem, EncodedJustification, Justifications, Storage, }; @@ -753,8 +752,9 @@ async fn beefy_importing_justifications() { .and_then(|j| j.get(BEEFY_ENGINE_ID).cloned()) }; - let parent_id = BlockId::Number(0); - let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap(); + let builder = full_client + .new_block_at(full_client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); let block = builder.build().unwrap().block; let hashof1 = block.header.hash(); @@ -772,9 +772,8 @@ async fn beefy_importing_justifications() { ); // Import block 2 with "valid" justification (beefy pallet genesis block not yet reached). - let parent_id = BlockId::Number(1); let block_num = 2; - let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap(); + let builder = full_client.new_block_at(hashof1, Default::default(), false).unwrap(); let block = builder.build().unwrap().block; let hashof2 = block.header.hash(); @@ -805,9 +804,8 @@ async fn beefy_importing_justifications() { } // Import block 3 with valid justification. - let parent_id = BlockId::Number(2); let block_num = 3; - let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap(); + let builder = full_client.new_block_at(hashof2, Default::default(), false).unwrap(); let block = builder.build().unwrap().block; let hashof3 = block.header.hash(); let proof = crate::justification::tests::new_finality_proof(block_num, &good_set, keys); @@ -840,9 +838,8 @@ async fn beefy_importing_justifications() { } // Import block 4 with invalid justification (incorrect validator set). - let parent_id = BlockId::Number(3); let block_num = 4; - let builder = full_client.new_block_at(&parent_id, Default::default(), false).unwrap(); + let builder = full_client.new_block_at(hashof3, Default::default(), false).unwrap(); let block = builder.build().unwrap().block; let hashof4 = block.header.hash(); let keys = &[BeefyKeyring::Alice]; diff --git a/client/block-builder/src/lib.rs b/client/block-builder/src/lib.rs index d302a834fd723..437e43a71d634 100644 --- a/client/block-builder/src/lib.rs +++ b/client/block-builder/src/lib.rs @@ -34,7 +34,6 @@ use sp_api::{ use sp_blockchain::{ApplyExtrinsicFailed, Error}; use sp_core::ExecutionContext; use sp_runtime::{ - generic::BlockId, legacy, traits::{Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One}, Digest, @@ -120,7 +119,7 @@ where /// output of this block builder without having access to the full storage. fn new_block_at>( &self, - parent: &BlockId, + parent: Block::Hash, inherent_digests: Digest, record_proof: R, ) -> sp_blockchain::Result>; diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index ad2e95df033f4..d1ad91a1ce760 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -45,7 +45,7 @@ use sp_keystore::{ SyncCryptoStore, }; use sp_runtime::{ - generic::{BlockId, Digest, DigestItem}, + generic::{Digest, DigestItem}, traits::Block as BlockT, }; use sp_timestamp::Timestamp; @@ -123,11 +123,8 @@ impl DummyProposer { Error, >, > { - let block_builder = self - .factory - .client - .new_block_at(&BlockId::Hash(self.parent_hash), pre_digests, false) - .unwrap(); + let block_builder = + self.factory.client.new_block_at(self.parent_hash, pre_digests, false).unwrap(); let mut block = match block_builder.build().map_err(|e| e.into()) { Ok(b) => b.block, diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index d132abd940ba3..fee3b13ba0be9 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -875,7 +875,7 @@ async fn allows_reimporting_change_blocks() { let full_client = client.as_client(); let builder = full_client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(full_client.chain_info().genesis_hash, Default::default(), false) .unwrap(); let mut block = builder.build().unwrap().block; add_scheduled_change( @@ -922,7 +922,7 @@ async fn test_bad_justification() { let full_client = client.as_client(); let builder = full_client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(full_client.chain_info().genesis_hash, Default::default(), false) .unwrap(); let mut block = builder.build().unwrap().block; @@ -1854,7 +1854,7 @@ async fn imports_justification_for_regular_blocks_on_import() { let full_client = client.as_client(); let builder = full_client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(full_client.chain_info().genesis_hash, Default::default(), false) .unwrap(); let block = builder.build().unwrap().block; diff --git a/client/merkle-mountain-range/src/test_utils.rs b/client/merkle-mountain-range/src/test_utils.rs index e5a6673483dbb..9decaa3c243ff 100644 --- a/client/merkle-mountain-range/src/test_utils.rs +++ b/client/merkle-mountain-range/src/test_utils.rs @@ -124,7 +124,8 @@ impl MockClient { ) -> MmrBlock { let mut client = self.client.lock(); - let mut block_builder = client.new_block_at(at, Default::default(), false).unwrap(); + let hash = client.expect_block_hash_from_id(&at).unwrap(); + let mut block_builder = client.new_block_at(hash, Default::default(), false).unwrap(); // Make sure the block has a different hash than its siblings block_builder .push_storage_change(b"name".to_vec(), Some(name.to_vec())) diff --git a/client/network/src/service/tests/chain_sync.rs b/client/network/src/service/tests/chain_sync.rs index 1ae432fd4c235..98884024ac7e1 100644 --- a/client/network/src/service/tests/chain_sync.rs +++ b/client/network/src/service/tests/chain_sync.rs @@ -34,10 +34,7 @@ use sc_network_common::{ }; use sc_network_sync::{mock::MockChainSync, service::mock::MockChainSyncInterface, ChainSync}; use sp_core::H256; -use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, Header as _}, -}; +use sp_runtime::traits::{Block as BlockT, Header as _}; use std::{ sync::{Arc, RwLock}, task::Poll, @@ -188,7 +185,7 @@ async fn on_block_finalized() { let at = client.header(client.info().best_hash).unwrap().unwrap().hash(); let block = client - .new_block_at(&BlockId::Hash(at), Default::default(), false) + .new_block_at(at, Default::default(), false) .unwrap() .build() .unwrap() diff --git a/client/network/sync/src/lib.rs b/client/network/sync/src/lib.rs index f56ef13fc9065..1f4f6a04ebd77 100644 --- a/client/network/sync/src/lib.rs +++ b/client/network/sync/src/lib.rs @@ -3212,7 +3212,6 @@ mod test { }; use sp_blockchain::HeaderBackend; use sp_consensus::block_validation::DefaultBlockAnnounceValidator; - use sp_runtime::generic::BlockId; use substrate_test_runtime_client::{ runtime::{Block, Hash, Header}, BlockBuilderExt, ClientBlockImportExt, ClientExt, DefaultTestClientBuilderExt, TestClient, @@ -3449,8 +3448,7 @@ mod test { fn build_block(client: &mut Arc, at: Option, fork: bool) -> Block { let at = at.unwrap_or_else(|| client.info().best_hash); - let mut block_builder = - client.new_block_at(&BlockId::Hash(at), Default::default(), false).unwrap(); + let mut block_builder = client.new_block_at(at, Default::default(), false).unwrap(); if fork { block_builder.push_storage_change(vec![1, 2, 3], Some(vec![4, 5, 6])).unwrap(); @@ -3503,8 +3501,7 @@ mod test { let mut client2 = client.clone(); let mut build_block_at = |at, import| { - let mut block_builder = - client2.new_block_at(&BlockId::Hash(at), Default::default(), false).unwrap(); + let mut block_builder = client2.new_block_at(at, Default::default(), false).unwrap(); // Make sure we generate a different block as fork block_builder.push_storage_change(vec![1, 2, 3], Some(vec![4, 5, 6])).unwrap(); diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index c47e3c86f5c0e..3cd508103c41a 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -377,8 +377,7 @@ where let full_client = self.client.as_client(); let mut at = full_client.block_hash_from_id(&at).unwrap().unwrap(); for _ in 0..count { - let builder = - full_client.new_block_at(&BlockId::Hash(at), Default::default(), false).unwrap(); + let builder = full_client.new_block_at(at, Default::default(), false).unwrap(); let block = edit_block(builder); let hash = block.header.hash(); trace!( diff --git a/client/rpc-spec-v2/src/chain_head/tests.rs b/client/rpc-spec-v2/src/chain_head/tests.rs index 4084075f0b321..79be391368f71 100644 --- a/client/rpc-spec-v2/src/chain_head/tests.rs +++ b/client/rpc-spec-v2/src/chain_head/tests.rs @@ -8,7 +8,6 @@ use jsonrpsee::{ }; use sc_block_builder::BlockBuilderProvider; use sc_client_api::ChildInfo; -use sp_api::BlockId; use sp_blockchain::HeaderBackend; use sp_consensus::BlockOrigin; use sp_core::{ @@ -639,9 +638,8 @@ async fn follow_generates_initial_blocks() { let block_2_hash = block_2.header.hash(); client.import(BlockOrigin::Own, block_2.clone()).await.unwrap(); - let mut block_builder = client - .new_block_at(&BlockId::Hash(block_1.header.hash()), Default::default(), false) - .unwrap(); + let mut block_builder = + client.new_block_at(block_1.header.hash(), Default::default(), false).unwrap(); // This push is required as otherwise block 3 has the same hash as block 2 and won't get // imported block_builder @@ -921,9 +919,7 @@ async fn follow_prune_best_block() { client.import(BlockOrigin::Own, block_4.clone()).await.unwrap(); // Import block 2 as best on the fork. - let mut block_builder = client - .new_block_at(&BlockId::Hash(block_1.header.hash()), Default::default(), false) - .unwrap(); + let mut block_builder = client.new_block_at(block_1_hash, Default::default(), false).unwrap(); // This push is required as otherwise block 3 has the same hash as block 2 and won't get // imported block_builder diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 7bd37b5163664..615817cc32517 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -1408,14 +1408,14 @@ where { fn new_block_at>( &self, - parent: &BlockId, + parent: Block::Hash, inherent_digests: Digest, record_proof: R, ) -> sp_blockchain::Result> { sc_block_builder::BlockBuilder::new( self, - self.expect_block_hash_from_id(parent)?, - self.expect_block_number_from_id(parent)?, + parent, + self.expect_block_number_from_id(&BlockId::Hash(parent))?, record_proof.into(), inherent_digests, &self.backend, diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index 53af18c6b8604..0fe4760fcb93e 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -447,7 +447,7 @@ fn uncles_with_multiple_forks() { // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -456,7 +456,7 @@ fn uncles_with_multiple_forks() { // A2 -> A3 let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -465,7 +465,7 @@ fn uncles_with_multiple_forks() { // A3 -> A4 let a4 = client - .new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false) + .new_block_at(a3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -474,7 +474,7 @@ fn uncles_with_multiple_forks() { // A4 -> A5 let a5 = client - .new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false) + .new_block_at(a4.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -482,9 +482,7 @@ fn uncles_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap(); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder .push_transfer(Transfer { @@ -499,7 +497,7 @@ fn uncles_with_multiple_forks() { // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -508,7 +506,7 @@ fn uncles_with_multiple_forks() { // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -516,9 +514,7 @@ fn uncles_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, b4.clone())).unwrap(); // // B2 -> C3 - let mut builder = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(b2.hash(), Default::default(), false).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder .push_transfer(Transfer { @@ -532,9 +528,7 @@ fn uncles_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, c3.clone())).unwrap(); // A1 -> D2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder .push_transfer(Transfer { @@ -608,7 +602,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -617,7 +611,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // A2 -> A3 let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -626,7 +620,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // A3 -> A4 let a4 = client - .new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false) + .new_block_at(a3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -635,7 +629,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // A4 -> A5 let a5 = client - .new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false) + .new_block_at(a4.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -643,9 +637,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap(); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder .push_transfer(Transfer { @@ -660,7 +652,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -669,7 +661,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -677,9 +669,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, b4.clone())).unwrap(); // B2 -> C3 - let mut builder = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(b2.hash(), Default::default(), false).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder .push_transfer(Transfer { @@ -693,9 +683,7 @@ fn finality_target_on_longest_chain_with_multiple_forks() { block_on(client.import(BlockOrigin::Own, c3.clone())).unwrap(); // A1 -> D2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder .push_transfer(Transfer { @@ -871,9 +859,7 @@ fn finality_target_with_best_not_on_longest_chain() { block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap(); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder .push_transfer(Transfer { @@ -895,7 +881,7 @@ fn finality_target_with_best_not_on_longest_chain() { // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -904,7 +890,7 @@ fn finality_target_with_best_not_on_longest_chain() { // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -940,7 +926,7 @@ fn import_with_justification() { // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -951,7 +937,7 @@ fn import_with_justification() { // A2 -> A3 let justification = Justifications::from((TEST_ENGINE_ID, vec![1, 2, 3])); let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -982,7 +968,7 @@ fn importing_diverged_finalized_block_should_trigger_reorg() { let mut finality_notifications = client.finality_notification_stream(); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() @@ -990,14 +976,16 @@ fn importing_diverged_finalized_block_should_trigger_reorg() { block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap(); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 b1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1035,7 +1023,7 @@ fn finalizing_diverged_block_should_trigger_reorg() { let mut finality_notifications = client.finality_notification_stream(); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() @@ -1043,14 +1031,16 @@ fn finalizing_diverged_block_should_trigger_reorg() { block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap(); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 b1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1063,7 +1053,7 @@ fn finalizing_diverged_block_should_trigger_reorg() { block_on(client.import(BlockOrigin::Own, b1.clone())).unwrap(); let b2 = client - .new_block_at(&BlockId::Hash(b1.hash()), Default::default(), false) + .new_block_at(b1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1089,7 +1079,7 @@ fn finalizing_diverged_block_should_trigger_reorg() { // after we build B3 on top of B2 and import it, it should be the new best block let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1121,7 +1111,7 @@ fn finality_notifications_content() { let mut finality_notifications = client.finality_notification_stream(); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() @@ -1129,7 +1119,7 @@ fn finality_notifications_content() { block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap(); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1137,14 +1127,16 @@ fn finality_notifications_content() { block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap(); let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::Own, a3.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 b1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1157,14 +1149,16 @@ fn finality_notifications_content() { block_on(client.import(BlockOrigin::Own, b1.clone())).unwrap(); let b2 = client - .new_block_at(&BlockId::Hash(b1.hash()), Default::default(), false) + .new_block_at(b1.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::Own, b2.clone())).unwrap(); - let mut c1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut c1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 c1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1176,9 +1170,7 @@ fn finality_notifications_content() { let c1 = c1.build().unwrap().block; block_on(client.import(BlockOrigin::Own, c1.clone())).unwrap(); - let mut d3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) - .unwrap(); + let mut d3 = client.new_block_at(a2.hash(), Default::default(), false).unwrap(); // needed to make sure D3 gets a different hash from A3 d3.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1191,7 +1183,7 @@ fn finality_notifications_content() { block_on(client.import(BlockOrigin::Own, d3.clone())).unwrap(); let d4 = client - .new_block_at(&BlockId::Hash(d3.hash()), Default::default(), false) + .new_block_at(d3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1251,7 +1243,9 @@ fn state_reverted_on_reorg() { // G -> A1 -> A2 // \ // -> B1 - let mut a1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut a1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); a1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Bob.into(), @@ -1262,7 +1256,9 @@ fn state_reverted_on_reorg() { let a1 = a1.build().unwrap().block; block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); b1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Ferdie.into(), @@ -1275,9 +1271,7 @@ fn state_reverted_on_reorg() { block_on(client.import_as_best(BlockOrigin::Own, b1.clone())).unwrap(); assert_eq!(950, current_balance(&client)); - let mut a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut a2 = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); a2.push_transfer(Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Charlie.into(), @@ -1322,7 +1316,7 @@ fn doesnt_import_blocks_that_revert_finality() { // -> B1 -> B2 -> B3 let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() @@ -1330,14 +1324,16 @@ fn doesnt_import_blocks_that_revert_finality() { block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap(); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 b1.push_transfer(Transfer { @@ -1351,7 +1347,7 @@ fn doesnt_import_blocks_that_revert_finality() { block_on(client.import(BlockOrigin::Own, b1.clone())).unwrap(); let b2 = client - .new_block_at(&BlockId::Hash(b1.hash()), Default::default(), false) + .new_block_at(b1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1361,7 +1357,7 @@ fn doesnt_import_blocks_that_revert_finality() { // prepare B3 before we finalize A2, because otherwise we won't be able to // read changes trie configuration after A2 is finalized let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1379,7 +1375,9 @@ fn doesnt_import_blocks_that_revert_finality() { // adding a C1 block which is lower than the last finalized should also // fail (with a cheaper check that doesn't require checking ancestry). - let mut c1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut c1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure C1 gets a different hash from A1 and B1 c1.push_transfer(Transfer { @@ -1398,7 +1396,7 @@ fn doesnt_import_blocks_that_revert_finality() { assert_eq!(import_err.to_string(), expected_err.to_string()); let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1428,16 +1426,34 @@ fn respects_block_rules() { .build() }; + // test modus operandi: + // + // B[2] + // / + // G[0]--B[1] + // \ \ + // \ B'[2] + // \ + // B'[1] + // + // B[1] - block ok + // B'[1] - block not ok, added to block_rules::bad + // + // B[2] - block ok, correct fork for block height==2, added to block_rules::forks + // B'[2] - block not ok, (incorrect fork) + + // build B[1] let block_ok = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() .block; + let block_ok_1_hash = block_ok.hash(); let params = BlockCheckParams { hash: block_ok.hash(), - number: 0, + number: 1, parent_hash: *block_ok.header().parent_hash(), allow_missing_state: false, allow_missing_parent: false, @@ -1445,15 +1461,16 @@ fn respects_block_rules() { }; assert_eq!(block_on(client.check_block(params)).unwrap(), ImportResult::imported(false)); - // this is 0x0d6d6612a10485370d9e085aeea7ec427fb3f34d961c6a816cdbe5cde2278864 - let mut block_not_ok = - client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + // build B'[1] + let mut block_not_ok = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); block_not_ok.push_storage_change(vec![0], Some(vec![1])).unwrap(); let block_not_ok = block_not_ok.build().unwrap().block; let params = BlockCheckParams { hash: block_not_ok.hash(), - number: 0, + number: 1, parent_hash: *block_not_ok.header().parent_hash(), allow_missing_state: false, allow_missing_parent: false, @@ -1468,34 +1485,35 @@ fn respects_block_rules() { // Now going to the fork block_on(client.import_as_final(BlockOrigin::Own, block_ok)).unwrap(); - // And check good fork - let mut block_ok = - client.new_block_at(&BlockId::Number(1), Default::default(), false).unwrap(); + // And check good fork (build B[2]) + let mut block_ok = client.new_block_at(block_ok_1_hash, Default::default(), false).unwrap(); block_ok.push_storage_change(vec![0], Some(vec![2])).unwrap(); let block_ok = block_ok.build().unwrap().block; + assert_eq!(*block_ok.header().number(), 2); let params = BlockCheckParams { hash: block_ok.hash(), - number: 1, + number: 2, parent_hash: *block_ok.header().parent_hash(), allow_missing_state: false, allow_missing_parent: false, import_existing: false, }; if record_only { - fork_rules.push((1, block_ok.hash())); + fork_rules.push((2, block_ok.hash())); } assert_eq!(block_on(client.check_block(params)).unwrap(), ImportResult::imported(false)); - // And now try bad fork + // And now try bad fork (build B'[2]) let mut block_not_ok = - client.new_block_at(&BlockId::Number(1), Default::default(), false).unwrap(); + client.new_block_at(block_ok_1_hash, Default::default(), false).unwrap(); block_not_ok.push_storage_change(vec![0], Some(vec![3])).unwrap(); let block_not_ok = block_not_ok.build().unwrap().block; + assert_eq!(*block_not_ok.header().number(), 2); let params = BlockCheckParams { hash: block_not_ok.hash(), - number: 1, + number: 2, parent_hash: *block_not_ok.header().parent_hash(), allow_missing_state: false, allow_missing_parent: false, @@ -1540,13 +1558,15 @@ fn returns_status_for_pruned_blocks() { let mut client = TestClientBuilder::with_backend(backend).build(); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() .block; - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // b1 is created, but not imported b1.push_transfer(Transfer { @@ -1582,7 +1602,7 @@ fn returns_status_for_pruned_blocks() { assert_eq!(client.block_status(check_block_a1.hash).unwrap(), BlockStatus::InChainWithState); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1610,7 +1630,7 @@ fn returns_status_for_pruned_blocks() { assert_eq!(client.block_status(check_block_a2.hash).unwrap(), BlockStatus::InChainWithState); let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1907,7 +1927,7 @@ fn reorg_triggers_a_notification_even_for_sources_that_should_not_trigger_notifi futures::executor::block_on_stream(client.import_notification_stream()); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() @@ -1915,14 +1935,16 @@ fn reorg_triggers_a_notification_even_for_sources_that_should_not_trigger_notifi block_on(client.import(BlockOrigin::NetworkInitialSync, a1.clone())).unwrap(); let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() .block; block_on(client.import(BlockOrigin::NetworkInitialSync, a2.clone())).unwrap(); - let mut b1 = client.new_block_at(&BlockId::Number(0), Default::default(), false).unwrap(); + let mut b1 = client + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) + .unwrap(); // needed to make sure B1 gets a different hash from A1 b1.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1935,7 +1957,7 @@ fn reorg_triggers_a_notification_even_for_sources_that_should_not_trigger_notifi block_on(client.import(BlockOrigin::NetworkInitialSync, b1.clone())).unwrap(); let b2 = client - .new_block_at(&BlockId::Hash(b1.hash()), Default::default(), false) + .new_block_at(b1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -1971,7 +1993,7 @@ fn use_dalek_ext_works() { ); let a1 = client - .new_block_at(&BlockId::Number(0), Default::default(), false) + .new_block_at(client.chain_info().genesis_hash, Default::default(), false) .unwrap() .build() .unwrap() diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 4f88d887c8c55..feb3e1a6ef48c 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -16,10 +16,7 @@ // limitations under the License. use sp_api::{Core, ProvideRuntimeApi}; -use sp_runtime::{ - generic::BlockId, - traits::{HashFor, Header as HeaderT}, -}; +use sp_runtime::traits::{HashFor, Header as HeaderT}; use sp_state_machine::{ create_proof_check_backend, execution_proof_check_on_trie_backend, ExecutionStrategy, }; @@ -166,10 +163,9 @@ fn record_proof_works() { } .into_signed_tx(); - let block_id = BlockId::Hash(client.chain_info().best_hash); // Build the block and record proof let mut builder = client - .new_block_at(&block_id, Default::default(), true) + .new_block_at(client.chain_info().best_hash, Default::default(), true) .expect("Creates block builder"); builder.push(transaction.clone()).unwrap(); let (block, _, proof) = builder.build().expect("Bake block").into_inner(); diff --git a/test-utils/runtime/client/src/trait_tests.rs b/test-utils/runtime/client/src/trait_tests.rs index 19772c8c94067..7ec56635e2d03 100644 --- a/test-utils/runtime/client/src/trait_tests.rs +++ b/test-utils/runtime/client/src/trait_tests.rs @@ -32,7 +32,7 @@ use sc_client_api::{ blockchain::{Backend as BlockChainBackendT, HeaderBackend}, }; use sp_consensus::BlockOrigin; -use sp_runtime::{generic::BlockId, traits::Block as BlockT}; +use sp_runtime::traits::Block as BlockT; use substrate_test_runtime::{self, Transfer}; /// helper to test the `leaves` implementation for various backends @@ -60,7 +60,7 @@ where // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -71,7 +71,7 @@ where // A2 -> A3 let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -82,7 +82,7 @@ where // A3 -> A4 let a4 = client - .new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false) + .new_block_at(a3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -92,7 +92,7 @@ where // A4 -> A5 let a5 = client - .new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false) + .new_block_at(a4.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -102,9 +102,7 @@ where assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash()]); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder @@ -121,7 +119,7 @@ where // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -132,7 +130,7 @@ where // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -141,9 +139,7 @@ where assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash()]); // // B2 -> C3 - let mut builder = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(b2.hash(), Default::default(), false).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder .push_transfer(Transfer { @@ -158,9 +154,7 @@ where assert_eq!(blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash(), c3.hash()]); // A1 -> D2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder .push_transfer(Transfer { @@ -195,7 +189,7 @@ where // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -204,7 +198,7 @@ where // A2 -> A3 let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -213,7 +207,7 @@ where // A3 -> A4 let a4 = client - .new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false) + .new_block_at(a3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -222,7 +216,7 @@ where // A4 -> A5 let a5 = client - .new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false) + .new_block_at(a4.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -230,9 +224,7 @@ where block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap(); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder .push_transfer(Transfer { @@ -247,7 +239,7 @@ where // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -256,7 +248,7 @@ where // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -264,9 +256,7 @@ where block_on(client.import(BlockOrigin::Own, b4)).unwrap(); // // B2 -> C3 - let mut builder = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(b2.hash(), Default::default(), false).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder .push_transfer(Transfer { @@ -280,9 +270,7 @@ where block_on(client.import(BlockOrigin::Own, c3.clone())).unwrap(); // A1 -> D2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder .push_transfer(Transfer { @@ -328,7 +316,7 @@ where // A1 -> A2 let a2 = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) + .new_block_at(a1.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -337,7 +325,7 @@ where // A2 -> A3 let a3 = client - .new_block_at(&BlockId::Hash(a2.hash()), Default::default(), false) + .new_block_at(a2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -346,7 +334,7 @@ where // A3 -> A4 let a4 = client - .new_block_at(&BlockId::Hash(a3.hash()), Default::default(), false) + .new_block_at(a3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -355,7 +343,7 @@ where // A4 -> A5 let a5 = client - .new_block_at(&BlockId::Hash(a4.hash()), Default::default(), false) + .new_block_at(a4.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -363,9 +351,7 @@ where block_on(client.import(BlockOrigin::Own, a5.clone())).unwrap(); // A1 -> B2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder .push_transfer(Transfer { @@ -380,7 +366,7 @@ where // B2 -> B3 let b3 = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) + .new_block_at(b2.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -389,7 +375,7 @@ where // B3 -> B4 let b4 = client - .new_block_at(&BlockId::Hash(b3.hash()), Default::default(), false) + .new_block_at(b3.hash(), Default::default(), false) .unwrap() .build() .unwrap() @@ -397,9 +383,7 @@ where block_on(client.import(BlockOrigin::Own, b4)).unwrap(); // // B2 -> C3 - let mut builder = client - .new_block_at(&BlockId::Hash(b2.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(b2.hash(), Default::default(), false).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder .push_transfer(Transfer { @@ -413,9 +397,7 @@ where block_on(client.import(BlockOrigin::Own, c3)).unwrap(); // A1 -> D2 - let mut builder = client - .new_block_at(&BlockId::Hash(a1.hash()), Default::default(), false) - .unwrap(); + let mut builder = client.new_block_at(a1.hash(), Default::default(), false).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder .push_transfer(Transfer {