Allow capping the amount of work performed when deleting a child trie (#7671)

* Allow Backend::for_keys_in_child_storage to be aborted by the closure

* Ext::kill_child_storage now takes an upper limit for backend deletion

* Add Storage::storage_kill_limited() runtime interface

* review: Use a new version of kill_storage instead of a new interface

* review: Simplify boolean expression

Co-authored-by: cheme <emericchevalier.pro@gmail.com>

* review: Rename for_keys_in_child_storage

Co-authored-by: cheme <emericchevalier.pro@gmail.com>
This commit is contained in:
Alexander Theißen
2020-12-09 02:17:28 +01:00
committed by GitHub
parent 4689c21069
commit 9ce24fe1f4
19 changed files with 219 additions and 34 deletions
+11 -1
View File
@@ -137,7 +137,17 @@ pub trait Externalities: ExtensionStore {
) -> Option<Vec<u8>>;
/// Clear an entire child storage.
fn kill_child_storage(&mut self, child_info: &ChildInfo);
///
/// Deletes all keys from the overlay and up to `limit` keys from the backend. No
/// limit is applied if `limit` is `None`. Returns `true` if the child trie was
/// removed completely and `false` if there are remaining keys after the function
/// returns.
///
/// # Note
///
/// An implementation is free to delete more keys than the specified limit as long as
/// it is able to do that in constant time.
fn kill_child_storage(&mut self, child_info: &ChildInfo, limit: Option<u32>) -> bool;
/// Clear storage entries which keys are start with the given prefix.
fn clear_prefix(&mut self, prefix: &[u8]);