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

Commit

Permalink
Some nitpicks 🙈
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed May 25, 2022
1 parent 0338fce commit 73d1fc6
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 93 deletions.
4 changes: 2 additions & 2 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ pub mod tests {
// Note this is the incorrect answer (for now), since we are using v2 of
// `clear_prefix`.
// When we switch to v3, then this will become:
// sp_io::ClearPrefixResult::NoneLeft { db: 0, total: 2 },
sp_io::ClearPrefixResult { maybe_cursor: None, db: 0, total: 0, loops: 0 },
// sp_io::MultiRemovalResults::NoneLeft { db: 0, total: 2 },
sp_io::MultiRemovalResults { maybe_cursor: None, backend: 0, unique: 0, loops: 0 },
));
assert_eq!(DoubleMap::get(&key1, &key2), 0u64);
assert_eq!(DoubleMap::get(&key1, &(key2 + 1)), 0u64);
Expand Down
12 changes: 6 additions & 6 deletions frame/support/src/storage/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// NOTE: could replace unhashed by having only one kind of storage (top trie being the child info
// of null length parent storage key).

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

/// Ensure `key` has no explicit entry in storage.
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/storage/generator/double_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ where
k1: KArg1,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> sp_io::ClearPrefixResult
) -> sp_io::MultiRemovalResults
where
KArg1: EncodeLike<K1>,
{
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/storage/generator/nmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ where
partial_key: KP,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> sp_io::ClearPrefixResult
) -> sp_io::MultiRemovalResults
where
K: HasKeyPrefix<KP>,
{
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/storage/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn clear_storage_prefix(
hash: &[u8],
maybe_limit: Option<u32>,
maybe_cursor: Option<&[u8]>,
) -> sp_io::ClearPrefixResult {
) -> sp_io::MultiRemovalResults {
let mut key = vec![0u8; 32 + hash.len()];
let storage_prefix = storage_prefix(module, item);
key[0..32].copy_from_slice(&storage_prefix);
Expand Down
14 changes: 7 additions & 7 deletions frame/support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
k1: KArg1,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> sp_io::ClearPrefixResult
) -> sp_io::MultiRemovalResults
where
KArg1: ?Sized + EncodeLike<K1>;

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

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

Expand Down Expand Up @@ -1172,8 +1172,8 @@ pub trait StoragePrefixedMap<Value: FullCodec> {

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

Expand Down
10 changes: 5 additions & 5 deletions frame/support/src/storage/types/counted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
Never,
};
use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref};
use sp_io::ClearPrefixResult;
use sp_io::MultiRemovalResults;
use sp_runtime::traits::Saturating;
use sp_std::prelude::*;

Expand Down Expand Up @@ -284,8 +284,8 @@ where

/// Attempt to remove all items from the map.
///
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
/// field is `None`, then no further items remain to be deleted.
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once
/// the resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
///
/// NOTE: After the initial call for any given map, it is important that no further items
/// are inserted into the map. If so, then the map may not be empty when the resultant
Expand All @@ -305,11 +305,11 @@ where
/// passed once (in the initial call) for any given storage map. Subsequent calls
/// operating on the same map should always pass `Some`, and this should be equal to the
/// previous call result's `maybe_cursor` field.
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> ClearPrefixResult {
pub fn clear(limit: u32, maybe_cursor: Option<&[u8]>) -> MultiRemovalResults {
let result = <Self as MapWrapper>::Map::clear(limit, maybe_cursor);
match result.maybe_cursor {
None => CounterFor::<Prefix>::kill(),
Some(_) => CounterFor::<Prefix>::mutate(|x| x.saturating_reduce(result.total)),
Some(_) => CounterFor::<Prefix>::mutate(|x| x.saturating_reduce(result.unique)),
}
result
}
Expand Down
12 changes: 6 additions & 6 deletions frame/support/src/storage/types/double_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ where

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

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

Expand Down
6 changes: 3 additions & 3 deletions frame/support/src/storage/types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ where

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

Expand Down
12 changes: 6 additions & 6 deletions frame/support/src/storage/types/nmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ where

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

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

Expand Down
10 changes: 5 additions & 5 deletions frame/support/src/storage/unhashed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ pub fn kill_prefix(prefix: &[u8], limit: Option<u32>) -> sp_io::KillStorageResul
/// cursor need not be passed in an a `None` may be passed instead. This exception may be useful
/// then making this call solely from a block-hook such as `on_initialize`.
///
/// Returns [`ClearPrefixResult`] to inform about the result. Once the resultant `maybe_cursor`
/// field is `None`, then no further items remain to be deleted.
/// Returns [`MultiRemovalResults`](sp_io::MultiRemovalResults) to inform about the result. Once the
/// resultant `maybe_cursor` field is `None`, then no further items remain to be deleted.
///
/// NOTE: After the initial call for any given child storage, it is important that no keys further
/// keys are inserted. If so, then they may or may not be deleted by subsequent calls.
Expand All @@ -140,17 +140,17 @@ pub fn clear_prefix(
prefix: &[u8],
maybe_limit: Option<u32>,
_maybe_cursor: Option<&[u8]>,
) -> sp_io::ClearPrefixResult {
) -> sp_io::MultiRemovalResults {
// TODO: Once the network has upgraded to include the new host functions, this code can be
// enabled.
// sp_io::storage::clear_prefix(prefix, maybe_limit, maybe_cursor)
use sp_io::{ClearPrefixResult, KillStorageResult::*};
use sp_io::{KillStorageResult::*, MultiRemovalResults};
#[allow(deprecated)]
let (maybe_cursor, i) = match kill_prefix(prefix, maybe_limit) {
AllRemoved(i) => (None, i),
SomeRemaining(i) => (Some(prefix.to_vec()), i),
};
ClearPrefixResult { maybe_cursor, db: i, total: i, loops: i }
MultiRemovalResults { maybe_cursor, backend: i, unique: i, loops: i }
}

/// Get a Vec of bytes from storage.
Expand Down
2 changes: 2 additions & 0 deletions primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub enum Error {
}

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

0 comments on commit 73d1fc6

Please sign in to comment.