Skip to content

Commit ea71d2e

Browse files
michalkucharczykmelekes
authored andcommitted
BlockId removal: Client::runtime_version_at (paritytech#13393)
* BlockId removal: Client::runtime_version_at It changes the arguments of `Client::runtime_version_at` from: `BlockId<Block>` to: `Block::Hash` * Apply suggestions from code review Co-authored-by: Anton <anton.kalyaev@gmail.com> --------- Co-authored-by: Anton <anton.kalyaev@gmail.com> Co-authored-by: parity-processbot <>
1 parent 8dc3754 commit ea71d2e

File tree

7 files changed

+13
-18
lines changed

7 files changed

+13
-18
lines changed

bin/node/bench/src/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl core::Benchmark for ConstructionBenchmark {
120120

121121
let _ = context
122122
.client
123-
.runtime_version_at(&BlockId::Number(0))
123+
.runtime_version_at(context.client.chain_info().genesis_hash)
124124
.expect("Failed to get runtime version")
125125
.spec_version;
126126

bin/node/bench/src/import.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::borrow::Cow;
3535
use node_primitives::Block;
3636
use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile};
3737
use sc_client_api::backend::Backend;
38-
use sp_runtime::generic::BlockId;
3938
use sp_state_machine::InspectState;
4039

4140
use crate::{
@@ -115,7 +114,7 @@ impl core::Benchmark for ImportBenchmark {
115114

116115
let _ = context
117116
.client
118-
.runtime_version_at(&BlockId::Number(0))
117+
.runtime_version_at(context.client.chain_info().genesis_hash)
119118
.expect("Failed to get runtime version")
120119
.spec_version;
121120

bin/node/bench/src/txpool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl core::Benchmark for PoolBenchmark {
6161

6262
let _ = context
6363
.client
64-
.runtime_version_at(&BlockId::Number(0))
64+
.runtime_version_at(context.client.chain_info().genesis_hash)
6565
.expect("Failed to get runtime version")
6666
.spec_version;
6767

bin/node/cli/src/service.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ mod tests {
587587
use sp_keyring::AccountKeyring;
588588
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
589589
use sp_runtime::{
590-
generic::{BlockId, Digest, Era, SignedPayload},
590+
generic::{Digest, Era, SignedPayload},
591591
key_types::BABE,
592592
traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, Verify},
593593
RuntimeAppPublic,
@@ -754,9 +754,9 @@ mod tests {
754754
let to: Address = AccountPublic::from(bob.public()).into_account().into();
755755
let from: Address = AccountPublic::from(charlie.public()).into_account().into();
756756
let genesis_hash = service.client().block_hash(0).unwrap().unwrap();
757-
let best_block_id = BlockId::number(service.client().chain_info().best_number);
757+
let best_hash = service.client().chain_info().best_hash;
758758
let (spec_version, transaction_version) = {
759-
let version = service.client().runtime_version_at(&best_block_id).unwrap();
759+
let version = service.client().runtime_version_at(best_hash).unwrap();
760760
(version.spec_version, version.transaction_version)
761761
};
762762
let signer = charlie.clone();

bin/node/testing/src/bench.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use node_primitives::Block;
4242
use sc_block_builder::BlockBuilderProvider;
4343
use sc_client_api::{
4444
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
45-
BlockBackend, ExecutionStrategy,
45+
ExecutionStrategy,
4646
};
4747
use sc_client_db::PruningMode;
4848
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
@@ -54,7 +54,7 @@ use sp_core::{blake2_256, ed25519, sr25519, traits::SpawnNamed, ExecutionContext
5454
use sp_inherents::InherentData;
5555
use sp_runtime::{
5656
generic::BlockId,
57-
traits::{Block as BlockT, IdentifyAccount, Verify, Zero},
57+
traits::{Block as BlockT, IdentifyAccount, Verify},
5858
OpaqueExtrinsic,
5959
};
6060

@@ -273,15 +273,12 @@ pub struct BlockContentIterator<'a> {
273273

274274
impl<'a> BlockContentIterator<'a> {
275275
fn new(content: BlockContent, keyring: &'a BenchKeyring, client: &Client) -> Self {
276+
let genesis_hash = client.chain_info().genesis_hash;
277+
276278
let runtime_version = client
277-
.runtime_version_at(&BlockId::number(0))
279+
.runtime_version_at(genesis_hash)
278280
.expect("There should be runtime version at 0");
279281

280-
let genesis_hash = client
281-
.block_hash(Zero::zero())
282-
.expect("Database error?")
283-
.expect("Genesis block always exists; qed");
284-
285282
BlockContentIterator { iteration: 0, content, keyring, runtime_version, genesis_hash }
286283
}
287284
}

client/service/src/client/call_executor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ mod tests {
485485
)
486486
.expect("Creates a client");
487487

488-
let version = client.runtime_version_at(&BlockId::Number(0)).unwrap();
488+
let version = client.runtime_version_at(client.chain_info().genesis_hash).unwrap();
489489

490490
assert_eq!(SUBSTITUTE_SPEC_NAME, &*version.spec_name);
491491
}

client/service/src/client/client.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ where
491491
}
492492

493493
/// Get the RuntimeVersion at a given block.
494-
pub fn runtime_version_at(&self, id: &BlockId<Block>) -> sp_blockchain::Result<RuntimeVersion> {
495-
let hash = self.backend.blockchain().expect_block_hash_from_id(id)?;
494+
pub fn runtime_version_at(&self, hash: Block::Hash) -> sp_blockchain::Result<RuntimeVersion> {
496495
CallExecutor::runtime_version(&self.executor, hash)
497496
}
498497

0 commit comments

Comments
 (0)