Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow Backend::for_keys_in_child_storage to be aborted by the closure
  • Loading branch information
athei committed Dec 3, 2020
commit 5265fba92b441768201fdb87c735a6681b87ea2c
2 changes: 1 addition & 1 deletion client/db/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
}
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
2 changes: 1 addition & 1 deletion client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<B: BlockT> StateBackend<HashFor<B>> for RefTrackingState<B> {
self.state.for_key_values_with_prefix(prefix, f)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
4 changes: 2 additions & 2 deletions client/db/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Cachin
self.state.exists_child_storage(child_info, key)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down Expand Up @@ -766,7 +766,7 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Syncin
self.caching_state().exists_child_storage(child_info, key)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
2 changes: 1 addition & 1 deletion client/light/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
}
}

fn for_keys_in_child_storage<A: FnMut(&[u8])>(
fn for_keys_in_child_storage<A: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
action: A,
Expand Down
5 changes: 3 additions & 2 deletions primitives/state-machine/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
) -> Result<Option<StorageKey>, Self::Error>;

/// Retrieve all entries keys of child storage and call `f` for each of those keys.
fn for_keys_in_child_storage<F: FnMut(&[u8])>(
/// Aborts as soon as `f` returns false.
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down Expand Up @@ -263,7 +264,7 @@ impl<'a, T: Backend<H>, H: Hasher> Backend<H> for &'a T {
(*self).child_storage(child_info, key)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
1 change: 1 addition & 0 deletions primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ where
self.overlay.clear_child_storage(child_info);
self.backend.for_keys_in_child_storage(child_info, |key| {
self.overlay.set_child_storage(child_info, key.to_vec(), None);
true
});
}

Expand Down
2 changes: 1 addition & 1 deletion primitives/state-machine/src/proving_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a, S, H> Backend<H> for ProvingBackend<'a, S, H>
self.0.child_storage(child_info, key)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
2 changes: 1 addition & 1 deletion primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> Backend<H> for TrieBackend<S, H> where
self.essence.for_key_values_with_prefix(prefix, f)
}

fn for_keys_in_child_storage<F: FnMut(&[u8])>(
fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
3 changes: 2 additions & 1 deletion primitives/state-machine/src/trie_backend_essence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ impl<S: TrieBackendStorage<H>, H: Hasher> TrieBackendEssence<S, H> where H::Out:
}

/// Retrieve all entries keys of child storage and call `f` for each of those keys.
pub fn for_keys_in_child_storage<F: FnMut(&[u8])>(
/// Aborts as soon as `f` returns false.
pub fn for_keys_in_child_storage<F: FnMut(&[u8]) -> bool>(
&self,
child_info: &ChildInfo,
f: F,
Expand Down
7 changes: 5 additions & 2 deletions primitives/trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ pub fn child_delta_trie_root<L: TrieConfiguration, I, A, B, DB, RD, V>(
}

/// Call `f` for all keys in a child trie.
pub fn for_keys_in_child_trie<L: TrieConfiguration, F: FnMut(&[u8]), DB>(
/// Aborts as soon as `f` returns false.
pub fn for_keys_in_child_trie<L: TrieConfiguration, F: FnMut(&[u8]) -> bool, DB>(
keyspace: &[u8],
db: &DB,
root_slice: &[u8],
Expand All @@ -290,7 +291,9 @@ pub fn for_keys_in_child_trie<L: TrieConfiguration, F: FnMut(&[u8]), DB>(

for x in iter {
let (key, _) = x?;
f(&key);
if !f(&key) {
break;
}
}

Ok(())
Expand Down