mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 06:47:57 +00:00
This PR adds support for fetching the closest merkle value of some key. Builds on top of - https://github.com/paritytech/trie/pull/199 Migrates https://github.com/paritytech/substrate/pull/14818 to the monorepo. Closes: https://github.com/paritytech/substrate/issues/14550 Closes: https://github.com/paritytech/polkadot-sdk/issues/1506 // @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
@@ -37,7 +37,7 @@ use sp_state_machine::{
|
||||
};
|
||||
use sp_trie::{
|
||||
cache::{CacheSize, SharedTrieCache},
|
||||
prefixed_key, MemoryDB,
|
||||
prefixed_key, MemoryDB, MerkleValue,
|
||||
};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
@@ -382,6 +382,27 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
|
||||
.child_storage_hash(child_info, key)
|
||||
}
|
||||
|
||||
fn closest_merkle_value(
|
||||
&self,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.add_read_key(None, key);
|
||||
self.state.borrow().as_ref().ok_or_else(state_err)?.closest_merkle_value(key)
|
||||
}
|
||||
|
||||
fn child_closest_merkle_value(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.add_read_key(None, key);
|
||||
self.state
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.ok_or_else(state_err)?
|
||||
.child_closest_merkle_value(child_info, key)
|
||||
}
|
||||
|
||||
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
|
||||
self.add_read_key(None, key);
|
||||
self.state.borrow().as_ref().ok_or_else(state_err)?.exists_storage(key)
|
||||
|
||||
@@ -90,7 +90,7 @@ use sp_state_machine::{
|
||||
OffchainChangesCollection, StateMachineStats, StorageCollection, StorageIterator, StorageKey,
|
||||
StorageValue, UsageInfo as StateUsageInfo,
|
||||
};
|
||||
use sp_trie::{cache::SharedTrieCache, prefixed_key, MemoryDB, PrefixedMemoryDB};
|
||||
use sp_trie::{cache::SharedTrieCache, prefixed_key, MemoryDB, MerkleValue, PrefixedMemoryDB};
|
||||
|
||||
// Re-export the Database trait so that one can pass an implementation of it.
|
||||
pub use sc_state_db::PruningMode;
|
||||
@@ -214,6 +214,21 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
|
||||
self.state.child_storage_hash(child_info, key)
|
||||
}
|
||||
|
||||
fn closest_merkle_value(
|
||||
&self,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.state.closest_merkle_value(key)
|
||||
}
|
||||
|
||||
fn child_closest_merkle_value(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.state.child_closest_merkle_value(child_info, key)
|
||||
}
|
||||
|
||||
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
|
||||
self.state.exists_storage(key)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use sp_state_machine::{
|
||||
backend::{AsTrieBackend, Backend as StateBackend},
|
||||
BackendTransaction, IterArgs, StorageIterator, StorageKey, StorageValue, TrieBackend,
|
||||
};
|
||||
use sp_trie::MerkleValue;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// State abstraction for recording stats about state access.
|
||||
@@ -144,6 +145,21 @@ impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
|
||||
self.state.child_storage_hash(child_info, key)
|
||||
}
|
||||
|
||||
fn closest_merkle_value(
|
||||
&self,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.state.closest_merkle_value(key)
|
||||
}
|
||||
|
||||
fn child_closest_merkle_value(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
key: &[u8],
|
||||
) -> Result<Option<MerkleValue<B::Hash>>, Self::Error> {
|
||||
self.state.child_closest_merkle_value(child_info, key)
|
||||
}
|
||||
|
||||
fn exists_storage(&self, key: &[u8]) -> Result<bool, Self::Error> {
|
||||
self.state.exists_storage(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user