mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
change HashFor to HashingFor (#14483)
* change HashFor to HashingFor * fmt * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: command-bot <>
This commit is contained in:
@@ -28,7 +28,7 @@ use sp_core::{
|
||||
storage::{ChildInfo, TrackedStorageKey},
|
||||
};
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, HashFor},
|
||||
traits::{Block as BlockT, HashingFor},
|
||||
StateVersion, Storage,
|
||||
};
|
||||
use sp_state_machine::{
|
||||
@@ -52,9 +52,9 @@ struct StorageDb<Block: BlockT> {
|
||||
_block: std::marker::PhantomData<Block>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for StorageDb<Block> {
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashingFor<Block>> for StorageDb<Block> {
|
||||
fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result<Option<DBValue>, String> {
|
||||
let prefixed_key = prefixed_key::<HashFor<Block>>(key, prefix);
|
||||
let prefixed_key = prefixed_key::<HashingFor<Block>>(key, prefix);
|
||||
self.db
|
||||
.get(0, &prefixed_key)
|
||||
.map_err(|e| format!("Database backend error: {:?}", e))
|
||||
@@ -84,19 +84,19 @@ pub struct BenchmarkingState<B: BlockT> {
|
||||
record: Cell<Vec<Vec<u8>>>,
|
||||
key_tracker: Arc<Mutex<KeyTracker>>,
|
||||
whitelist: RefCell<Vec<TrackedStorageKey>>,
|
||||
proof_recorder: Option<sp_trie::recorder::Recorder<HashFor<B>>>,
|
||||
proof_recorder: Option<sp_trie::recorder::Recorder<HashingFor<B>>>,
|
||||
proof_recorder_root: Cell<B::Hash>,
|
||||
shared_trie_cache: SharedTrieCache<HashFor<B>>,
|
||||
shared_trie_cache: SharedTrieCache<HashingFor<B>>,
|
||||
}
|
||||
|
||||
/// A raw iterator over the `BenchmarkingState`.
|
||||
pub struct RawIter<B: BlockT> {
|
||||
inner: <DbState<B> as StateBackend<HashFor<B>>>::RawIter,
|
||||
inner: <DbState<B> as StateBackend<HashingFor<B>>>::RawIter,
|
||||
child_trie: Option<Vec<u8>>,
|
||||
key_tracker: Arc<Mutex<KeyTracker>>,
|
||||
}
|
||||
|
||||
impl<B: BlockT> StorageIterator<HashFor<B>> for RawIter<B> {
|
||||
impl<B: BlockT> StorageIterator<HashingFor<B>> for RawIter<B> {
|
||||
type Backend = BenchmarkingState<B>;
|
||||
type Error = String;
|
||||
|
||||
@@ -138,8 +138,8 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
) -> Result<Self, String> {
|
||||
let state_version = sp_runtime::StateVersion::default();
|
||||
let mut root = B::Hash::default();
|
||||
let mut mdb = MemoryDB::<HashFor<B>>::default();
|
||||
sp_trie::trie_types::TrieDBMutBuilderV1::<HashFor<B>>::new(&mut mdb, &mut root).build();
|
||||
let mut mdb = MemoryDB::<HashingFor<B>>::default();
|
||||
sp_trie::trie_types::TrieDBMutBuilderV1::<HashingFor<B>>::new(&mut mdb, &mut root).build();
|
||||
|
||||
let mut state = BenchmarkingState {
|
||||
state: RefCell::new(None),
|
||||
@@ -341,10 +341,10 @@ fn state_err() -> String {
|
||||
"State is not open".into()
|
||||
}
|
||||
|
||||
impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
|
||||
type Error = <DbState<B> as StateBackend<HashFor<B>>>::Error;
|
||||
type Transaction = <DbState<B> as StateBackend<HashFor<B>>>::Transaction;
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashFor<B>>>::TrieBackendStorage;
|
||||
impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
|
||||
type Error = <DbState<B> as StateBackend<HashingFor<B>>>::Error;
|
||||
type Transaction = <DbState<B> as StateBackend<HashingFor<B>>>::Transaction;
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashingFor<B>>>::TrieBackendStorage;
|
||||
type RawIter = RawIter<B>;
|
||||
|
||||
fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
|
||||
@@ -459,7 +459,7 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
|
||||
|
||||
fn commit(
|
||||
&self,
|
||||
storage_root: <HashFor<B> as Hasher>::Out,
|
||||
storage_root: <HashingFor<B> as Hasher>::Out,
|
||||
mut transaction: Self::Transaction,
|
||||
main_storage_changes: StorageCollection,
|
||||
child_storage_changes: ChildStorageCollection,
|
||||
@@ -614,7 +614,8 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
|
||||
log::debug!(target: "benchmark", "Some proof size: {}", &proof_size);
|
||||
proof_size
|
||||
} else {
|
||||
if let Some(size) = proof.encoded_compact_size::<HashFor<B>>(proof_recorder_root) {
|
||||
if let Some(size) = proof.encoded_compact_size::<HashingFor<B>>(proof_recorder_root)
|
||||
{
|
||||
size as u32
|
||||
} else if proof_recorder_root == self.root.get() {
|
||||
log::debug!(target: "benchmark", "No changes - no proof");
|
||||
|
||||
@@ -79,7 +79,7 @@ use sp_database::Transaction;
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{
|
||||
Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One, SaturatedConversion,
|
||||
Block as BlockT, Hash, HashingFor, Header as HeaderT, NumberFor, One, SaturatedConversion,
|
||||
Zero,
|
||||
},
|
||||
Justification, Justifications, StateVersion, Storage,
|
||||
@@ -102,12 +102,12 @@ const CACHE_HEADERS: usize = 8;
|
||||
|
||||
/// DB-backed patricia trie state, transaction type is an overlay of changes to commit.
|
||||
pub type DbState<B> =
|
||||
sp_state_machine::TrieBackend<Arc<dyn sp_state_machine::Storage<HashFor<B>>>, HashFor<B>>;
|
||||
sp_state_machine::TrieBackend<Arc<dyn sp_state_machine::Storage<HashingFor<B>>>, HashingFor<B>>;
|
||||
|
||||
/// Builder for [`DbState`].
|
||||
pub type DbStateBuilder<B> = sp_state_machine::TrieBackendBuilder<
|
||||
Arc<dyn sp_state_machine::Storage<HashFor<B>>>,
|
||||
HashFor<B>,
|
||||
Arc<dyn sp_state_machine::Storage<HashingFor<B>>>,
|
||||
HashingFor<B>,
|
||||
>;
|
||||
|
||||
/// Length of a [`DbHash`].
|
||||
@@ -162,12 +162,12 @@ impl<Block: BlockT> std::fmt::Debug for RefTrackingState<Block> {
|
||||
|
||||
/// A raw iterator over the `RefTrackingState`.
|
||||
pub struct RawIter<B: BlockT> {
|
||||
inner: <DbState<B> as StateBackend<HashFor<B>>>::RawIter,
|
||||
inner: <DbState<B> as StateBackend<HashingFor<B>>>::RawIter,
|
||||
}
|
||||
|
||||
impl<B: BlockT> StorageIterator<HashFor<B>> for RawIter<B> {
|
||||
impl<B: BlockT> StorageIterator<HashingFor<B>> for RawIter<B> {
|
||||
type Backend = RefTrackingState<B>;
|
||||
type Error = <DbState<B> as StateBackend<HashFor<B>>>::Error;
|
||||
type Error = <DbState<B> as StateBackend<HashingFor<B>>>::Error;
|
||||
|
||||
fn next_key(&mut self, backend: &Self::Backend) -> Option<Result<StorageKey, Self::Error>> {
|
||||
self.inner.next_key(&backend.state)
|
||||
@@ -185,10 +185,10 @@ impl<B: BlockT> StorageIterator<HashFor<B>> for RawIter<B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> StateBackend<HashFor<B>> for RefTrackingState<B> {
|
||||
type Error = <DbState<B> as StateBackend<HashFor<B>>>::Error;
|
||||
type Transaction = <DbState<B> as StateBackend<HashFor<B>>>::Transaction;
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashFor<B>>>::TrieBackendStorage;
|
||||
impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
|
||||
type Error = <DbState<B> as StateBackend<HashingFor<B>>>::Error;
|
||||
type Transaction = <DbState<B> as StateBackend<HashingFor<B>>>::Transaction;
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashingFor<B>>>::TrieBackendStorage;
|
||||
type RawIter = RawIter<B>;
|
||||
|
||||
fn storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
|
||||
@@ -269,12 +269,12 @@ impl<B: BlockT> StateBackend<HashFor<B>> for RefTrackingState<B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> AsTrieBackend<HashFor<B>> for RefTrackingState<B> {
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashFor<B>>>::TrieBackendStorage;
|
||||
impl<B: BlockT> AsTrieBackend<HashingFor<B>> for RefTrackingState<B> {
|
||||
type TrieBackendStorage = <DbState<B> as StateBackend<HashingFor<B>>>::TrieBackendStorage;
|
||||
|
||||
fn as_trie_backend(
|
||||
&self,
|
||||
) -> &sp_state_machine::TrieBackend<Self::TrieBackendStorage, HashFor<B>> {
|
||||
) -> &sp_state_machine::TrieBackend<Self::TrieBackendStorage, HashingFor<B>> {
|
||||
&self.state.as_trie_backend()
|
||||
}
|
||||
}
|
||||
@@ -818,7 +818,7 @@ impl<Block: BlockT> HeaderMetadata<Block> for BlockchainDb<Block> {
|
||||
/// Database transaction
|
||||
pub struct BlockImportOperation<Block: BlockT> {
|
||||
old_state: RecordStatsState<RefTrackingState<Block>, Block>,
|
||||
db_updates: PrefixedMemoryDB<HashFor<Block>>,
|
||||
db_updates: PrefixedMemoryDB<HashingFor<Block>>,
|
||||
storage_updates: StorageCollection,
|
||||
child_storage_updates: ChildStorageCollection,
|
||||
offchain_storage_updates: OffchainChangesCollection,
|
||||
@@ -907,7 +907,10 @@ impl<Block: BlockT> sc_client_api::backend::BlockImportOperation<Block>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_db_storage(&mut self, update: PrefixedMemoryDB<HashFor<Block>>) -> ClientResult<()> {
|
||||
fn update_db_storage(
|
||||
&mut self,
|
||||
update: PrefixedMemoryDB<HashingFor<Block>>,
|
||||
) -> ClientResult<()> {
|
||||
self.db_updates = update;
|
||||
Ok(())
|
||||
}
|
||||
@@ -986,10 +989,10 @@ struct StorageDb<Block: BlockT> {
|
||||
prefix_keys: bool,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for StorageDb<Block> {
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashingFor<Block>> for StorageDb<Block> {
|
||||
fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result<Option<DBValue>, String> {
|
||||
if self.prefix_keys {
|
||||
let key = prefixed_key::<HashFor<Block>>(key, prefix);
|
||||
let key = prefixed_key::<HashingFor<Block>>(key, prefix);
|
||||
self.state_db.get(&key, self)
|
||||
} else {
|
||||
self.state_db.get(key.as_ref(), self)
|
||||
@@ -1009,16 +1012,16 @@ impl<Block: BlockT> sc_state_db::NodeDb for StorageDb<Block> {
|
||||
|
||||
struct DbGenesisStorage<Block: BlockT> {
|
||||
root: Block::Hash,
|
||||
storage: PrefixedMemoryDB<HashFor<Block>>,
|
||||
storage: PrefixedMemoryDB<HashingFor<Block>>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> DbGenesisStorage<Block> {
|
||||
pub fn new(root: Block::Hash, storage: PrefixedMemoryDB<HashFor<Block>>) -> Self {
|
||||
pub fn new(root: Block::Hash, storage: PrefixedMemoryDB<HashingFor<Block>>) -> Self {
|
||||
DbGenesisStorage { root, storage }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for DbGenesisStorage<Block> {
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashingFor<Block>> for DbGenesisStorage<Block> {
|
||||
fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result<Option<DBValue>, String> {
|
||||
use hash_db::HashDB;
|
||||
Ok(self.storage.get(key, prefix))
|
||||
@@ -1030,14 +1033,15 @@ struct EmptyStorage<Block: BlockT>(pub Block::Hash);
|
||||
impl<Block: BlockT> EmptyStorage<Block> {
|
||||
pub fn new() -> Self {
|
||||
let mut root = Block::Hash::default();
|
||||
let mut mdb = MemoryDB::<HashFor<Block>>::default();
|
||||
let mut mdb = MemoryDB::<HashingFor<Block>>::default();
|
||||
// both triedbmut are the same on empty storage.
|
||||
sp_trie::trie_types::TrieDBMutBuilderV1::<HashFor<Block>>::new(&mut mdb, &mut root).build();
|
||||
sp_trie::trie_types::TrieDBMutBuilderV1::<HashingFor<Block>>::new(&mut mdb, &mut root)
|
||||
.build();
|
||||
EmptyStorage(root)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for EmptyStorage<Block> {
|
||||
impl<Block: BlockT> sp_state_machine::Storage<HashingFor<Block>> for EmptyStorage<Block> {
|
||||
fn get(&self, _key: &Block::Hash, _prefix: Prefix) -> Result<Option<DBValue>, String> {
|
||||
Ok(None)
|
||||
}
|
||||
@@ -1098,7 +1102,7 @@ pub struct Backend<Block: BlockT> {
|
||||
io_stats: FrozenForDuration<(kvdb::IoStats, StateUsageInfo)>,
|
||||
state_usage: Arc<StateUsageStats>,
|
||||
genesis_state: RwLock<Option<Arc<DbGenesisStorage<Block>>>>,
|
||||
shared_trie_cache: Option<sp_trie::cache::SharedTrieCache<HashFor<Block>>>,
|
||||
shared_trie_cache: Option<sp_trie::cache::SharedTrieCache<HashingFor<Block>>>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT> Backend<Block> {
|
||||
@@ -1173,7 +1177,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
///
|
||||
/// Should only be needed for benchmarking.
|
||||
#[cfg(any(feature = "runtime-benchmarks"))]
|
||||
pub fn expose_storage(&self) -> Arc<dyn sp_state_machine::Storage<HashFor<Block>>> {
|
||||
pub fn expose_storage(&self) -> Arc<dyn sp_state_machine::Storage<HashingFor<Block>>> {
|
||||
self.storage.clone()
|
||||
}
|
||||
|
||||
@@ -3542,8 +3546,8 @@ pub(crate) mod tests {
|
||||
|
||||
let x0 = ExtrinsicWrapper::from(0u64).encode();
|
||||
let x1 = ExtrinsicWrapper::from(1u64).encode();
|
||||
let x0_hash = <HashFor<Block> as sp_core::Hasher>::hash(&x0[1..]);
|
||||
let x1_hash = <HashFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
||||
let x0_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x0[1..]);
|
||||
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
||||
let index = vec![
|
||||
IndexOperation::Insert {
|
||||
extrinsic: 0,
|
||||
@@ -3586,8 +3590,8 @@ pub(crate) mod tests {
|
||||
|
||||
let x0 = ExtrinsicWrapper::from(0u64).encode();
|
||||
let x1 = ExtrinsicWrapper::from(1u64).encode();
|
||||
let x0_hash = <HashFor<Block> as sp_core::Hasher>::hash(&x0[..]);
|
||||
let x1_hash = <HashFor<Block> as sp_core::Hasher>::hash(&x1[..]);
|
||||
let x0_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x0[..]);
|
||||
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[..]);
|
||||
let index = vec![
|
||||
IndexOperation::Insert {
|
||||
extrinsic: 0,
|
||||
@@ -3621,7 +3625,7 @@ pub(crate) mod tests {
|
||||
let mut blocks = Vec::new();
|
||||
let mut prev_hash = Default::default();
|
||||
let x1 = ExtrinsicWrapper::from(0u64).encode();
|
||||
let x1_hash = <HashFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
||||
let x1_hash = <HashingFor<Block> as sp_core::Hasher>::hash(&x1[1..]);
|
||||
for i in 0..10 {
|
||||
let mut index = Vec::new();
|
||||
if i == 0 {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use crate::stats::StateUsageStats;
|
||||
use sp_core::storage::ChildInfo;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, HashFor},
|
||||
traits::{Block as BlockT, HashingFor},
|
||||
StateVersion,
|
||||
};
|
||||
use sp_state_machine::{
|
||||
@@ -56,7 +56,7 @@ impl<S, B: BlockT> Drop for RecordStatsState<S, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: StateBackend<HashFor<B>>, B: BlockT> RecordStatsState<S, B> {
|
||||
impl<S: StateBackend<HashingFor<B>>, B: BlockT> RecordStatsState<S, B> {
|
||||
/// Create a new instance wrapping generic State and shared cache.
|
||||
pub(crate) fn new(
|
||||
state: S,
|
||||
@@ -75,15 +75,15 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> RecordStatsState<S, B> {
|
||||
|
||||
pub struct RawIter<S, B>
|
||||
where
|
||||
S: StateBackend<HashFor<B>>,
|
||||
S: StateBackend<HashingFor<B>>,
|
||||
B: BlockT,
|
||||
{
|
||||
inner: <S as StateBackend<HashFor<B>>>::RawIter,
|
||||
inner: <S as StateBackend<HashingFor<B>>>::RawIter,
|
||||
}
|
||||
|
||||
impl<S, B> StorageIterator<HashFor<B>> for RawIter<S, B>
|
||||
impl<S, B> StorageIterator<HashingFor<B>> for RawIter<S, B>
|
||||
where
|
||||
S: StateBackend<HashFor<B>>,
|
||||
S: StateBackend<HashingFor<B>>,
|
||||
B: BlockT,
|
||||
{
|
||||
type Backend = RecordStatsState<S, B>;
|
||||
@@ -105,7 +105,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for RecordStatsState<S, B> {
|
||||
impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
|
||||
for RecordStatsState<S, B>
|
||||
{
|
||||
type Error = S::Error;
|
||||
type Transaction = S::Transaction;
|
||||
type TrieBackendStorage = S::TrieBackendStorage;
|
||||
@@ -199,12 +201,12 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Record
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: StateBackend<HashFor<B>> + AsTrieBackend<HashFor<B>>, B: BlockT> AsTrieBackend<HashFor<B>>
|
||||
for RecordStatsState<S, B>
|
||||
impl<S: StateBackend<HashingFor<B>> + AsTrieBackend<HashingFor<B>>, B: BlockT>
|
||||
AsTrieBackend<HashingFor<B>> for RecordStatsState<S, B>
|
||||
{
|
||||
type TrieBackendStorage = <S as AsTrieBackend<HashFor<B>>>::TrieBackendStorage;
|
||||
type TrieBackendStorage = <S as AsTrieBackend<HashingFor<B>>>::TrieBackendStorage;
|
||||
|
||||
fn as_trie_backend(&self) -> &TrieBackend<Self::TrieBackendStorage, HashFor<B>> {
|
||||
fn as_trie_backend(&self) -> &TrieBackend<Self::TrieBackendStorage, HashingFor<B>> {
|
||||
self.state.as_trie_backend()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user