Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit e23d4af

Browse files
chemeshawntabrizi
authored andcommitted
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>
1 parent 87e38e4 commit e23d4af

File tree

35 files changed

+310
-237
lines changed

35 files changed

+310
-237
lines changed

client/db/src/bench.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,14 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
373373
}
374374
}
375375

376-
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
376+
fn apply_to_keys_while<F: FnMut(&[u8]) -> bool>(
377377
&self,
378-
child_info: &ChildInfo,
378+
child_info: Option<&ChildInfo>,
379+
prefix: Option<&[u8]>,
379380
f: F,
380381
) {
381382
if let Some(ref state) = *self.state.borrow() {
382-
state.apply_to_child_keys_while(child_info, f)
383+
state.apply_to_keys_while(child_info, prefix, f)
383384
}
384385
}
385386

client/db/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ impl<B: BlockT> StateBackend<HashFor<B>> for RefTrackingState<B> {
205205
self.state.for_key_values_with_prefix(prefix, f)
206206
}
207207

208-
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
208+
fn apply_to_keys_while<F: FnMut(&[u8]) -> bool>(
209209
&self,
210-
child_info: &ChildInfo,
210+
child_info: Option<&ChildInfo>,
211+
prefix: Option<&[u8]>,
211212
f: F,
212213
) {
213-
self.state.apply_to_child_keys_while(child_info, f)
214+
self.state.apply_to_keys_while(child_info, prefix, f)
214215
}
215216

216217
fn for_child_keys_with_prefix<F: FnMut(&[u8])>(

client/db/src/storage_cache.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,13 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Cachin
605605
self.state.exists_child_storage(child_info, key)
606606
}
607607

608-
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
608+
fn apply_to_keys_while<F: FnMut(&[u8]) -> bool>(
609609
&self,
610-
child_info: &ChildInfo,
610+
child_info: Option<&ChildInfo>,
611+
prefix: Option<&[u8]>,
611612
f: F,
612613
) {
613-
self.state.apply_to_child_keys_while(child_info, f)
614+
self.state.apply_to_keys_while(child_info, prefix, f)
614615
}
615616

616617
fn next_storage_key(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {
@@ -787,12 +788,13 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Syncin
787788
self.caching_state().exists_child_storage(child_info, key)
788789
}
789790

790-
fn apply_to_child_keys_while<F: FnMut(&[u8]) -> bool>(
791+
fn apply_to_keys_while<F: FnMut(&[u8]) -> bool>(
791792
&self,
792-
child_info: &ChildInfo,
793+
child_info: Option<&ChildInfo>,
794+
prefix: Option<&[u8]>,
793795
f: F,
794796
) {
795-
self.caching_state().apply_to_child_keys_while(child_info, f)
797+
self.caching_state().apply_to_keys_while(child_info, prefix, f)
796798
}
797799

798800
fn next_storage_key(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error> {

client/executor/runtime-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ sp_core::wasm_export_functions! {
6363
}
6464

6565
fn test_clear_prefix(input: Vec<u8>) -> Vec<u8> {
66-
storage::clear_prefix(&input);
66+
storage::clear_prefix(&input, None);
6767
b"all ok!".to_vec()
6868
}
6969

client/light/src/backend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,15 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
461461
}
462462
}
463463

464-
fn apply_to_child_keys_while<A: FnMut(&[u8]) -> bool>(
464+
fn apply_to_keys_while<A: FnMut(&[u8]) -> bool>(
465465
&self,
466-
child_info: &ChildInfo,
466+
child_info: Option<&ChildInfo>,
467+
prefix: Option<&[u8]>,
467468
action: A,
468469
) {
469470
match *self {
470471
GenesisOrUnavailableState::Genesis(ref state) =>
471-
state.apply_to_child_keys_while(child_info, action),
472+
state.apply_to_keys_while(child_info, prefix, action),
472473
GenesisOrUnavailableState::Unavailable => (),
473474
}
474475
}

frame/contracts/src/storage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_runtime::{
3333
use sp_core::crypto::UncheckedFrom;
3434
use frame_support::{
3535
dispatch::{DispatchError, DispatchResult},
36-
storage::child::{self, KillChildStorageResult, ChildInfo},
36+
storage::child::{self, KillStorageResult, ChildInfo},
3737
traits::Get,
3838
weights::Weight,
3939
};
@@ -331,14 +331,14 @@ where
331331
let removed = queue.swap_remove(0);
332332
match outcome {
333333
// This should not happen as our budget was large enough to remove all keys.
334-
KillChildStorageResult::SomeRemaining(_) => {
334+
KillStorageResult::SomeRemaining(_) => {
335335
log::error!(
336336
target: "runtime::contracts",
337337
"After deletion keys are remaining in this child trie: {:?}",
338338
removed.trie_id,
339339
);
340340
},
341-
KillChildStorageResult::AllRemoved(_) => (),
341+
KillStorageResult::AllRemoved(_) => (),
342342
}
343343
}
344344
remaining_key_budget = remaining_key_budget

frame/elections-phragmen/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn clean<T: Config>() {
142142
<Members<T>>::kill();
143143
<Candidates<T>>::kill();
144144
<RunnersUp<T>>::kill();
145-
<Voting<T>>::remove_all();
145+
<Voting<T>>::remove_all(None);
146146
}
147147

148148
benchmarks! {

frame/im-online/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
809809
// Remove all received heartbeats and number of authored blocks from the
810810
// current session, they have already been processed and won't be needed
811811
// anymore.
812-
ReceivedHeartbeats::<T>::remove_prefix(&T::ValidatorSet::session_index());
813-
AuthoredBlocks::<T>::remove_prefix(&T::ValidatorSet::session_index());
812+
ReceivedHeartbeats::<T>::remove_prefix(&T::ValidatorSet::session_index(), None);
813+
AuthoredBlocks::<T>::remove_prefix(&T::ValidatorSet::session_index(), None);
814814

815815
if offenders.is_empty() {
816816
Self::deposit_event(Event::<T>::AllGood);

frame/society/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ decl_module! {
871871
Founder::<T, I>::kill();
872872
Rules::<T, I>::kill();
873873
Candidates::<T, I>::kill();
874-
SuspendedCandidates::<T, I>::remove_all();
874+
SuspendedCandidates::<T, I>::remove_all(None);
875875
Self::deposit_event(RawEvent::Unfounded(founder));
876876
}
877877

@@ -1402,7 +1402,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
14021402
}).collect::<Vec<_>>();
14031403

14041404
// Clean up all votes.
1405-
<Votes<T, I>>::remove_all();
1405+
<Votes<T, I>>::remove_all(None);
14061406

14071407
// Reward one of the voters who voted the right way.
14081408
if !total_slash.is_zero() {
@@ -1570,7 +1570,7 @@ impl<T: Config<I>, I: Instance> Module<T, I> {
15701570
}
15711571

15721572
// Clean up all votes.
1573-
<DefenderVotes<T, I>>::remove_all();
1573+
<DefenderVotes<T, I>>::remove_all(None);
15741574
}
15751575

15761576
// Avoid challenging if there's only two members since we never challenge the Head or

frame/staking/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,9 +2846,9 @@ impl<T: Config> Pallet<T> {
28462846

28472847
/// Clear all era information for given era.
28482848
fn clear_era_information(era_index: EraIndex) {
2849-
<ErasStakers<T>>::remove_prefix(era_index);
2850-
<ErasStakersClipped<T>>::remove_prefix(era_index);
2851-
<ErasValidatorPrefs<T>>::remove_prefix(era_index);
2849+
<ErasStakers<T>>::remove_prefix(era_index, None);
2850+
<ErasStakersClipped<T>>::remove_prefix(era_index, None);
2851+
<ErasValidatorPrefs<T>>::remove_prefix(era_index, None);
28522852
<ErasValidatorReward<T>>::remove(era_index);
28532853
<ErasRewardPoints<T>>::remove(era_index);
28542854
<ErasTotalStake<T>>::remove(era_index);

0 commit comments

Comments
 (0)