mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Rework storage iterators (#13284)
* Rework storage iterators * Make sure storage iteration is also accounted for when benchmarking * Use `trie-db` from crates.io * Appease clippy * Bump `trie-bench` to 0.35.0 * Fix tests' compilation * Update comment to clarify how `IterArgs::start_at` works * Add extra tests * Fix iterators on `Client` so that they behave as before * Add extra `unwrap`s in tests * More clippy fixes * Come on clippy, give me a break already * Rename `allow_missing` to `stop_on_incomplete_database` * Add `#[inline]` to `with_recorder_and_cache` * Use `with_recorder_and_cache` in `with_trie_db`; add doc comment * Simplify code: use `with_trie_db` in `next_storage_key_from_root` * Remove `expect`s in the benchmarking CLI * Add extra doc comments * Move `RawIter` before `TrieBackendEssence` (no code changes; just cut-paste) * Remove a TODO in tests * Update comment for `StorageIterator::was_complete` * Update `trie-db` to 0.25.1
This commit is contained in:
@@ -213,23 +213,29 @@ where
|
||||
.map_err(client_err)
|
||||
}
|
||||
|
||||
// TODO: This is horribly broken; either remove it, or make it streaming.
|
||||
fn storage_keys(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
prefix: StorageKey,
|
||||
) -> std::result::Result<Vec<StorageKey>, Error> {
|
||||
// TODO: Remove the `.collect`.
|
||||
self.block_or_best(block)
|
||||
.and_then(|block| self.client.storage_keys(block, &prefix))
|
||||
.and_then(|block| self.client.storage_keys(block, Some(&prefix), None))
|
||||
.map(|iter| iter.collect())
|
||||
.map_err(client_err)
|
||||
}
|
||||
|
||||
// TODO: This is horribly broken; either remove it, or make it streaming.
|
||||
fn storage_pairs(
|
||||
&self,
|
||||
block: Option<Block::Hash>,
|
||||
prefix: StorageKey,
|
||||
) -> std::result::Result<Vec<(StorageKey, StorageData)>, Error> {
|
||||
// TODO: Remove the `.collect`.
|
||||
self.block_or_best(block)
|
||||
.and_then(|block| self.client.storage_pairs(block, &prefix))
|
||||
.and_then(|block| self.client.storage_pairs(block, Some(&prefix), None))
|
||||
.map(|iter| iter.collect())
|
||||
.map_err(client_err)
|
||||
}
|
||||
|
||||
@@ -241,9 +247,7 @@ where
|
||||
start_key: Option<StorageKey>,
|
||||
) -> std::result::Result<Vec<StorageKey>, Error> {
|
||||
self.block_or_best(block)
|
||||
.and_then(|block| {
|
||||
self.client.storage_keys_iter(block, prefix.as_ref(), start_key.as_ref())
|
||||
})
|
||||
.and_then(|block| self.client.storage_keys(block, prefix.as_ref(), start_key.as_ref()))
|
||||
.map(|iter| iter.take(count as usize).collect())
|
||||
.map_err(client_err)
|
||||
}
|
||||
@@ -284,7 +288,7 @@ where
|
||||
}
|
||||
|
||||
// The key doesn't point to anything, so it's probably a prefix.
|
||||
let iter = match client.storage_keys_iter(block, Some(&key), None).map_err(client_err) {
|
||||
let iter = match client.storage_keys(block, Some(&key), None).map_err(client_err) {
|
||||
Ok(iter) => iter,
|
||||
Err(e) => return Ok(Err(e)),
|
||||
};
|
||||
@@ -531,6 +535,7 @@ where
|
||||
storage_key: PrefixedStorageKey,
|
||||
prefix: StorageKey,
|
||||
) -> std::result::Result<Vec<StorageKey>, Error> {
|
||||
// TODO: Remove the `.collect`.
|
||||
self.block_or_best(block)
|
||||
.and_then(|block| {
|
||||
let child_info = match ChildType::from_prefixed_key(&storage_key) {
|
||||
@@ -538,8 +543,9 @@ where
|
||||
ChildInfo::new_default(storage_key),
|
||||
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
|
||||
};
|
||||
self.client.child_storage_keys(block, &child_info, &prefix)
|
||||
self.client.child_storage_keys(block, child_info, Some(&prefix), None)
|
||||
})
|
||||
.map(|iter| iter.collect())
|
||||
.map_err(client_err)
|
||||
}
|
||||
|
||||
@@ -558,7 +564,7 @@ where
|
||||
ChildInfo::new_default(storage_key),
|
||||
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
|
||||
};
|
||||
self.client.child_storage_keys_iter(
|
||||
self.client.child_storage_keys(
|
||||
block,
|
||||
child_info,
|
||||
prefix.as_ref(),
|
||||
|
||||
Reference in New Issue
Block a user