mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Return number of keys removed when calling storage_kill on child trie (#8166)
* Initial piping of returning amount of keys killed * One more test for `None` limit * forgot to update * fix return value * use version 3 * Update to return `KillOutcome` * Update name to KillChildStorageResult
This commit is contained in:
@@ -57,7 +57,7 @@ use sp_core::{
|
||||
use sp_trie::{TrieConfiguration, trie_types::Layout};
|
||||
|
||||
use sp_runtime_interface::{runtime_interface, Pointer};
|
||||
use sp_runtime_interface::pass_by::PassBy;
|
||||
use sp_runtime_interface::pass_by::{PassBy, PassByCodec};
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
@@ -81,6 +81,16 @@ pub enum EcdsaVerifyError {
|
||||
BadSignature,
|
||||
}
|
||||
|
||||
/// The outcome of calling [`kill_storage`]. Returned value is the number of storage items
|
||||
/// removed from the trie from making the `kill_storage` call.
|
||||
#[derive(PassByCodec, Encode, Decode)]
|
||||
pub enum KillChildStorageResult {
|
||||
/// No key remains in the child trie.
|
||||
AllRemoved(u32),
|
||||
/// At least one key still resides in the child trie due to the supplied limit.
|
||||
SomeRemaining(u32),
|
||||
}
|
||||
|
||||
/// Interface for accessing the storage from within the runtime.
|
||||
#[runtime_interface]
|
||||
pub trait Storage {
|
||||
@@ -290,7 +300,7 @@ pub trait DefaultChildStorage {
|
||||
/// The limit can be used to partially delete a child trie in case it is too large
|
||||
/// to delete in one go (block).
|
||||
///
|
||||
/// It returns false iff some keys are remaining in
|
||||
/// It returns a boolean false iff some keys are remaining in
|
||||
/// the child trie after the functions returns.
|
||||
///
|
||||
/// # Note
|
||||
@@ -307,7 +317,41 @@ pub trait DefaultChildStorage {
|
||||
#[version(2)]
|
||||
fn storage_kill(&mut self, storage_key: &[u8], limit: Option<u32>) -> bool {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
self.kill_child_storage(&child_info, limit)
|
||||
let (all_removed, _num_removed) = self.kill_child_storage(&child_info, limit);
|
||||
all_removed
|
||||
}
|
||||
|
||||
/// Clear a child storage key.
|
||||
///
|
||||
/// Deletes all keys from the overlay and up to `limit` keys from the backend if
|
||||
/// it is set to `Some`. No limit is applied when `limit` is set to `None`.
|
||||
///
|
||||
/// The limit can be used to partially delete a child trie in case it is too large
|
||||
/// to delete in one go (block).
|
||||
///
|
||||
/// It returns a boolean false iff some keys are remaining in
|
||||
/// the child trie after the functions returns. Also returns a `u32` with
|
||||
/// the number of keys removed from the process.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Please note that keys that are residing in the overlay for that child trie when
|
||||
/// issuing this call are all deleted without counting towards the `limit`. Only keys
|
||||
/// written during the current block are part of the overlay. Deleting with a `limit`
|
||||
/// mostly makes sense with an empty overlay for that child trie.
|
||||
///
|
||||
/// Calling this function multiple times per block for the same `storage_key` does
|
||||
/// not make much sense because it is not cumulative when called inside the same block.
|
||||
/// Use this function to distribute the deletion of a single child trie across multiple
|
||||
/// blocks.
|
||||
#[version(3)]
|
||||
fn storage_kill(&mut self, storage_key: &[u8], limit: Option<u32>) -> KillChildStorageResult {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
let (all_removed, num_removed) = self.kill_child_storage(&child_info, limit);
|
||||
match all_removed {
|
||||
true => KillChildStorageResult::AllRemoved(num_removed),
|
||||
false => KillChildStorageResult::SomeRemaining(num_removed),
|
||||
}
|
||||
}
|
||||
|
||||
/// Check a child storage key.
|
||||
|
||||
Reference in New Issue
Block a user