diff --git a/bin/node/bench/src/construct.rs b/bin/node/bench/src/construct.rs index f994b29b5e843..529a3ba7a001e 100644 --- a/bin/node/bench/src/construct.rs +++ b/bin/node/bench/src/construct.rs @@ -120,7 +120,7 @@ impl core::Benchmark for ConstructionBenchmark { let _ = context .client - .runtime_version_at(&BlockId::Number(0)) + .runtime_version_at(context.client.chain_info().genesis_hash) .expect("Failed to get runtime version") .spec_version; diff --git a/bin/node/bench/src/import.rs b/bin/node/bench/src/import.rs index 7d59e94a44a09..db93833c83200 100644 --- a/bin/node/bench/src/import.rs +++ b/bin/node/bench/src/import.rs @@ -35,7 +35,6 @@ use std::borrow::Cow; use node_primitives::Block; use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile}; use sc_client_api::backend::Backend; -use sp_runtime::generic::BlockId; use sp_state_machine::InspectState; use crate::{ @@ -115,7 +114,7 @@ impl core::Benchmark for ImportBenchmark { let _ = context .client - .runtime_version_at(&BlockId::Number(0)) + .runtime_version_at(context.client.chain_info().genesis_hash) .expect("Failed to get runtime version") .spec_version; diff --git a/bin/node/bench/src/txpool.rs b/bin/node/bench/src/txpool.rs index 322dc352e8972..5b4d5513e2b5a 100644 --- a/bin/node/bench/src/txpool.rs +++ b/bin/node/bench/src/txpool.rs @@ -61,7 +61,7 @@ impl core::Benchmark for PoolBenchmark { let _ = context .client - .runtime_version_at(&BlockId::Number(0)) + .runtime_version_at(context.client.chain_info().genesis_hash) .expect("Failed to get runtime version") .spec_version; diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 7ad1a9486b544..c98fe17cfc693 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -587,7 +587,7 @@ mod tests { use sp_keyring::AccountKeyring; use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; use sp_runtime::{ - generic::{BlockId, Digest, Era, SignedPayload}, + generic::{Digest, Era, SignedPayload}, key_types::BABE, traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, Verify}, RuntimeAppPublic, @@ -754,9 +754,9 @@ mod tests { let to: Address = AccountPublic::from(bob.public()).into_account().into(); let from: Address = AccountPublic::from(charlie.public()).into_account().into(); let genesis_hash = service.client().block_hash(0).unwrap().unwrap(); - let best_block_id = BlockId::number(service.client().chain_info().best_number); + let best_hash = service.client().chain_info().best_hash; let (spec_version, transaction_version) = { - let version = service.client().runtime_version_at(&best_block_id).unwrap(); + let version = service.client().runtime_version_at(best_hash).unwrap(); (version.spec_version, version.transaction_version) }; let signer = charlie.clone(); diff --git a/bin/node/testing/src/bench.rs b/bin/node/testing/src/bench.rs index 2151a61a6ca7a..cc0a93ca27fc2 100644 --- a/bin/node/testing/src/bench.rs +++ b/bin/node/testing/src/bench.rs @@ -42,7 +42,7 @@ use node_primitives::Block; use sc_block_builder::BlockBuilderProvider; use sc_client_api::{ execution_extensions::{ExecutionExtensions, ExecutionStrategies}, - BlockBackend, ExecutionStrategy, + ExecutionStrategy, }; use sc_client_db::PruningMode; use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux}; @@ -54,7 +54,7 @@ use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, ExecutionContext use sp_inherents::InherentData; use sp_runtime::{ generic::BlockId, - traits::{Block as BlockT, IdentifyAccount, Verify, Zero}, + traits::{Block as BlockT, IdentifyAccount, Verify}, OpaqueExtrinsic, }; @@ -273,15 +273,12 @@ pub struct BlockContentIterator<'a> { impl<'a> BlockContentIterator<'a> { fn new(content: BlockContent, keyring: &'a BenchKeyring, client: &Client) -> Self { + let genesis_hash = client.chain_info().genesis_hash; + let runtime_version = client - .runtime_version_at(&BlockId::number(0)) + .runtime_version_at(genesis_hash) .expect("There should be runtime version at 0"); - let genesis_hash = client - .block_hash(Zero::zero()) - .expect("Database error?") - .expect("Genesis block always exists; qed"); - BlockContentIterator { iteration: 0, content, keyring, runtime_version, genesis_hash } } } diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 7906d62240e0b..49b969e3e71b0 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -485,7 +485,7 @@ mod tests { ) .expect("Creates a client"); - let version = client.runtime_version_at(&BlockId::Number(0)).unwrap(); + let version = client.runtime_version_at(client.chain_info().genesis_hash).unwrap(); assert_eq!(SUBSTITUTE_SPEC_NAME, &*version.spec_name); } diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 4b28b39931756..d452104ce7e51 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -491,8 +491,7 @@ where } /// Get the RuntimeVersion at a given block. - pub fn runtime_version_at(&self, id: &BlockId) -> sp_blockchain::Result { - let hash = self.backend.blockchain().expect_block_hash_from_id(id)?; + pub fn runtime_version_at(&self, hash: Block::Hash) -> sp_blockchain::Result { CallExecutor::runtime_version(&self.executor, hash) }