Frame remove_all with size limit. (#9106)

* remove prefixed content with limit.

* test match

* factor comment and factor ext limit removal.

* fix benchmark

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
cheme
2021-06-15 15:23:58 +02:00
committed by GitHub
parent 5f0257f3b3
commit 693b39f43b
36 changed files with 312 additions and 239 deletions
@@ -216,13 +216,13 @@ impl Externalities for BasicExternalities {
(true, num_removed as u32)
}
fn clear_prefix(&mut self, prefix: &[u8]) {
fn clear_prefix(&mut self, prefix: &[u8], _limit: Option<u32>) -> (bool, u32) {
if is_child_storage_key(prefix) {
warn!(
target: "trie",
"Refuse to clear prefix that is part of child storage key via main storage"
);
return;
return (false, 0);
}
let to_remove = self.inner.top.range::<[u8], _>((Bound::Included(prefix), Bound::Unbounded))
@@ -231,16 +231,19 @@ impl Externalities for BasicExternalities {
.cloned()
.collect::<Vec<_>>();
let num_removed = to_remove.len();
for key in to_remove {
self.inner.top.remove(&key);
}
(true, num_removed as u32)
}
fn clear_child_prefix(
&mut self,
child_info: &ChildInfo,
prefix: &[u8],
) {
_limit: Option<u32>,
) -> (bool, u32) {
if let Some(child) = self.inner.children_default.get_mut(child_info.storage_key()) {
let to_remove = child.data.range::<[u8], _>((Bound::Included(prefix), Bound::Unbounded))
.map(|(k, _)| k)
@@ -248,9 +251,13 @@ impl Externalities for BasicExternalities {
.cloned()
.collect::<Vec<_>>();
let num_removed = to_remove.len();
for key in to_remove {
child.data.remove(&key);
}
(true, num_removed as u32)
} else {
(true, 0)
}
}