mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Add storage cache for child trie and notification internals (#2639)
* child cache, and test failing notifications * fix tests and no listen child on top wildcard * remove useless method * bump impl version * Update core/client/src/notifications.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update core/client/src/notifications.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update core/client/src/notifications.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update core/client/src/notifications.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * factoring notification methods to remove some redundant code. * test child sub removal * HStorage implementation and some type alias. * Remove HStorage cache: does not fit * fix removal * Make cache use byte length (shared) instead of number of kv * Make use of hashes cache in rpc * applying ratio on different lru caches * Fix format * break a line * Remove per element overhead of lru cache. * typo
This commit is contained in:
@@ -362,8 +362,9 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
}
|
||||
|
||||
fn storage_hash(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<Block::Hash>> {
|
||||
use runtime_primitives::traits::{Hash, Header as HeaderT};
|
||||
Ok(self.storage(key, block)?.map(|x| <Block::Header as HeaderT>::Hashing::hash(&x.0)))
|
||||
let block = self.unwrap_or_best(block)?;
|
||||
trace!(target: "rpc", "Querying storage hash at {:?} for key {}", block, HexDisplay::from(&key.0));
|
||||
Ok(self.client.storage_hash(&BlockId::Hash(block), &key)?)
|
||||
}
|
||||
|
||||
fn storage_size(&self, key: StorageKey, block: Option<Block::Hash>) -> Result<Option<u64>> {
|
||||
@@ -398,11 +399,13 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
key: StorageKey,
|
||||
block: Option<Block::Hash>
|
||||
) -> Result<Option<Block::Hash>> {
|
||||
use runtime_primitives::traits::{Hash, Header as HeaderT};
|
||||
Ok(
|
||||
self.child_storage(child_storage_key, key, block)?
|
||||
.map(|x| <Block::Header as HeaderT>::Hashing::hash(&x.0))
|
||||
)
|
||||
let block = self.unwrap_or_best(block)?;
|
||||
trace!(
|
||||
target: "rpc", "Querying child storage hash at {:?} for key {}",
|
||||
block,
|
||||
HexDisplay::from(&key.0),
|
||||
);
|
||||
Ok(self.client.child_storage_hash(&BlockId::Hash(block), &child_storage_key, &key)?)
|
||||
}
|
||||
|
||||
fn child_storage_size(
|
||||
@@ -439,7 +442,10 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
keys: Option<Vec<StorageKey>>
|
||||
) {
|
||||
let keys = Into::<Option<Vec<_>>>::into(keys);
|
||||
let stream = match self.client.storage_changes_notification_stream(keys.as_ref().map(|x| &**x)) {
|
||||
let stream = match self.client.storage_changes_notification_stream(
|
||||
keys.as_ref().map(|x| &**x),
|
||||
None
|
||||
) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
let _ = subscriber.reject(error::Error::from(err).into());
|
||||
@@ -466,7 +472,10 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
.map_err(|e| warn!("Error creating storage notification stream: {:?}", e))
|
||||
.map(|(block, changes)| Ok(StorageChangeSet {
|
||||
block,
|
||||
changes: changes.iter().cloned().collect(),
|
||||
changes: changes.iter()
|
||||
.filter_map(|(o_sk, k, v)| if o_sk.is_none() {
|
||||
Some((k.clone(),v.cloned()))
|
||||
} else { None }).collect(),
|
||||
}));
|
||||
|
||||
sink
|
||||
@@ -488,7 +497,8 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
|
||||
fn subscribe_runtime_version(&self, _meta: Self::Metadata, subscriber: Subscriber<RuntimeVersion>) {
|
||||
let stream = match self.client.storage_changes_notification_stream(
|
||||
Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())])
|
||||
Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())]),
|
||||
None,
|
||||
) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
|
||||
Reference in New Issue
Block a user