-
Notifications
You must be signed in to change notification settings - Fork 2.6k
use CountedMap in pallet-bags-list #10179
Changes from 3 commits
37771d1
8df8b8f
6f42e81
8cb4b38
7c218eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ use crate::{ | |
Never, | ||
}; | ||
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; | ||
use sp_arithmetic::traits::Bounded; | ||
use sp_runtime::traits::Saturating; | ||
use sp_std::prelude::*; | ||
|
||
|
@@ -262,9 +263,10 @@ where | |
} | ||
|
||
/// Remove all value of the storage. | ||
pub fn remove_all() { | ||
CounterFor::<Prefix>::set(0u32); | ||
<Self as MapWrapper>::Map::remove_all(None); | ||
pub fn remove_all(maybe_limit: Option<u32>) { | ||
let leftover = Self::count().saturating_sub(maybe_limit.unwrap_or_else(Bounded::max_value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only logical change here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not correct, the documentation of remove_all for the storage map is indeed missing, but underneath it calls sp-io::storage::clear_prefix Thus we cannot keep an accurate leftover here, we need to change sp-io::storage::clear_prefix to return here the number of key deleted in the overlay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kianenigma wat happens nao? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow up is #10231 |
||
CounterFor::<Prefix>::set(leftover); | ||
<Self as MapWrapper>::Map::remove_all(maybe_limit); | ||
} | ||
|
||
/// Iter over all value of the storage. | ||
|
@@ -676,7 +678,7 @@ mod test { | |
assert_eq!(A::count(), 2); | ||
|
||
// Remove all. | ||
A::remove_all(); | ||
A::remove_all(None); | ||
|
||
assert_eq!(A::count(), 0); | ||
assert_eq!(A::initialize_counter(), 0); | ||
|
@@ -907,7 +909,7 @@ mod test { | |
assert_eq!(B::count(), 2); | ||
|
||
// Remove all. | ||
B::remove_all(); | ||
B::remove_all(None); | ||
|
||
assert_eq!(B::count(), 0); | ||
assert_eq!(B::initialize_counter(), 0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this previous code also doesn't seems correct, it is not ensure that
count
items are removed.