mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 07:37:57 +00:00
BlockId removal: refactor: StorageProvider (#12510)
* BlockId removal: refactor: StorageProvider It changes the arguments of `Backend::StorageProvider` trait from: block: `BlockId<Block>` to: hash: `&Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * Update client/api/src/backend.rs Co-authored-by: Dmitrii Markin <dmitry@markin.tech> * GrandpaBlockImport::current_set_id reworked * ExportStateCmd reworked * trigger CI job * trigger CI job Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Dmitrii Markin <dmitry@markin.tech>
This commit is contained in:
committed by
GitHub
parent
2f341fcf15
commit
b16135f602
@@ -22,7 +22,9 @@ use frame_support::weights::constants::WEIGHT_PER_NANOS;
|
||||
use frame_system::ConsumedWeight;
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_cli::{Error, Result};
|
||||
use sc_client_api::{Backend as ClientBackend, BlockBackend, StorageProvider, UsageProvider};
|
||||
use sc_client_api::{
|
||||
Backend as ClientBackend, BlockBackend, HeaderBackend, StorageProvider, UsageProvider,
|
||||
};
|
||||
use sp_api::{ApiExt, Core, HeaderT, ProvideRuntimeApi};
|
||||
use sp_blockchain::Error::RuntimeApiError;
|
||||
use sp_runtime::{generic::BlockId, traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
|
||||
@@ -73,7 +75,8 @@ where
|
||||
+ ProvideRuntimeApi<Block>
|
||||
+ StorageProvider<Block, BA>
|
||||
+ UsageProvider<Block>
|
||||
+ BlockBackend<Block>,
|
||||
+ BlockBackend<Block>
|
||||
+ HeaderBackend<Block>,
|
||||
C::Api: ApiExt<Block, StateBackend = BA::State> + BlockBuilderApi<Block>,
|
||||
{
|
||||
/// Returns a new [`Self`] from the arguments.
|
||||
@@ -136,9 +139,10 @@ where
|
||||
)?;
|
||||
let key = StorageKey(hash);
|
||||
|
||||
let block_hash = self.client.expect_block_hash_from_id(block)?;
|
||||
let mut raw_weight = &self
|
||||
.client
|
||||
.storage(&block, &key)?
|
||||
.storage(&block_hash, &key)?
|
||||
.ok_or(format!("Could not find System::BlockWeight for block: {}", block))?
|
||||
.0[..];
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||
use sc_client_api::{Backend as ClientBackend, BlockBackend, StorageProvider, UsageProvider};
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_runtime::{traits::Block as BlockT, OpaqueExtrinsic};
|
||||
|
||||
use clap::Parser;
|
||||
@@ -87,7 +88,8 @@ impl BlockCmd {
|
||||
+ BlockBackend<Block>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
+ StorageProvider<Block, BA>
|
||||
+ UsageProvider<Block>,
|
||||
+ UsageProvider<Block>
|
||||
+ HeaderBackend<Block>,
|
||||
C::Api: ApiExt<Block, StateBackend = BA::State> + BlockBuilderApi<Block>,
|
||||
{
|
||||
// Put everything in the benchmark type to have the generic types handy.
|
||||
|
||||
@@ -191,9 +191,9 @@ impl StorageCmd {
|
||||
B: BlockT + Debug,
|
||||
BA: ClientBackend<B>,
|
||||
{
|
||||
let block = BlockId::Hash(client.usage_info().chain.best_hash);
|
||||
let hash = client.usage_info().chain.best_hash;
|
||||
let empty_prefix = StorageKey(Vec::new());
|
||||
let mut keys = client.storage_keys(&block, &empty_prefix)?;
|
||||
let mut keys = client.storage_keys(&hash, &empty_prefix)?;
|
||||
let (mut rng, _) = new_rng(None);
|
||||
keys.shuffle(&mut rng);
|
||||
|
||||
@@ -201,7 +201,7 @@ impl StorageCmd {
|
||||
info!("Warmup round {}/{}", i + 1, self.params.warmups);
|
||||
for key in keys.as_slice() {
|
||||
let _ = client
|
||||
.storage(&block, &key)
|
||||
.storage(&hash, &key)
|
||||
.expect("Checked above to exist")
|
||||
.ok_or("Value unexpectedly empty");
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@
|
||||
use sc_cli::Result;
|
||||
use sc_client_api::{Backend as ClientBackend, StorageProvider, UsageProvider};
|
||||
use sp_core::storage::StorageKey;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, Header as HeaderT},
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
|
||||
use log::info;
|
||||
use rand::prelude::*;
|
||||
@@ -41,12 +38,12 @@ impl StorageCmd {
|
||||
<<B as BlockT>::Header as HeaderT>::Number: From<u32>,
|
||||
{
|
||||
let mut record = BenchRecord::default();
|
||||
let block = BlockId::Hash(client.usage_info().chain.best_hash);
|
||||
let best_hash = client.usage_info().chain.best_hash;
|
||||
|
||||
info!("Preparing keys from block {}", block);
|
||||
info!("Preparing keys from block {}", best_hash);
|
||||
// Load all keys and randomly shuffle them.
|
||||
let empty_prefix = StorageKey(Vec::new());
|
||||
let mut keys = client.storage_keys(&block, &empty_prefix)?;
|
||||
let mut keys = client.storage_keys(&best_hash, &empty_prefix)?;
|
||||
let (mut rng, _) = new_rng(None);
|
||||
keys.shuffle(&mut rng);
|
||||
|
||||
@@ -58,7 +55,7 @@ impl StorageCmd {
|
||||
match (self.params.include_child_trees, self.is_child_key(key.clone().0)) {
|
||||
(true, Some(info)) => {
|
||||
// child tree key
|
||||
let child_keys = client.child_storage_keys(&block, &info, &empty_prefix)?;
|
||||
let child_keys = client.child_storage_keys(&best_hash, &info, &empty_prefix)?;
|
||||
for ck in child_keys {
|
||||
child_nodes.push((ck.clone(), info.clone()));
|
||||
}
|
||||
@@ -67,7 +64,7 @@ impl StorageCmd {
|
||||
// regular key
|
||||
let start = Instant::now();
|
||||
let v = client
|
||||
.storage(&block, &key)
|
||||
.storage(&best_hash, &key)
|
||||
.expect("Checked above to exist")
|
||||
.ok_or("Value unexpectedly empty")?;
|
||||
record.append(v.0.len(), start.elapsed())?;
|
||||
@@ -82,7 +79,7 @@ impl StorageCmd {
|
||||
for (key, info) in child_nodes.as_slice() {
|
||||
let start = Instant::now();
|
||||
let v = client
|
||||
.child_storage(&block, info, key)
|
||||
.child_storage(&best_hash, info, key)
|
||||
.expect("Checked above to exist")
|
||||
.ok_or("Value unexpectedly empty")?;
|
||||
record.append(v.0.len(), start.elapsed())?;
|
||||
|
||||
@@ -57,12 +57,12 @@ impl StorageCmd {
|
||||
// Store the time that it took to write each value.
|
||||
let mut record = BenchRecord::default();
|
||||
|
||||
let block = BlockId::Hash(client.usage_info().chain.best_hash);
|
||||
let header = client.header(block)?.ok_or("Header not found")?;
|
||||
let best_hash = client.usage_info().chain.best_hash;
|
||||
let header = client.header(BlockId::Hash(best_hash))?.ok_or("Header not found")?;
|
||||
let original_root = *header.state_root();
|
||||
let trie = DbStateBuilder::<Block>::new(storage.clone(), original_root).build();
|
||||
|
||||
info!("Preparing keys from block {}", block);
|
||||
info!("Preparing keys from block {}", best_hash);
|
||||
// Load all KV pairs and randomly shuffle them.
|
||||
let mut kvs = trie.pairs();
|
||||
let (mut rng, _) = new_rng(None);
|
||||
@@ -77,7 +77,7 @@ impl StorageCmd {
|
||||
match (self.params.include_child_trees, self.is_child_key(k.to_vec())) {
|
||||
(true, Some(info)) => {
|
||||
let child_keys =
|
||||
client.child_storage_keys_iter(&block, info.clone(), None, None)?;
|
||||
client.child_storage_keys_iter(&best_hash, info.clone(), None, None)?;
|
||||
for ck in child_keys {
|
||||
child_nodes.push((ck.clone(), info.clone()));
|
||||
}
|
||||
@@ -124,7 +124,7 @@ impl StorageCmd {
|
||||
|
||||
for (key, info) in child_nodes {
|
||||
if let Some(original_v) = client
|
||||
.child_storage(&block, &info.clone(), &key)
|
||||
.child_storage(&best_hash, &info.clone(), &key)
|
||||
.expect("Checked above to exist")
|
||||
{
|
||||
let mut new_v = vec![0; original_v.0.len()];
|
||||
|
||||
Reference in New Issue
Block a user