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

Commit 73d1fc6

Browse files
committed
Some nitpicks 🙈
1 parent 0338fce commit 73d1fc6

File tree

16 files changed

+76
-93
lines changed

16 files changed

+76
-93
lines changed

frame/support/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ pub mod tests {
11011101
// Note this is the incorrect answer (for now), since we are using v2 of
11021102
// `clear_prefix`.
11031103
// When we switch to v3, then this will become:
1104-
// sp_io::ClearPrefixResult::NoneLeft { db: 0, total: 2 },
1105-
sp_io::ClearPrefixResult { maybe_cursor: None, db: 0, total: 0, loops: 0 },
1104+
// sp_io::MultiRemovalResults::NoneLeft { db: 0, total: 2 },
1105+
sp_io::MultiRemovalResults { maybe_cursor: None, backend: 0, unique: 0, loops: 0 },
11061106
));
11071107
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
11081108
assert_eq!(DoubleMap::get(&key1, &(key2 + 1)), 0u64);

frame/support/src/storage/child.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// NOTE: could replace unhashed by having only one kind of storage (top trie being the child info
2222
// of null length parent storage key).
2323

24-
pub use crate::sp_io::{ClearPrefixResult, KillStorageResult};
24+
pub use crate::sp_io::{KillStorageResult, MultiRemovalResults};
2525
use crate::sp_std::prelude::*;
2626
use codec::{Codec, Decode, Encode};
2727
pub use sp_core::storage::{ChildInfo, ChildType, StateVersion};
@@ -166,8 +166,8 @@ pub fn kill_storage(child_info: &ChildInfo, limit: Option<u32>) -> KillStorageRe
166166
/// cursor need not be passed in an a `None` may be passed instead. This exception may be useful
167167
/// then making this call solely from a block-hook such as `on_initialize`.
168168
///
169-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
170-
/// field is `None`, then no further items remain to be deleted.
169+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once the
170+
/// resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
171171
///
172172
/// NOTE: After the initial call for any given child storage, it is important that no keys further
173173
/// keys are inserted. If so, then they may or may not be deleted by subsequent calls.
@@ -180,7 +180,7 @@ pub fn clear_storage(
180180
child_info: &ChildInfo,
181181
maybe_limit: Option<u32>,
182182
_maybe_cursor: Option<&[u8]>,
183-
) -> ClearPrefixResult {
183+
) -> MultiRemovalResults {
184184
// TODO: Once the network has upgraded to include the new host functions, this code can be
185185
// enabled.
186186
// sp_io::default_child_storage::storage_kill(prefix, maybe_limit, maybe_cursor)
@@ -189,11 +189,11 @@ pub fn clear_storage(
189189
sp_io::default_child_storage::storage_kill(child_info.storage_key(), maybe_limit),
190190
};
191191
use sp_io::KillStorageResult::*;
192-
let (maybe_cursor, db) = match r {
192+
let (maybe_cursor, backend) = match r {
193193
AllRemoved(db) => (None, db),
194194
SomeRemaining(db) => (Some(child_info.storage_key().to_vec()), db),
195195
};
196-
ClearPrefixResult { maybe_cursor, db, total: db, loops: db }
196+
MultiRemovalResults { maybe_cursor, backend, unique: backend, loops: backend }
197197
}
198198

199199
/// Ensure `key` has no explicit entry in storage.

frame/support/src/storage/generator/double_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ where
214214
k1: KArg1,
215215
limit: u32,
216216
maybe_cursor: Option<&[u8]>,
217-
) -> sp_io::ClearPrefixResult
217+
) -> sp_io::MultiRemovalResults
218218
where
219219
KArg1: EncodeLike<K1>,
220220
{

frame/support/src/storage/generator/nmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ where
190190
partial_key: KP,
191191
limit: u32,
192192
maybe_cursor: Option<&[u8]>,
193-
) -> sp_io::ClearPrefixResult
193+
) -> sp_io::MultiRemovalResults
194194
where
195195
K: HasKeyPrefix<KP>,
196196
{

frame/support/src/storage/migration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub fn clear_storage_prefix(
287287
hash: &[u8],
288288
maybe_limit: Option<u32>,
289289
maybe_cursor: Option<&[u8]>,
290-
) -> sp_io::ClearPrefixResult {
290+
) -> sp_io::MultiRemovalResults {
291291
let mut key = vec![0u8; 32 + hash.len()];
292292
let storage_prefix = storage_prefix(module, item);
293293
key[0..32].copy_from_slice(&storage_prefix);

frame/support/src/storage/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
538538
k1: KArg1,
539539
limit: u32,
540540
maybe_cursor: Option<&[u8]>,
541-
) -> sp_io::ClearPrefixResult
541+
) -> sp_io::MultiRemovalResults
542542
where
543543
KArg1: ?Sized + EncodeLike<K1>;
544544

@@ -686,8 +686,8 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
686686

687687
/// Attempt to remove items from the map matching a `partial_key` prefix.
688688
///
689-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
690-
/// field is `None`, then no further items remain to be deleted.
689+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
690+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
691691
///
692692
/// NOTE: After the initial call for any given map, it is important that no further items
693693
/// are inserted into the map which match the `partial key`. If so, then the map may not be
@@ -711,7 +711,7 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
711711
partial_key: KP,
712712
limit: u32,
713713
maybe_cursor: Option<&[u8]>,
714-
) -> sp_io::ClearPrefixResult
714+
) -> sp_io::MultiRemovalResults
715715
where
716716
K: HasKeyPrefix<KP>;
717717

@@ -1172,8 +1172,8 @@ pub trait StoragePrefixedMap<Value: FullCodec> {
11721172

11731173
/// Attempt to remove all items from the map.
11741174
///
1175-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
1176-
/// field is `None`, then no further items remain to be deleted.
1175+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
1176+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
11771177
///
11781178
/// NOTE: After the initial call for any given map, it is important that no further items
11791179
/// are inserted into the map. If so, then the map may not be empty when the resultant
@@ -1193,7 +1193,7 @@ pub trait StoragePrefixedMap<Value: FullCodec> {
11931193
/// passed once (in the initial call) for any given storage map. Subsequent calls
11941194
/// operating on the same map should always pass `Some`, and this should be equal to the
11951195
/// previous call result's `maybe_cursor` field.
1196-
fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::ClearPrefixResult {
1196+
fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::MultiRemovalResults {
11971197
unhashed::clear_prefix(&Self::final_prefix(), Some(limit), maybe_cursor)
11981198
}
11991199

frame/support/src/storage/types/counted_map.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
Never,
3232
};
3333
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref};
34-
use sp_io::ClearPrefixResult;
34+
use sp_io::MultiRemovalResults;
3535
use sp_runtime::traits::Saturating;
3636
use sp_std::prelude::*;
3737

@@ -284,8 +284,8 @@ where
284284

285285
/// Attempt to remove all items from the map.
286286
///
287-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
288-
/// field is `None`, then no further items remain to be deleted.
287+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
288+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
289289
///
290290
/// NOTE: After the initial call for any given map, it is important that no further items
291291
/// are inserted into the map. If so, then the map may not be empty when the resultant
@@ -305,11 +305,11 @@ where
305305
/// passed once (in the initial call) for any given storage map. Subsequent calls
306306
/// operating on the same map should always pass `Some`, and this should be equal to the
307307
/// previous call result's `maybe_cursor` field.
308-
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> ClearPrefixResult {
308+
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> MultiRemovalResults {
309309
let result = <Self as MapWrapper>::Map::clear(limit, maybe_cursor);
310310
match result.maybe_cursor {
311311
None => CounterFor::<Prefix>::kill(),
312-
Some(_) => CounterFor::<Prefix>::mutate(|x| x.saturating_reduce(result.total)),
312+
Some(_) => CounterFor::<Prefix>::mutate(|x| x.saturating_reduce(result.unique)),
313313
}
314314
result
315315
}

frame/support/src/storage/types/double_map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ where
240240

241241
/// Attempt to remove items from the map matching a `first_key` prefix.
242242
///
243-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
244-
/// field is `None`, then no further items remain to be deleted.
243+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
244+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
245245
///
246246
/// NOTE: After the initial call for any given map, it is important that no further items
247247
/// are inserted into the map which match the `first_key`. If so, then the map may not be
@@ -265,7 +265,7 @@ where
265265
first_key: KArg1,
266266
limit: u32,
267267
maybe_cursor: Option<&[u8]>,
268-
) -> sp_io::ClearPrefixResult
268+
) -> sp_io::MultiRemovalResults
269269
where
270270
KArg1: ?Sized + EncodeLike<Key1>,
271271
{
@@ -407,8 +407,8 @@ where
407407

408408
/// Attempt to remove all items from the map.
409409
///
410-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
411-
/// field is `None`, then no further items remain to be deleted.
410+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
411+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
412412
///
413413
/// NOTE: After the initial call for any given map, it is important that no further items
414414
/// are inserted into the map. If so, then the map may not be empty when the resultant
@@ -428,7 +428,7 @@ where
428428
/// passed once (in the initial call) for any given storage map. Subsequent calls
429429
/// operating on the same map should always pass `Some`, and this should be equal to the
430430
/// previous call result's `maybe_cursor` field.
431-
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::ClearPrefixResult {
431+
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::MultiRemovalResults {
432432
<Self as crate::storage::StoragePrefixedMap<Value>>::clear(limit, maybe_cursor)
433433
}
434434

frame/support/src/storage/types/map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ where
255255

256256
/// Attempt to remove all items from the map.
257257
///
258-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
259-
/// field is `None`, then no further items remain to be deleted.
258+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
259+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
260260
///
261261
/// NOTE: After the initial call for any given map, it is important that no further items
262262
/// are inserted into the map. If so, then the map may not be empty when the resultant
@@ -276,7 +276,7 @@ where
276276
/// passed once (in the initial call) for any given storage map. Subsequent calls
277277
/// operating on the same map should always pass `Some`, and this should be equal to the
278278
/// previous call result's `maybe_cursor` field.
279-
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::ClearPrefixResult {
279+
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::MultiRemovalResults {
280280
<Self as crate::storage::StoragePrefixedMap<Value>>::clear(limit, maybe_cursor)
281281
}
282282

frame/support/src/storage/types/nmap.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ where
196196

197197
/// Attempt to remove items from the map matching a `partial_key` prefix.
198198
///
199-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
200-
/// field is `None`, then no further items remain to be deleted.
199+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
200+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
201201
///
202202
/// NOTE: After the initial call for any given map, it is important that no further items
203203
/// are inserted into the map which match the `partial key`. If so, then the map may not be
@@ -221,7 +221,7 @@ where
221221
partial_key: KP,
222222
limit: u32,
223223
maybe_cursor: Option<&[u8]>,
224-
) -> sp_io::ClearPrefixResult
224+
) -> sp_io::MultiRemovalResults
225225
where
226226
Key: HasKeyPrefix<KP>,
227227
{
@@ -347,8 +347,8 @@ where
347347

348348
/// Attempt to remove all items from the map.
349349
///
350-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
351-
/// field is `None`, then no further items remain to be deleted.
350+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
351+
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
352352
///
353353
/// NOTE: After the initial call for any given map, it is important that no further items
354354
/// are inserted into the map. If so, then the map may not be empty when the resultant
@@ -368,7 +368,7 @@ where
368368
/// passed once (in the initial call) for any given storage map. Subsequent calls
369369
/// operating on the same map should always pass `Some`, and this should be equal to the
370370
/// previous call result's `maybe_cursor` field.
371-
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::ClearPrefixResult {
371+
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> sp_io::MultiRemovalResults {
372372
<Self as crate::storage::StoragePrefixedMap<Value>>::clear(limit, maybe_cursor)
373373
}
374374

frame/support/src/storage/unhashed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ pub fn kill_prefix(prefix: &[u8], limit: Option<u32>) -> sp_io::KillStorageResul
126126
/// cursor need not be passed in an a `None` may be passed instead. This exception may be useful
127127
/// then making this call solely from a block-hook such as `on_initialize`.
128128
///
129-
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
130-
/// field is `None`, then no further items remain to be deleted.
129+
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once the
130+
/// resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
131131
///
132132
/// NOTE: After the initial call for any given child storage, it is important that no keys further
133133
/// keys are inserted. If so, then they may or may not be deleted by subsequent calls.
@@ -140,17 +140,17 @@ pub fn clear_prefix(
140140
prefix: &[u8],
141141
maybe_limit: Option<u32>,
142142
_maybe_cursor: Option<&[u8]>,
143-
) -> sp_io::ClearPrefixResult {
143+
) -> sp_io::MultiRemovalResults {
144144
// TODO: Once the network has upgraded to include the new host functions, this code can be
145145
// enabled.
146146
// sp_io::storage::clear_prefix(prefix, maybe_limit, maybe_cursor)
147-
use sp_io::{ClearPrefixResult, KillStorageResult::*};
147+
use sp_io::{KillStorageResult::*, MultiRemovalResults};
148148
#[allow(deprecated)]
149149
let (maybe_cursor, i) = match kill_prefix(prefix, maybe_limit) {
150150
AllRemoved(i) => (None, i),
151151
SomeRemaining(i) => (Some(prefix.to_vec()), i),
152152
};
153-
ClearPrefixResult { maybe_cursor, db: i, total: i, loops: i }
153+
MultiRemovalResults { maybe_cursor, backend: i, unique: i, loops: i }
154154
}
155155

156156
/// Get a Vec of bytes from storage.

primitives/externalities/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub enum Error {
5353
}
5454

5555
/// Results concerning an operation to remove many keys.
56+
#[derive(codec::Encode, codec::Decode)]
57+
#[must_use]
5658
pub struct MultiRemovalResults {
5759
/// A continuation cursor which, if `Some` must be provided to the subsequent removal call.
5860
/// If `None` then all removals are complete and no further calls are needed.

0 commit comments

Comments
 (0)