mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +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:
@@ -32,7 +32,7 @@ use sp_core::crypto::UncheckedFrom;
|
||||
use frame_support::{
|
||||
dispatch::DispatchResult,
|
||||
debug,
|
||||
storage::child::{self, KillOutcome},
|
||||
storage::child::{self, KillChildStorageResult},
|
||||
traits::Get,
|
||||
weights::Weight,
|
||||
};
|
||||
@@ -269,13 +269,13 @@ where
|
||||
let removed = queue.swap_remove(0);
|
||||
match outcome {
|
||||
// This should not happen as our budget was large enough to remove all keys.
|
||||
KillOutcome::SomeRemaining => {
|
||||
KillChildStorageResult::SomeRemaining(_) => {
|
||||
debug::error!(
|
||||
"After deletion keys are remaining in this child trie: {:?}",
|
||||
removed.trie_id,
|
||||
);
|
||||
},
|
||||
KillOutcome::AllRemoved => (),
|
||||
KillChildStorageResult::AllRemoved(_) => (),
|
||||
}
|
||||
}
|
||||
remaining_key_budget = remaining_key_budget
|
||||
|
||||
@@ -24,14 +24,7 @@
|
||||
use crate::sp_std::prelude::*;
|
||||
use codec::{Codec, Encode, Decode};
|
||||
pub use sp_core::storage::{ChildInfo, ChildType};
|
||||
|
||||
/// The outcome of calling [`kill_storage`].
|
||||
pub enum KillOutcome {
|
||||
/// No key remains in the child trie.
|
||||
AllRemoved,
|
||||
/// At least one key still resides in the child trie due to the supplied limit.
|
||||
SomeRemaining,
|
||||
}
|
||||
pub use crate::sp_io::KillChildStorageResult;
|
||||
|
||||
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
|
||||
pub fn get<T: Decode + Sized>(
|
||||
@@ -177,16 +170,12 @@ pub fn exists(
|
||||
pub fn kill_storage(
|
||||
child_info: &ChildInfo,
|
||||
limit: Option<u32>,
|
||||
) -> KillOutcome {
|
||||
let all_removed = match child_info.child_type() {
|
||||
) -> KillChildStorageResult {
|
||||
match child_info.child_type() {
|
||||
ChildType::ParentKeyId => sp_io::default_child_storage::storage_kill(
|
||||
child_info.storage_key(),
|
||||
limit
|
||||
),
|
||||
};
|
||||
match all_removed {
|
||||
true => KillOutcome::AllRemoved,
|
||||
false => KillOutcome::SomeRemaining,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user