Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Revert "BlockId removal: Client::runtime_version_at (#13393)"
Browse files Browse the repository at this point in the history
This reverts commit b48a362.
  • Loading branch information
Ross Bulat committed Feb 19, 2023
1 parent d09d75d commit d3a09e2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/node/bench/src/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl core::Benchmark for ConstructionBenchmark {

let _ = context
.client
.runtime_version_at(context.client.chain_info().genesis_hash)
.runtime_version_at(&BlockId::Number(0))
.expect("Failed to get runtime version")
.spec_version;

Expand Down
3 changes: 2 additions & 1 deletion bin/node/bench/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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::{
Expand Down Expand Up @@ -114,7 +115,7 @@ impl core::Benchmark for ImportBenchmark {

let _ = context
.client
.runtime_version_at(context.client.chain_info().genesis_hash)
.runtime_version_at(&BlockId::Number(0))
.expect("Failed to get runtime version")
.spec_version;

Expand Down
2 changes: 1 addition & 1 deletion bin/node/bench/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl core::Benchmark for PoolBenchmark {

let _ = context
.client
.runtime_version_at(context.client.chain_info().genesis_hash)
.runtime_version_at(&BlockId::Number(0))
.expect("Failed to get runtime version")
.spec_version;

Expand Down
6 changes: 3 additions & 3 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ mod tests {
use sp_keyring::AccountKeyring;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::{
generic::{Digest, Era, SignedPayload},
generic::{BlockId, Digest, Era, SignedPayload},
key_types::BABE,
traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, Verify},
RuntimeAppPublic,
Expand Down Expand Up @@ -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_hash = service.client().chain_info().best_hash;
let best_block_id = BlockId::number(service.client().chain_info().best_number);
let (spec_version, transaction_version) = {
let version = service.client().runtime_version_at(best_hash).unwrap();
let version = service.client().runtime_version_at(&best_block_id).unwrap();
(version.spec_version, version.transaction_version)
};
let signer = charlie.clone();
Expand Down
13 changes: 8 additions & 5 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use node_primitives::Block;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{
execution_extensions::{ExecutionExtensions, ExecutionStrategies},
ExecutionStrategy,
BlockBackend, ExecutionStrategy,
};
use sc_client_db::PruningMode;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
Expand All @@ -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},
traits::{Block as BlockT, IdentifyAccount, Verify, Zero},
OpaqueExtrinsic,
};

Expand Down Expand Up @@ -273,12 +273,15 @@ 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(genesis_hash)
.runtime_version_at(&BlockId::number(0))
.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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/service/src/client/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ mod tests {
)
.expect("Creates a client");

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

assert_eq!(SUBSTITUTE_SPEC_NAME, &*version.spec_name);
}
Expand Down
3 changes: 2 additions & 1 deletion client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ where
}

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

Expand Down

0 comments on commit d3a09e2

Please sign in to comment.