From c04769f40f42e918365e883b84e5e69c8e11b850 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 7 Jan 2022 21:58:23 +0200 Subject: [PATCH 01/50] add initial CountedDoubleMap implementation --- client/offchain/src/api/http.rs | 10 +- .../src/storage/types/counted_double_map.rs | 413 ++++++++++++++++++ frame/support/src/storage/types/mod.rs | 1 + 3 files changed, 420 insertions(+), 4 deletions(-) create mode 100644 frame/support/src/storage/types/counted_double_map.rs diff --git a/client/offchain/src/api/http.rs b/client/offchain/src/api/http.rs index bc8f81f25a643..2a7514116cb5d 100644 --- a/client/offchain/src/api/http.rs +++ b/client/offchain/src/api/http.rs @@ -432,8 +432,9 @@ impl HttpApi { ); }, None => {}, // can happen if we detected an IO error when sending the body - _ => - tracing::error!(target: "offchain-worker::http", "State mismatch between the API and worker"), + _ => { + tracing::error!(target: "offchain-worker::http", "State mismatch between the API and worker") + }, } }, @@ -443,8 +444,9 @@ impl HttpApi { self.requests.insert(id, HttpApiRequest::Fail(error)); }, None => {}, // can happen if we detected an IO error when sending the body - _ => - tracing::error!(target: "offchain-worker::http", "State mismatch between the API and worker"), + _ => { + tracing::error!(target: "offchain-worker::http", "State mismatch between the API and worker") + }, }, None => { diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs new file mode 100644 index 0000000000000..1cf3fdc12257d --- /dev/null +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -0,0 +1,413 @@ +use crate::{ + storage::{ + types::{OptionQuery, QueryKindTrait, StorageDoubleMap, StorageValue, ValueQuery}, + StorageAppend, StorageDecodeLength, StorageTryAppend, + }, + traits::{Get, GetDefault, StorageInstance}, + Never, +}; +use codec::{Decode, Encode, EncodeLike, FullCodec, Ref}; +use sp_runtime::traits::Saturating; + +pub struct CountedStorageDoubleMap< + Prefix, + Hasher1, + Key1, + Hasher2, + Key2, + Value, + QueryKind = OptionQuery, + OnEmpty = GetDefault, + MaxValues = GetDefault, +>( + core::marker::PhantomData<( + Prefix, + Hasher1, + Key1, + Hasher2, + Key2, + Value, + QueryKind, + OnEmpty, + MaxValues, + )>, +); + +/// The requirement for an instance of [`CountedStorageDoubleMap`]. +pub trait CountedStorageDoubleMapInstance: StorageInstance { + /// The prefix to use for the counter storage value. + type CounterPrefix: StorageInstance; +} + +// Private helper trait to access map from counted storage double map +trait MapWrapper { + type Map; +} + +impl MapWrapper + for CountedStorageDoubleMap +{ + type Map = StorageDoubleMap; +} + +type CounterFor

= + StorageValue<

::CounterPrefix, u32, ValueQuery>; + +/// On removal logic for updating counter while draining upon some prefix with +/// [`crate::storage::PrefixIterator`]. +pub struct OnRemovalCounterUpdate(core::marker::PhantomData); + +impl crate::storage::PrefixIteratorOnRemoval + for OnRemovalCounterUpdate +{ + fn on_removal(_key: &[u8], _value: &[u8]) { + CounterFor::::mutate(|value| value.saturating_dec()); + } +} + +impl + CountedStorageDoubleMap +where + Prefix: CountedStorageDoubleMapInstance, + Hasher1: crate::hash::StorageHasher, + Key1: FullCodec, + Hasher2: crate::hash::StorageHasher, + Key2: FullCodec, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + /// The key used to store the counter of the map. + pub fn counter_storage_final_key() -> [u8; 32] { + CounterFor::::hashed_key() + } + + /// The prefix used to generate the key of the map. + pub fn map_storage_final_prefix() -> Vec { + use crate::storage::generator::StorageDoubleMap; + ::Map::prefix_hash() + } + + /// Get the storage key used to fetch a value corresponding to a specific key. + pub fn hashed_key_for(k1: KArg1, k2: KArg2) -> Vec + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + ::Map::hashed_key_for(k1, k2) + } + + /// Does the value (explicitly) exist in storage? + pub fn contains_key(k1: KArg1, k2: KArg2) -> bool + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + ::Map::contains_key(k1, k2) + } + + /// Load the value associated with the given key from the double map. + pub fn get(k1: KArg1, k2: KArg2) -> QueryKind::Query + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + ::Map::get(k1, k2) + } + + /// Try to get the value for the given key from the double map. + /// + /// Returns `Ok` if it exists, `Err` if not. + pub fn try_get(k1: KArg1, k2: KArg2) -> Result + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + ::Map::try_get(k1, k2) + } + + /// Take a value from storage, removing it afterwards. + pub fn take(k1: KArg1, k2: KArg2) -> QueryKind::Query + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + ::Map::take(k1, k2) + } + + /// Swap the values of two key-pairs. + pub fn swap( + x_k1: XKArg1, + x_k2: XKArg2, + y_k1: YKArg1, + y_k2: YKArg2, + ) where + XKArg1: EncodeLike, + XKArg2: EncodeLike, + YKArg1: EncodeLike, + YKArg2: EncodeLike, + { + ::Map::swap(x_k1, x_k2, y_k1, y_k2) + } + + /// Store a value to be associated with the given keys from the double map. + pub fn insert(k1: KArg1, k2: KArg2, val: VArg) + where + KArg1: EncodeLike, + KArg2: EncodeLike, + VArg: EncodeLike, + { + if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { + CounterFor::::mutate(|value| value.saturating_inc()); + } + ::Map::insert(k1, k2, val) + } + + /// Remove the value under the given keys. + pub fn remove(k1: KArg1, k2: KArg2) + where + KArg1: EncodeLike, + KArg2: EncodeLike, + { + if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { + CounterFor::::mutate(|value| value.saturating_dec()); + } + ::Map::remove(k1, k2) + } + + /// Remove all values under the first key. + pub fn remove_prefix(k1: KArg1) + where + KArg1: ?Sized + EncodeLike, + { + // TODO: implement + // ::Map::remove_prefix(k1, limit) + } + + /// Iterate over values that share the first key. + pub fn iter_prefix_values( + k1: KArg1, + ) -> crate::storage::PrefixIterator> + where + KArg1: ?Sized + EncodeLike, + { + let map_iterator = ::Map::iter_prefix_values(k1); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Mutate the value under the given keys. + pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut QueryKind::Query) -> R, + { + Self::try_mutate(k1, k2, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") + } + + /// Mutate the value under the given keys when the closure returns `Ok`. + pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut QueryKind::Query) -> Result, + { + // TODO: implement + // Self::try_mutate_exists(k1, k2, |option_value_ref| { + // let option_value = core::mem::replace(option_value_ref, None); + // let mut query = ::Map::from_optional_value_to_query(option_value); + // let res = f(&mut query); + // let option_value = ::Map::from_query_to_optional_value(query); + // let _ = core::mem::replace(option_value_ref, option_value); + // res + // }) + } + + /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. + pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut Option) -> R, + { + Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") + } + + /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut Option) -> Result, + { + ::Map::try_mutate_exists(k1, k2, |option_value| { + let existed = option_value.is_some(); + let res = f(option_value); + let exist = option_value.is_some(); + + if res.is_ok() { + if existed && !exist { + // Value was deleted + CounterFor::::mutate(|value| value.saturating_dec()); + } else if !existed && exist { + // Value was added + CounterFor::::mutate(|value| value.saturating_inc()); + } + } + res + }) + } + + /// Append the given item to the value in the storage. + /// + /// `Value` is required to implement [`StorageAppend`]. + /// + /// # Warning + /// + /// If the storage item is not encoded properly, the storage will be overwritten + /// and set to `[item]`. Any default value set for the storage item will be ignored + /// on overwrite. + pub fn append(k1: KArg1, k2: KArg2, item: EncodeLikeItem) + where + KArg1: EncodeLike, + KArg2: EncodeLike, + Item: Encode, + EncodeLikeItem: EncodeLike, + Value: StorageAppend, + { + if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { + CounterFor::::mutate(|value| value.saturating_inc()); + } + ::Map::append(k1, k2, item) + } + + /// Read the length of the storage value without decoding the entire value under the + /// given `key1` and `key2`. + /// + /// `Value` is required to implement [`StorageDecodeLength`]. + /// + /// If the value does not exists or it fails to decode the length, `None` is returned. + /// Otherwise `Some(len)` is returned. + /// + /// # Warning + /// + /// `None` does not mean that `get()` does not return a value. The default value is completly + /// ignored by this function. + pub fn decode_len(key1: KArg1, key2: KArg2) -> Option + where + KArg1: EncodeLike, + KArg2: EncodeLike, + Value: StorageDecodeLength, + { + ::Map::decode_len(key1, key2) + } + + /// Migrate an item with the given `key1` and `key2` from defunct `OldHasher1` and + /// `OldHasher2` to the current hashers. + /// + /// If the key doesn't exist, then it's a no-op. If it does, then it returns its value. + pub fn migrate_keys< + OldHasher1: crate::StorageHasher, + OldHasher2: crate::StorageHasher, + KeyArg1: EncodeLike, + KeyArg2: EncodeLike, + >( + key1: KeyArg1, + key2: KeyArg2, + ) -> Option { + ::Map::migrate_keys::(key1, key2) + } + + /// Remove all value of the storage. + pub fn remove_all() { + // NOTE: it is not possible to remove up to some limit because + // `sp_io::storage::clear_prefix` and `StorageMap::remove_all` don't give the number of + // value removed from the overlay. + CounterFor::::set(0u32); + ::Map::remove_all(None); + } + + /// Iter over all value of the storage. + /// + /// NOTE: If a value failed to decode because storage is corrupted then it is skipped. + pub fn iter_values() -> crate::storage::PrefixIterator> { + let map_iterator = ::Map::iter_values(); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Translate the values of all elements by a function `f`, in the map in no particular order. + /// By returning `None` from `f` for an element, you'll remove it from the map. + /// + /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. + /// + /// # Warning + /// + /// This function must be used with care, before being updated the storage still contains the + /// old type, thus other calls (such as `get`) will fail at decoding it. + /// + /// # Usage + /// + /// This would typically be called inside the module implementation of on_runtime_upgrade. + pub fn translate_values Option>(f: F) { + ::Map::translate_values(|old_value| { + let res = f(old_value); + if res.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + res + }) + } + + /// Try and append the given item to the value in the storage. + /// + /// Is only available if `Value` of the storage implements [`StorageTryAppend`]. + pub fn try_append( + key1: KArg1, + key2: KArg2, + item: EncodeLikeItem, + ) -> Result<(), ()> + where + KArg1: EncodeLike + Clone, + KArg2: EncodeLike + Clone, + Item: Encode, + EncodeLikeItem: EncodeLike, + Value: StorageTryAppend, + { + // TODO: implement + // >::try_append( + // key1, key2, item, + // ) + } + + /// Initialize the counter with the actual number of items in the map. + /// + /// This function iterates through all the items in the map and sets the counter. This operation + /// can be very heavy, so use with caution. + /// + /// Returns the number of items in the map which is used to set the counter. + pub fn initialize_counter() -> u32 { + let count = Self::iter_values().count() as u32; + CounterFor::::set(count); + count + } + + /// Return the count. + pub fn count() -> u32 { + CounterFor::::get() + } +} diff --git a/frame/support/src/storage/types/mod.rs b/frame/support/src/storage/types/mod.rs index 0706e9fb377e2..17d7f2b81c8d5 100644 --- a/frame/support/src/storage/types/mod.rs +++ b/frame/support/src/storage/types/mod.rs @@ -22,6 +22,7 @@ use crate::metadata::{StorageEntryMetadata, StorageEntryModifier}; use codec::FullCodec; use sp_std::prelude::*; +mod counted_double_map; mod counted_map; mod double_map; mod key; From da34fae3683d77cb08c568d062ee6d19099d0533 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jan 2022 10:35:47 +0200 Subject: [PATCH 02/50] extend CountedDoubleMap functionality --- .../src/storage/types/counted_double_map.rs | 341 +++++++++++++----- 1 file changed, 256 insertions(+), 85 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 1cf3fdc12257d..7c124887ecea3 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -176,14 +176,14 @@ where ::Map::remove(k1, k2) } + // TODO: implement /// Remove all values under the first key. - pub fn remove_prefix(k1: KArg1) - where - KArg1: ?Sized + EncodeLike, - { - // TODO: implement - // ::Map::remove_prefix(k1, limit) - } + // pub fn remove_prefix(k1: KArg1) + // where + // KArg1: ?Sized + EncodeLike, + // { + // ::Map::remove_prefix(k1, limit) + // } /// Iterate over values that share the first key. pub fn iter_prefix_values( @@ -202,70 +202,73 @@ where } } + // TODO: implement /// Mutate the value under the given keys. - pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut QueryKind::Query) -> R, - { - Self::try_mutate(k1, k2, |v| Ok::(f(v))) - .expect("`Never` can not be constructed; qed") - } - + // pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R + // where + // KArg1: EncodeLike, + // KArg2: EncodeLike, + // F: FnOnce(&mut QueryKind::Query) -> R, + // { + // Self::try_mutate(k1, k2, |v| Ok::(f(v))) + // .expect("`Never` can not be constructed; qed") + // } + + // TODO: implement /// Mutate the value under the given keys when the closure returns `Ok`. - pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut QueryKind::Query) -> Result, - { - // TODO: implement - // Self::try_mutate_exists(k1, k2, |option_value_ref| { - // let option_value = core::mem::replace(option_value_ref, None); - // let mut query = ::Map::from_optional_value_to_query(option_value); - // let res = f(&mut query); - // let option_value = ::Map::from_query_to_optional_value(query); - // let _ = core::mem::replace(option_value_ref, option_value); - // res - // }) - } - + // pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result + // where + // KArg1: EncodeLike, + // KArg2: EncodeLike, + // F: FnOnce(&mut QueryKind::Query) -> Result, + // { + // Self::try_mutate_exists(k1, k2, |option_value_ref| { + // let option_value = core::mem::replace(option_value_ref, None); + // let mut query = ::Map::from_optional_value_to_query(option_value); + // let res = f(&mut query); + // let option_value = ::Map::from_query_to_optional_value(query); + // let _ = core::mem::replace(option_value_ref, option_value); + // res + // }) + // } + + // TODO: implement /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. - pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut Option) -> R, - { - Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) - .expect("`Never` can not be constructed; qed") - } - + // pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R + // where + // KArg1: EncodeLike, + // KArg2: EncodeLike, + // F: FnOnce(&mut Option) -> R, + // { + // Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) + // .expect("`Never` can not be constructed; qed") + // } + + // TODO: implement /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut Option) -> Result, - { - ::Map::try_mutate_exists(k1, k2, |option_value| { - let existed = option_value.is_some(); - let res = f(option_value); - let exist = option_value.is_some(); - - if res.is_ok() { - if existed && !exist { - // Value was deleted - CounterFor::::mutate(|value| value.saturating_dec()); - } else if !existed && exist { - // Value was added - CounterFor::::mutate(|value| value.saturating_inc()); - } - } - res - }) - } + // pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result + // where + // KArg1: EncodeLike, + // KArg2: EncodeLike, + // F: FnOnce(&mut Option) -> Result, + // { + // ::Map::try_mutate_exists(k1, k2, |option_value| { + // let existed = option_value.is_some(); + // let res = f(option_value); + // let exist = option_value.is_some(); + + // if res.is_ok() { + // if existed && !exist { + // // Value was deleted + // CounterFor::::mutate(|value| value.saturating_dec()); + // } else if !existed && exist { + // // Value was added + // CounterFor::::mutate(|value| value.saturating_inc()); + // } + // } + // res + // }) + // } /// Append the given item to the value in the storage. /// @@ -363,7 +366,7 @@ where /// # Usage /// /// This would typically be called inside the module implementation of on_runtime_upgrade. - pub fn translate_values Option>(f: F) { + pub fn translate_values Option>(mut f: F) { ::Map::translate_values(|old_value| { let res = f(old_value); if res.is_none() { @@ -373,26 +376,26 @@ where }) } + // TODO: implement /// Try and append the given item to the value in the storage. /// /// Is only available if `Value` of the storage implements [`StorageTryAppend`]. - pub fn try_append( - key1: KArg1, - key2: KArg2, - item: EncodeLikeItem, - ) -> Result<(), ()> - where - KArg1: EncodeLike + Clone, - KArg2: EncodeLike + Clone, - Item: Encode, - EncodeLikeItem: EncodeLike, - Value: StorageTryAppend, - { - // TODO: implement - // >::try_append( - // key1, key2, item, - // ) - } + // pub fn try_append( + // key1: KArg1, + // key2: KArg2, + // item: EncodeLikeItem, + // ) -> Result<(), ()> + // where + // KArg1: EncodeLike + Clone, + // KArg2: EncodeLike + Clone, + // Item: Encode, + // EncodeLikeItem: EncodeLike, + // Value: StorageTryAppend, + // { + // >::try_append( + // key1, key2, item, + // ) + // } /// Initialize the counter with the actual number of items in the map. /// @@ -411,3 +414,171 @@ where CounterFor::::get() } } + +impl + CountedStorageDoubleMap +where + Prefix: CountedStorageDoubleMapInstance, + Hasher1: crate::hash::StorageHasher + crate::ReversibleStorageHasher, + Key1: FullCodec, + Hasher2: crate::hash::StorageHasher + crate::ReversibleStorageHasher, + Key2: FullCodec, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + /// Enumerate all elements in the map with first key `k1` in no particular order. + /// + /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get + /// undefined results. + pub fn iter_prefix( + k1: impl EncodeLike, + ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::iter_prefix(k1); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Enumerate all elements in the map with first key `k1` after a specified `starting_raw_key` + /// in no particular order. + /// + /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get + /// undefined results. + pub fn iter_prefix_from( + k1: impl EncodeLike, + starting_raw_key: Vec, + ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::iter_prefix_from(k1, starting_raw_key); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Enumerate all second keys `k2` in the map with the same first key `k1` in no particular + /// order. + /// + /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get + /// undefined results. + pub fn iter_key_prefix(k1: impl EncodeLike) -> crate::storage::KeyPrefixIterator { + ::Map::iter_key_prefix(k1) + } + + /// Enumerate all second keys `k2` in the map with the same first key `k1` after a specified + /// `starting_raw_key` in no particular order. + /// + /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get + /// undefined results. + pub fn iter_key_prefix_from( + k1: impl EncodeLike, + starting_raw_key: Vec, + ) -> crate::storage::KeyPrefixIterator { + ::Map::iter_key_prefix_from(k1, starting_raw_key) + } + + /// Remove all elements from the map with first key `k1` and iterate through them in no + /// particular order. + /// + /// If you add elements with first key `k1` to the map while doing this, you'll get undefined + /// results. + pub fn drain_prefix( + k1: impl EncodeLike, + ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::drain_prefix(k1); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Enumerate all elements in the map in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter( + ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::iter(); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Enumerate all elements in the map after a specified `starting_raw_key` in no particular + /// order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_from( + starting_raw_key: Vec, + ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::iter_from(starting_raw_key); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Enumerate all keys `k1` and `k2` in the map in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_keys() -> crate::storage::KeyPrefixIterator<(Key1, Key2)> { + ::Map::iter_keys() + } + + /// Enumerate all keys `k1` and `k2` in the map after a specified `starting_raw_key` in no + /// particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_keys_from( + starting_raw_key: Vec, + ) -> crate::storage::KeyPrefixIterator<(Key1, Key2)> { + ::Map::iter_keys_from(starting_raw_key) + } + + /// Remove all elements from the map and iterate through them in no particular order. + /// + /// If you add elements to the map while doing this, you'll get undefined results. + pub fn drain( + ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { + let map_iterator = ::Map::drain(); + crate::storage::PrefixIterator { + prefix: map_iterator.prefix, + previous_key: map_iterator.previous_key, + drain: map_iterator.drain, + closure: map_iterator.closure, + phantom: Default::default(), + } + } + + /// Translate the values of all elements by a function `f`, in the map in no particular order. + /// + /// By returning `None` from `f` for an element, you'll remove it from the map. + /// + /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. + pub fn translate Option>(mut f: F) { + ::Map::translate(|k1, k2, old_value| { + let res = f(k1, k2, old_value); + if res.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + res + }) + } +} From 59f14447412ded14928567c51c9533027b5e386e Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jan 2022 12:06:04 +0200 Subject: [PATCH 03/50] add some traits implementation for CountedStorageDoubleMap --- .../src/storage/types/counted_double_map.rs | 101 +++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 7c124887ecea3..283f671595736 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -1,12 +1,18 @@ use crate::{ + metadata::StorageEntryMetadata, storage::{ - types::{OptionQuery, QueryKindTrait, StorageDoubleMap, StorageValue, ValueQuery}, + types::{ + OptionQuery, QueryKindTrait, StorageDoubleMap, StorageEntryMetadataBuilder, + StorageValue, ValueQuery, + }, StorageAppend, StorageDecodeLength, StorageTryAppend, }, - traits::{Get, GetDefault, StorageInstance}, + traits::{ + Get, GetDefault, PartialStorageInfoTrait, StorageInfo, StorageInfoTrait, StorageInstance, + }, Never, }; -use codec::{Decode, Encode, EncodeLike, FullCodec, Ref}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; use sp_runtime::traits::Saturating; pub struct CountedStorageDoubleMap< @@ -582,3 +588,92 @@ where }) } } + +impl + StorageEntryMetadataBuilder + for CountedStorageDoubleMap< + Prefix, + Hasher1, + Key1, + Hasher2, + Key2, + Value, + QueryKind, + OnEmpty, + MaxValues, + > where + Prefix: CountedStorageDoubleMapInstance, + Hasher1: crate::hash::StorageHasher, + Hasher2: crate::hash::StorageHasher, + Key1: FullCodec + scale_info::StaticTypeInfo, + Key2: FullCodec + scale_info::StaticTypeInfo, + Value: FullCodec + scale_info::StaticTypeInfo, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn build_metadata(docs: Vec<&'static str>, entries: &mut Vec) { + ::Map::build_metadata(docs, entries); + CounterFor::::build_metadata( + vec![&"Counter for the related counted storage map"], + entries, + ); + } +} + +impl StorageInfoTrait + for CountedStorageDoubleMap< + Prefix, + Hasher1, + Key1, + Hasher2, + Key2, + Value, + QueryKind, + OnEmpty, + MaxValues, + > where + Prefix: CountedStorageDoubleMapInstance, + Hasher1: crate::hash::StorageHasher, + Hasher2: crate::hash::StorageHasher, + Key1: FullCodec + MaxEncodedLen, + Key2: FullCodec + MaxEncodedLen, + Value: FullCodec + MaxEncodedLen, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn storage_info() -> Vec { + [::Map::storage_info(), CounterFor::::storage_info()].concat() + } +} + +/// It doesn't require to implement `MaxEncodedLen` and give no information for `max_size`. +impl + PartialStorageInfoTrait + for CountedStorageDoubleMap< + Prefix, + Hasher1, + Key1, + Hasher2, + Key2, + Value, + QueryKind, + OnEmpty, + MaxValues, + > where + Prefix: CountedStorageDoubleMapInstance, + Hasher1: crate::hash::StorageHasher, + Hasher2: crate::hash::StorageHasher, + Key1: FullCodec, + Key2: FullCodec, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn partial_storage_info() -> Vec { + [::Map::partial_storage_info(), CounterFor::::storage_info()] + .concat() + } +} From 43db3d0c7db952d9307280db24030c37635544f5 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jan 2022 12:44:03 +0200 Subject: [PATCH 04/50] add basic tests for CountedStorageDoubleMap --- .../src/storage/types/counted_double_map.rs | 113 +++++++++++++++++- .../support/src/storage/types/counted_map.rs | 3 +- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 283f671595736..8c888c9bb0cab 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -176,7 +176,7 @@ where KArg1: EncodeLike, KArg2: EncodeLike, { - if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { + if ::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { CounterFor::::mutate(|value| value.saturating_dec()); } ::Map::remove(k1, k2) @@ -677,3 +677,114 @@ impl .concat() } } + +#[cfg(test)] +mod test { + use super::*; + use crate::hash::*; + use sp_io::{hashing::twox_128, TestExternalities}; + + struct Prefix; + impl StorageInstance for Prefix { + fn pallet_prefix() -> &'static str { + "test" + } + const STORAGE_PREFIX: &'static str = "foo"; + } + + struct CounterPrefix; + impl StorageInstance for CounterPrefix { + fn pallet_prefix() -> &'static str { + "test" + } + const STORAGE_PREFIX: &'static str = "counter_for_foo"; + } + impl CountedStorageDoubleMapInstance for Prefix { + type CounterPrefix = CounterPrefix; + } + + struct ADefault; + impl crate::traits::Get for ADefault { + fn get() -> u32 { + 97 + } + } + + #[test] + fn test_value_query() { + type A = CountedStorageDoubleMap< + Prefix, + Blake2_128Concat, + u16, + Twox64Concat, + u8, + u32, + OptionQuery, + >; + TestExternalities::default().execute_with(|| { + let mut k: Vec = vec![]; + k.extend(&twox_128(b"test")); + k.extend(&twox_128(b"foo")); + k.extend(&3u16.blake2_128_concat()); + k.extend(&30u8.twox_64_concat()); + assert_eq!(A::hashed_key_for(3, 30).to_vec(), k); + + assert_eq!(A::contains_key(3, 30), false); + assert_eq!(A::get(3, 30), None); + assert_eq!(A::try_get(3, 30), Err(())); + assert_eq!(A::count(), 0); + + A::insert(3, 30, 10); + assert_eq!(A::contains_key(3, 30), true); + assert_eq!(A::get(3, 30), Some(10)); + assert_eq!(A::try_get(3, 30), Ok(10)); + assert_eq!(A::count(), 1); + + A::swap(3, 30, 2, 20); + assert_eq!(A::contains_key(3, 30), false); + assert_eq!(A::contains_key(2, 20), true); + assert_eq!(A::get(3, 30), None); + assert_eq!(A::try_get(3, 30), Err(())); + assert_eq!(A::get(2, 20), Some(10)); + assert_eq!(A::try_get(2, 20), Ok(10)); + assert_eq!(A::count(), 1); + + A::swap(3, 30, 2, 20); + assert_eq!(A::contains_key(3, 30), true); + assert_eq!(A::contains_key(2, 20), false); + assert_eq!(A::get(3, 30), Some(10)); + assert_eq!(A::try_get(3, 30), Ok(10)); + assert_eq!(A::get(2, 20), None); + assert_eq!(A::try_get(2, 20), Err(())); + assert_eq!(A::count(), 1); + + A::insert(4, 40, 11); + assert_eq!(A::try_get(3, 30), Ok(10)); + assert_eq!(A::try_get(4, 40), Ok(11)); + assert_eq!(A::count(), 2); + + // Swap 2 existing. + A::swap(3, 30, 4, 40); + + assert_eq!(A::try_get(3, 30), Ok(11)); + assert_eq!(A::try_get(4, 40), Ok(10)); + assert_eq!(A::count(), 2); + + // Insert an existing key, shouldn't increment counted values. + A::insert(3, 30, 12); + assert_eq!(A::try_get(3, 30), Ok(12)); + assert_eq!(A::count(), 2); + + // Remove non-existing. + A::remove(2, 20); + assert_eq!(A::contains_key(2, 20), false); + assert_eq!(A::count(), 2); + + // Remove existing. + A::remove(3, 30); + + assert_eq!(A::try_get(3, 30), Err(())); + assert_eq!(A::count(), 1); + }) + } +} diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index 99d645fba3298..c645e7b17cc6b 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -581,8 +581,9 @@ mod test { assert_eq!(A::count(), 2); // Insert an existing key, shouldn't increment counted values. - A::insert(3, 11); + A::insert(3, 12); + assert_eq!(A::try_get(3), Ok(12)); assert_eq!(A::count(), 2); // Remove non-existing. From 1558d1e9d8ed9cc2361dd8f79207a5a4da3d47ab Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jan 2022 22:00:58 +0200 Subject: [PATCH 05/50] add mutate functions implementation --- .../src/storage/types/counted_double_map.rs | 157 +++++++++--------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 8c888c9bb0cab..dc37bae72065e 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -208,73 +208,69 @@ where } } - // TODO: implement /// Mutate the value under the given keys. - // pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R - // where - // KArg1: EncodeLike, - // KArg2: EncodeLike, - // F: FnOnce(&mut QueryKind::Query) -> R, - // { - // Self::try_mutate(k1, k2, |v| Ok::(f(v))) - // .expect("`Never` can not be constructed; qed") - // } + pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut QueryKind::Query) -> R, + { + Self::try_mutate(k1, k2, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") + } - // TODO: implement /// Mutate the value under the given keys when the closure returns `Ok`. - // pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result - // where - // KArg1: EncodeLike, - // KArg2: EncodeLike, - // F: FnOnce(&mut QueryKind::Query) -> Result, - // { - // Self::try_mutate_exists(k1, k2, |option_value_ref| { - // let option_value = core::mem::replace(option_value_ref, None); - // let mut query = ::Map::from_optional_value_to_query(option_value); - // let res = f(&mut query); - // let option_value = ::Map::from_query_to_optional_value(query); - // let _ = core::mem::replace(option_value_ref, option_value); - // res - // }) - // } + pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut QueryKind::Query) -> Result, + { + Self::try_mutate_exists(k1, k2, |option_value_ref| { + let option_value = core::mem::replace(option_value_ref, None); + let mut query = QueryKind::from_optional_value_to_query(option_value); + let res = f(&mut query); + let option_value = QueryKind::from_query_to_optional_value(query); + let _ = core::mem::replace(option_value_ref, option_value); + res + }) + } - // TODO: implement /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. - // pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R - // where - // KArg1: EncodeLike, - // KArg2: EncodeLike, - // F: FnOnce(&mut Option) -> R, - // { - // Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) - // .expect("`Never` can not be constructed; qed") - // } + pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut Option) -> R, + { + Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") + } - // TODO: implement /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - // pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result - // where - // KArg1: EncodeLike, - // KArg2: EncodeLike, - // F: FnOnce(&mut Option) -> Result, - // { - // ::Map::try_mutate_exists(k1, k2, |option_value| { - // let existed = option_value.is_some(); - // let res = f(option_value); - // let exist = option_value.is_some(); - - // if res.is_ok() { - // if existed && !exist { - // // Value was deleted - // CounterFor::::mutate(|value| value.saturating_dec()); - // } else if !existed && exist { - // // Value was added - // CounterFor::::mutate(|value| value.saturating_inc()); - // } - // } - // res - // }) - // } + pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result + where + KArg1: EncodeLike, + KArg2: EncodeLike, + F: FnOnce(&mut Option) -> Result, + { + ::Map::try_mutate_exists(k1, k2, |option_value| { + let existed = option_value.is_some(); + let res = f(option_value); + let exist = option_value.is_some(); + + if res.is_ok() { + if existed && !exist { + // Value was deleted + CounterFor::::mutate(|value| value.saturating_dec()); + } else if !existed && exist { + // Value was added + CounterFor::::mutate(|value| value.saturating_inc()); + } + } + res + }) + } /// Append the given item to the value in the storage. /// @@ -382,26 +378,33 @@ where }) } - // TODO: implement /// Try and append the given item to the value in the storage. /// /// Is only available if `Value` of the storage implements [`StorageTryAppend`]. - // pub fn try_append( - // key1: KArg1, - // key2: KArg2, - // item: EncodeLikeItem, - // ) -> Result<(), ()> - // where - // KArg1: EncodeLike + Clone, - // KArg2: EncodeLike + Clone, - // Item: Encode, - // EncodeLikeItem: EncodeLike, - // Value: StorageTryAppend, - // { - // >::try_append( - // key1, key2, item, - // ) - // } + pub fn try_append( + key1: KArg1, + key2: KArg2, + item: EncodeLikeItem, + ) -> Result<(), ()> + where + KArg1: EncodeLike + Clone, + KArg2: EncodeLike + Clone, + Item: Encode, + EncodeLikeItem: EncodeLike, + Value: StorageTryAppend, + { + let bound = Value::bound(); + let current = ::Map::decode_len(Ref::from(&key1), Ref::from(&key2)) + .unwrap_or_default(); + if current < bound { + CounterFor::::mutate(|value| value.saturating_inc()); + let key = ::Map::hashed_key_for(key1, key2); + sp_io::storage::append(&key, item.encode()); + Ok(()) + } else { + Err(()) + } + } /// Initialize the counter with the actual number of items in the map. /// From bf76962d2210701ac91115ef8b414bdfc01ffa37 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jan 2022 22:25:38 +0200 Subject: [PATCH 06/50] add additional tests --- .../src/storage/types/counted_double_map.rs | 145 +++++++++++++++++- .../support/src/storage/types/counted_map.rs | 6 +- 2 files changed, 140 insertions(+), 11 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index dc37bae72065e..e4a66c0f316c3 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -139,7 +139,13 @@ where KArg1: EncodeLike, KArg2: EncodeLike, { - ::Map::take(k1, k2) + let removed_value = ::Map::mutate_exists(k1, k2, |value| { + core::mem::replace(value, None) + }); + if removed_value.is_some() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + QueryKind::from_optional_value_to_query(removed_value) } /// Swap the values of two key-pairs. @@ -722,7 +728,8 @@ mod test { Twox64Concat, u8, u32, - OptionQuery, + ValueQuery, + ADefault, >; TestExternalities::default().execute_with(|| { let mut k: Vec = vec![]; @@ -733,31 +740,31 @@ mod test { assert_eq!(A::hashed_key_for(3, 30).to_vec(), k); assert_eq!(A::contains_key(3, 30), false); - assert_eq!(A::get(3, 30), None); + assert_eq!(A::get(3, 30), ADefault::get()); assert_eq!(A::try_get(3, 30), Err(())); assert_eq!(A::count(), 0); A::insert(3, 30, 10); assert_eq!(A::contains_key(3, 30), true); - assert_eq!(A::get(3, 30), Some(10)); + assert_eq!(A::get(3, 30), 10); assert_eq!(A::try_get(3, 30), Ok(10)); assert_eq!(A::count(), 1); A::swap(3, 30, 2, 20); assert_eq!(A::contains_key(3, 30), false); assert_eq!(A::contains_key(2, 20), true); - assert_eq!(A::get(3, 30), None); + assert_eq!(A::get(3, 30), ADefault::get()); assert_eq!(A::try_get(3, 30), Err(())); - assert_eq!(A::get(2, 20), Some(10)); + assert_eq!(A::get(2, 20), 10); assert_eq!(A::try_get(2, 20), Ok(10)); assert_eq!(A::count(), 1); A::swap(3, 30, 2, 20); assert_eq!(A::contains_key(3, 30), true); assert_eq!(A::contains_key(2, 20), false); - assert_eq!(A::get(3, 30), Some(10)); + assert_eq!(A::get(3, 30), 10); assert_eq!(A::try_get(3, 30), Ok(10)); - assert_eq!(A::get(2, 20), None); + assert_eq!(A::get(2, 20), ADefault::get()); assert_eq!(A::try_get(2, 20), Err(())); assert_eq!(A::count(), 1); @@ -788,6 +795,128 @@ mod test { assert_eq!(A::try_get(3, 30), Err(())); assert_eq!(A::count(), 1); + + // Mutate non-existing to existing. + A::mutate(3, 30, |query| { + assert_eq!(*query, ADefault::get()); + *query = 40; + }); + + assert_eq!(A::try_get(3, 30), Ok(40)); + assert_eq!(A::count(), 2); + + // Try fail mutate non-existing to existing. + A::try_mutate(2, 20, |query| { + assert_eq!(*query, ADefault::get()); + *query = 4; + Result::<(), ()>::Err(()) + }) + .err() + .unwrap(); + + assert_eq!(A::try_get(2, 20), Err(())); + assert_eq!(A::count(), 2); + + // Try succeed mutate non-existing to existing. + A::try_mutate(2, 20, |query| { + assert_eq!(*query, ADefault::get()); + *query = 41; + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(A::try_get(2, 20), Ok(41)); + assert_eq!(A::count(), 3); + + // Try succeed mutate existing to existing. + A::try_mutate(2, 20, |query| { + assert_eq!(*query, 41); + *query = 41; + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(A::try_get(2, 20), Ok(41)); + assert_eq!(A::count(), 3); + + // Try fail mutate non-existing to existing. + A::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, None); + *query = Some(4); + Result::<(), ()>::Err(()) + }) + .err() + .unwrap(); + + assert_eq!(A::try_get(1, 10), Err(())); + assert_eq!(A::count(), 3); + + // Try succeed mutate non-existing to existing. + A::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, None); + *query = Some(43); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(A::try_get(1, 10), Ok(43)); + assert_eq!(A::count(), 4); + + // Try succeed mutate existing to existing. + A::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, Some(43)); + *query = Some(45); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(A::try_get(1, 10), Ok(45)); + assert_eq!(A::count(), 4); + + // Try succeed mutate existing to non-existing. + A::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, Some(45)); + *query = None; + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(A::try_get(1, 10), Err(())); + assert_eq!(A::count(), 3); + + // Take exsisting. + assert_eq!(A::take(4, 40), 10); + + assert_eq!(A::try_get(4, 40), Err(())); + assert_eq!(A::count(), 2); + + // Take non-exsisting. + assert_eq!(A::take(4, 40), ADefault::get()); + + assert_eq!(A::try_get(4, 40), Err(())); + assert_eq!(A::count(), 2); + + // Remove all. + A::remove_all(); + + assert_eq!(A::count(), 0); + assert_eq!(A::initialize_counter(), 0); + + A::insert(1, 10, 1); + A::insert(2, 20, 2); + + // Iter values. + assert_eq!(A::iter_values().collect::>(), vec![2, 1]); + + // Iter drain values. + assert_eq!(A::iter_values().drain().collect::>(), vec![2, 1]); + assert_eq!(A::count(), 0); + + A::insert(1, 10, 1); + A::insert(2, 20, 2); + + // Test initialize_counter. + assert_eq!(A::initialize_counter(), 2); }) } } diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index c645e7b17cc6b..bc0f489046990 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -676,17 +676,17 @@ mod test { // Try succeed mutate existing to existing. A::try_mutate_exists(1, |query| { assert_eq!(*query, Some(43)); - *query = Some(43); + *query = Some(45); Result::<(), ()>::Ok(()) }) .unwrap(); - assert_eq!(A::try_get(1), Ok(43)); + assert_eq!(A::try_get(1), Ok(45)); assert_eq!(A::count(), 4); // Try succeed mutate existing to non-existing. A::try_mutate_exists(1, |query| { - assert_eq!(*query, Some(43)); + assert_eq!(*query, Some(45)); *query = None; Result::<(), ()>::Ok(()) }) From 9cae6fe2d9cd0bfe9939ac478c1cfc8667f79440 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 00:39:25 +0200 Subject: [PATCH 07/50] add test_option_query test --- .../src/storage/types/counted_double_map.rs | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index e4a66c0f316c3..d6aa071a464c7 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -919,4 +919,235 @@ mod test { assert_eq!(A::initialize_counter(), 2); }) } + + #[test] + fn test_option_query() { + type B = CountedStorageDoubleMap; + TestExternalities::default().execute_with(|| { + let mut k: Vec = vec![]; + k.extend(&twox_128(b"test")); + k.extend(&twox_128(b"foo")); + k.extend(&3u16.blake2_256()); + k.extend(&30u8.twox_64_concat()); + assert_eq!(B::hashed_key_for(3, 30).to_vec(), k); + + assert_eq!(B::contains_key(3, 30), false); + assert_eq!(B::get(3, 30), None); + assert_eq!(B::try_get(3, 30), Err(())); + assert_eq!(B::count(), 0); + + // Insert non-existing. + B::insert(3, 30, 10); + + assert_eq!(B::contains_key(3, 30), true); + assert_eq!(B::get(3, 30), Some(10)); + assert_eq!(B::try_get(3, 30), Ok(10)); + assert_eq!(B::count(), 1); + + // Swap non-existing with existing. + B::swap(4, 40, 3, 30); + + assert_eq!(B::contains_key(3, 30), false); + assert_eq!(B::get(3, 30), None); + assert_eq!(B::try_get(3, 30), Err(())); + assert_eq!(B::contains_key(4, 40), true); + assert_eq!(B::get(4, 40), Some(10)); + assert_eq!(B::try_get(4, 40), Ok(10)); + assert_eq!(B::count(), 1); + + // Swap existing with non-existing. + B::swap(4, 40, 3, 30); + + assert_eq!(B::try_get(3, 30), Ok(10)); + assert_eq!(B::contains_key(4, 40), false); + assert_eq!(B::get(4, 40), None); + assert_eq!(B::try_get(4, 40), Err(())); + assert_eq!(B::count(), 1); + + B::insert(4, 40, 11); + + assert_eq!(B::try_get(3, 30), Ok(10)); + assert_eq!(B::try_get(4, 40), Ok(11)); + assert_eq!(B::count(), 2); + + // Swap 2 existing. + B::swap(3, 30, 4, 40); + + assert_eq!(B::try_get(3, 30), Ok(11)); + assert_eq!(B::try_get(4, 40), Ok(10)); + assert_eq!(B::count(), 2); + + // Insert an existing key, shouldn't increment counted values. + B::insert(3, 30, 11); + + assert_eq!(B::count(), 2); + + // Remove non-existing. + B::remove(2, 20); + + assert_eq!(B::contains_key(2, 20), false); + assert_eq!(B::count(), 2); + + // Remove existing. + B::remove(3, 30); + + assert_eq!(B::try_get(3, 30), Err(())); + assert_eq!(B::count(), 1); + + // Mutate non-existing to existing. + B::mutate(3, 30, |query| { + assert_eq!(*query, None); + *query = Some(40) + }); + + assert_eq!(B::try_get(3, 30), Ok(40)); + assert_eq!(B::count(), 2); + + // Mutate existing to existing. + B::mutate(3, 30, |query| { + assert_eq!(*query, Some(40)); + *query = Some(40) + }); + + assert_eq!(B::try_get(3, 30), Ok(40)); + assert_eq!(B::count(), 2); + + // Mutate existing to non-existing. + B::mutate(3, 30, |query| { + assert_eq!(*query, Some(40)); + *query = None + }); + + assert_eq!(B::try_get(3, 30), Err(())); + assert_eq!(B::count(), 1); + + B::insert(3, 30, 40); + + // Try fail mutate non-existing to existing. + B::try_mutate(2, 20, |query| { + assert_eq!(*query, None); + *query = Some(4); + Result::<(), ()>::Err(()) + }) + .err() + .unwrap(); + + assert_eq!(B::try_get(2, 20), Err(())); + assert_eq!(B::count(), 2); + + // Try succeed mutate non-existing to existing. + B::try_mutate(2, 20, |query| { + assert_eq!(*query, None); + *query = Some(41); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(2, 20), Ok(41)); + assert_eq!(B::count(), 3); + + // Try succeed mutate existing to existing. + B::try_mutate(2, 20, |query| { + assert_eq!(*query, Some(41)); + *query = Some(41); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(2, 20), Ok(41)); + assert_eq!(B::count(), 3); + + // Try succeed mutate existing to non-existing. + B::try_mutate(2, 20, |query| { + assert_eq!(*query, Some(41)); + *query = None; + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(2, 20), Err(())); + assert_eq!(B::count(), 2); + + B::insert(2, 20, 41); + + // Try fail mutate non-existing to existing. + B::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, None); + *query = Some(4); + Result::<(), ()>::Err(()) + }) + .err() + .unwrap(); + + assert_eq!(B::try_get(1, 10), Err(())); + assert_eq!(B::count(), 3); + + // Try succeed mutate non-existing to existing. + B::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, None); + *query = Some(43); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(1, 10), Ok(43)); + assert_eq!(B::count(), 4); + + // Try succeed mutate existing to existing. + B::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, Some(43)); + *query = Some(43); + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(1, 10), Ok(43)); + assert_eq!(B::count(), 4); + + // Try succeed mutate existing to non-existing. + B::try_mutate_exists(1, 10, |query| { + assert_eq!(*query, Some(43)); + *query = None; + Result::<(), ()>::Ok(()) + }) + .unwrap(); + + assert_eq!(B::try_get(1, 10), Err(())); + assert_eq!(B::count(), 3); + + // Take exsisting. + assert_eq!(B::take(4, 40), Some(10)); + + assert_eq!(B::try_get(4, 40), Err(())); + assert_eq!(B::count(), 2); + + // Take non-exsisting. + assert_eq!(B::take(4, 40), None); + + assert_eq!(B::try_get(4, 40), Err(())); + assert_eq!(B::count(), 2); + + // Remove all. + B::remove_all(); + + assert_eq!(B::count(), 0); + assert_eq!(B::initialize_counter(), 0); + + B::insert(1, 10, 1); + B::insert(2, 20, 2); + + // Iter values. + assert_eq!(B::iter_values().collect::>(), vec![1, 2]); + + // Iter drain values. + assert_eq!(B::iter_values().drain().collect::>(), vec![1, 2]); + assert_eq!(B::count(), 0); + + B::insert(1, 10, 1); + B::insert(2, 20, 2); + + // Test initialize_counter. + assert_eq!(B::initialize_counter(), 2); + }) + } } From 42fa3f572496f7dfe848244fc327c37183eb1bd8 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 00:44:41 +0200 Subject: [PATCH 08/50] add try_append_decode_len_works, append_decode_len_works tests --- .../src/storage/types/counted_double_map.rs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index d6aa071a464c7..af61a3b4f0f8e 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -690,7 +690,7 @@ impl #[cfg(test)] mod test { use super::*; - use crate::hash::*; + use crate::{hash::*, storage::bounded_vec::BoundedVec, traits::ConstU32}; use sp_io::{hashing::twox_128, TestExternalities}; struct Prefix; @@ -1150,4 +1150,41 @@ mod test { assert_eq!(B::initialize_counter(), 2); }) } + + #[test] + fn append_decode_len_works() { + type B = CountedStorageDoubleMap>; + TestExternalities::default().execute_with(|| { + assert_eq!(B::decode_len(1, 10), None); + B::append(1, 10, 3); + assert_eq!(B::decode_len(1, 10), Some(1)); + B::append(1, 10, 3); + assert_eq!(B::decode_len(1, 10), Some(2)); + B::append(1, 10, 3); + assert_eq!(B::decode_len(1, 10), Some(3)); + }) + } + + #[test] + fn try_append_decode_len_works() { + type B = CountedStorageDoubleMap< + Prefix, + Blake2_256, + u16, + Twox64Concat, + u8, + BoundedVec>, + >; + TestExternalities::default().execute_with(|| { + assert_eq!(B::decode_len(1, 10), None); + B::try_append(1, 10, 3).unwrap(); + assert_eq!(B::decode_len(1, 10), Some(1)); + B::try_append(1, 10, 3).unwrap(); + assert_eq!(B::decode_len(1, 10), Some(2)); + B::try_append(1, 10, 3).unwrap(); + assert_eq!(B::decode_len(1, 10), Some(3)); + B::try_append(1, 10, 3).err().unwrap(); + assert_eq!(B::decode_len(1, 10), Some(3)); + }) + } } From c707346e78e9018a5bb7a6e60a2dd6fd84c52a1b Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 00:49:49 +0200 Subject: [PATCH 09/50] add migrate_keys_works, translate_values tests --- .../src/storage/types/counted_double_map.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index af61a3b4f0f8e..574eede8cdffe 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -1187,4 +1187,27 @@ mod test { assert_eq!(B::decode_len(1, 10), Some(3)); }) } + + #[test] + fn migrate_keys_works() { + type A = CountedStorageDoubleMap; + type B = CountedStorageDoubleMap; + TestExternalities::default().execute_with(|| { + A::insert(1, 10, 1); + assert_eq!(B::migrate_keys::(1, 10), Some(1)); + assert_eq!(B::get(1, 10), Some(1)); + }) + } + + #[test] + fn translate_values() { + type A = CountedStorageDoubleMap; + TestExternalities::default().execute_with(|| { + A::insert(1, 10, 1); + A::insert(2, 20, 2); + A::translate_values::(|old_value| if old_value == 1 { None } else { Some(1) }); + assert_eq!(A::count(), 1); + assert_eq!(A::get(2, 20), Some(1)); + }) + } } From 9eb2989f9becb76d5ab7bcd2a2add96cfe5893b0 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 01:01:05 +0200 Subject: [PATCH 10/50] add test_iter_drain_translate test --- .../src/storage/types/counted_double_map.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 574eede8cdffe..956ddf2a6d730 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -1210,4 +1210,27 @@ mod test { assert_eq!(A::get(2, 20), Some(1)); }) } + + #[test] + fn test_iter_drain_translate() { + type A = CountedStorageDoubleMap; + TestExternalities::default().execute_with(|| { + A::insert(1, 10, 1); + A::insert(2, 20, 2); + + assert_eq!(A::iter().collect::>(), vec![(2, 20, 2), (1, 10, 1)]); + + assert_eq!(A::count(), 2); + + A::translate::( + |key1, key2, value| if key1 == 1 { None } else { Some(key1 as u32 * value) }, + ); + + assert_eq!(A::count(), 1); + + assert_eq!(A::drain().collect::>(), vec![(2, 20, 4)]); + + assert_eq!(A::count(), 0); + }) + } } From b2085d7c832343b0d45a94cb9ca990947ffd60cc Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 01:06:25 +0200 Subject: [PATCH 11/50] add test_metadata test --- .../src/storage/types/counted_double_map.rs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 956ddf2a6d730..9ec95e7ddc5df 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -690,7 +690,12 @@ impl #[cfg(test)] mod test { use super::*; - use crate::{hash::*, storage::bounded_vec::BoundedVec, traits::ConstU32}; + use crate::{ + hash::*, + metadata::{StorageEntryModifier, StorageEntryType, StorageHasher}, + storage::bounded_vec::BoundedVec, + traits::ConstU32, + }; use sp_io::{hashing::twox_128, TestExternalities}; struct Prefix; @@ -1233,4 +1238,43 @@ mod test { assert_eq!(A::count(), 0); }) } + + #[test] + fn test_metadata() { + type A = CountedStorageDoubleMap< + Prefix, + Blake2_128Concat, + u16, + Twox64Concat, + u8, + u32, + ValueQuery, + ADefault, + >; + let mut entries = vec![]; + A::build_metadata(vec![], &mut entries); + assert_eq!( + entries, + vec![ + StorageEntryMetadata { + name: "foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Map { + hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat], + key: scale_info::meta_type::<(u16, u8)>(), + value: scale_info::meta_type::(), + }, + default: 97u32.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "counter_for_foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec!["Counter for the related counted storage map"], + }, + ] + ); + } } From 9b3db6d92615212fb0f9dc571dcead7831af849a Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 12:27:25 +0200 Subject: [PATCH 12/50] add remove_prefix implementation, add test_iter_drain_prefix test --- .../src/storage/types/counted_double_map.rs | 58 ++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 9ec95e7ddc5df..019b3fd37c251 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -188,14 +188,26 @@ where ::Map::remove(k1, k2) } - // TODO: implement /// Remove all values under the first key. - // pub fn remove_prefix(k1: KArg1) - // where - // KArg1: ?Sized + EncodeLike, - // { - // ::Map::remove_prefix(k1, limit) - // } + /// + /// # Warning + /// + /// Expensive operation, need to iterate over all 'k1' prefixes to calculate how many values + /// need to remove + pub fn remove_prefix(k1: KArg1) + where + KArg1: ?Sized + EncodeLike, + { + let mut on_remove = 0; + Self::iter_prefix_values(Ref::from(&k1)).for_each(|_| { + on_remove += 1; + }); + dbg!(&on_remove); + CounterFor::::mutate(|value| { + *value = value.saturating_sub(on_remove); + }); + ::Map::remove_prefix(k1, None); + } /// Iterate over values that share the first key. pub fn iter_prefix_values( @@ -1228,7 +1240,7 @@ mod test { assert_eq!(A::count(), 2); A::translate::( - |key1, key2, value| if key1 == 1 { None } else { Some(key1 as u32 * value) }, + |key1, _key2, value| if key1 == 1 { None } else { Some(key1 as u32 * value) }, ); assert_eq!(A::count(), 1); @@ -1239,6 +1251,36 @@ mod test { }) } + #[test] + fn test_iter_drain_prefix() { + type A = CountedStorageDoubleMap; + TestExternalities::default().execute_with(|| { + A::insert(1, 10, 1); + A::insert(1, 11, 2); + A::insert(2, 20, 3); + A::insert(2, 21, 4); + + assert_eq!(A::iter_prefix_values(1).collect::>(), vec![1, 2]); + assert_eq!(A::iter_prefix(1).collect::>(), vec![(10, 1), (11, 2)]); + assert_eq!(A::iter_prefix_values(2).collect::>(), vec![4, 3]); + assert_eq!(A::iter_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); + + assert_eq!(A::count(), 4); + + A::remove_prefix(1); + assert_eq!(A::iter_prefix(1).collect::>(), vec![]); + assert_eq!(A::iter_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); + + assert_eq!(A::count(), 2); + + assert_eq!(A::drain_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); + assert_eq!(A::iter_prefix(2).collect::>(), vec![]); + assert_eq!(A::drain_prefix(2).collect::>(), vec![]); + + assert_eq!(A::count(), 0); + }) + } + #[test] fn test_metadata() { type A = CountedStorageDoubleMap< From 603f7b6a0a5830e05c231b3698ef7fc231b1136c Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jan 2022 14:16:05 +0200 Subject: [PATCH 13/50] update --- frame/support/src/storage/types/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/support/src/storage/types/mod.rs b/frame/support/src/storage/types/mod.rs index 17d7f2b81c8d5..bd5cec9299a7e 100644 --- a/frame/support/src/storage/types/mod.rs +++ b/frame/support/src/storage/types/mod.rs @@ -30,6 +30,7 @@ mod map; mod nmap; mod value; +pub use counted_double_map::{CountedStorageDoubleMap, CountedStorageDoubleMapInstance}; pub use counted_map::{CountedStorageMap, CountedStorageMapInstance}; pub use double_map::StorageDoubleMap; pub use key::{ From e92395644fc63dbddc3dca9537d6ae228c1c09d6 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Mon, 10 Jan 2022 11:01:19 +0200 Subject: [PATCH 14/50] refactor PrefixIterator usage --- .../src/storage/types/counted_double_map.rs | 72 +++---------------- 1 file changed, 8 insertions(+), 64 deletions(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index 019b3fd37c251..efa13cad1cdc6 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -216,14 +216,7 @@ where where KArg1: ?Sized + EncodeLike, { - let map_iterator = ::Map::iter_prefix_values(k1); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter_prefix_values(k1).convert_on_removal() } /// Mutate the value under the given keys. @@ -363,14 +356,7 @@ where /// /// NOTE: If a value failed to decode because storage is corrupted then it is skipped. pub fn iter_values() -> crate::storage::PrefixIterator> { - let map_iterator = ::Map::iter_values(); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter_values().convert_on_removal() } /// Translate the values of all elements by a function `f`, in the map in no particular order. @@ -462,14 +448,7 @@ where pub fn iter_prefix( k1: impl EncodeLike, ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::iter_prefix(k1); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter_prefix(k1).convert_on_removal() } /// Enumerate all elements in the map with first key `k1` after a specified `starting_raw_key` @@ -481,14 +460,7 @@ where k1: impl EncodeLike, starting_raw_key: Vec, ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::iter_prefix_from(k1, starting_raw_key); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter_prefix_from(k1, starting_raw_key).convert_on_removal() } /// Enumerate all second keys `k2` in the map with the same first key `k1` in no particular @@ -520,14 +492,7 @@ where pub fn drain_prefix( k1: impl EncodeLike, ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::drain_prefix(k1); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::drain_prefix(k1).convert_on_removal() } /// Enumerate all elements in the map in no particular order. @@ -535,14 +500,7 @@ where /// If you add or remove values to the map while doing this, you'll get undefined results. pub fn iter( ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::iter(); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter().convert_on_removal() } /// Enumerate all elements in the map after a specified `starting_raw_key` in no particular @@ -552,14 +510,7 @@ where pub fn iter_from( starting_raw_key: Vec, ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::iter_from(starting_raw_key); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::iter_from(starting_raw_key).convert_on_removal() } /// Enumerate all keys `k1` and `k2` in the map in no particular order. @@ -584,14 +535,7 @@ where /// If you add elements to the map while doing this, you'll get undefined results. pub fn drain( ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - let map_iterator = ::Map::drain(); - crate::storage::PrefixIterator { - prefix: map_iterator.prefix, - previous_key: map_iterator.previous_key, - drain: map_iterator.drain, - closure: map_iterator.closure, - phantom: Default::default(), - } + ::Map::drain().convert_on_removal() } /// Translate the values of all elements by a function `f`, in the map in no particular order. From eac96161b9bace1f356bbf8e13e4d2fca41edf41 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Mon, 10 Jan 2022 12:28:50 +0200 Subject: [PATCH 15/50] Fix CI build --- frame/support/src/storage/types/counted_double_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs index efa13cad1cdc6..a85ea5d41441f 100644 --- a/frame/support/src/storage/types/counted_double_map.rs +++ b/frame/support/src/storage/types/counted_double_map.rs @@ -14,6 +14,7 @@ use crate::{ }; use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; use sp_runtime::traits::Saturating; +use sp_std::prelude::*; pub struct CountedStorageDoubleMap< Prefix, @@ -202,7 +203,6 @@ where Self::iter_prefix_values(Ref::from(&k1)).for_each(|_| { on_remove += 1; }); - dbg!(&on_remove); CounterFor::::mutate(|value| { *value = value.saturating_sub(on_remove); }); From 34cdbfaf4e6d9d1ed82907974466280831478d1c Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 11 Jan 2022 23:22:35 +0200 Subject: [PATCH 16/50] fix storage_ensure_span_are_ok_wrong_gen.rs storage_ensure_span_are_ok_wrong_gen_unnamed.rs --- ...age_ensure_span_are_ok_on_wrong_gen.stderr | 42 +++++++++---------- ...re_span_are_ok_on_wrong_gen_unnamed.stderr | 42 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.stderr b/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.stderr index 82fd3ad884f90..ac8b20d4692bf 100644 --- a/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.stderr +++ b/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar` @@ -8,13 +8,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `EncodeLike` is not implemented for `Bar` @@ -23,13 +23,13 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar` @@ -39,13 +39,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `TypeInfo` is not implemented for `Bar` @@ -53,13 +53,13 @@ error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied = note: required because of the requirements on the impl of `StaticTypeInfo` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar` @@ -68,13 +68,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `EncodeLike` is not implemented for `Bar` @@ -83,13 +83,13 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar` @@ -99,7 +99,7 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.stderr b/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.stderr index eb1404fc62c38..646c372749836 100644 --- a/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.stderr +++ b/frame/support/test/tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar` @@ -8,13 +8,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `EncodeLike` is not implemented for `Bar` @@ -23,13 +23,13 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:9:12 | 9 | #[pallet::pallet] | ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar` @@ -39,13 +39,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `partial_storage_info` - --> $DIR/storage.rs:88:2 + --> $WORKSPACE/frame/support/src/traits/storage.rs | -88 | fn partial_storage_info() -> Vec; + | fn partial_storage_info() -> Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `TypeInfo` is not implemented for `Bar` @@ -53,13 +53,13 @@ error[E0277]: the trait bound `Bar: TypeInfo` is not satisfied = note: required because of the requirements on the impl of `StaticTypeInfo` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `WrapperTypeDecode` is not implemented for `Bar` @@ -68,13 +68,13 @@ error[E0277]: the trait bound `Bar: WrapperTypeDecode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `EncodeLike` is not implemented for `Bar` @@ -83,13 +83,13 @@ error[E0277]: the trait bound `Bar: EncodeLike` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied - --> $DIR/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 + --> tests/pallet_ui/storage_ensure_span_are_ok_on_wrong_gen_unnamed.rs:20:12 | 20 | #[pallet::storage] | ^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `Bar` @@ -99,7 +99,7 @@ error[E0277]: the trait bound `Bar: WrapperTypeEncode` is not satisfied = note: required because of the requirements on the impl of `FullCodec` for `Bar` = note: required because of the requirements on the impl of `StorageEntryMetadataBuilder` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageFoo, Bar>` note: required by `build_metadata` - --> $DIR/mod.rs:113:2 + --> $WORKSPACE/frame/support/src/storage/types/mod.rs | -113 | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); + | fn build_metadata(doc: Vec<&'static str>, entries: &mut Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 9af68cb4b0c07053c9b5c14786b40cd0186a76be Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 2 Jul 2022 22:53:31 +0300 Subject: [PATCH 17/50] add counted_nmap implementation --- .../support/src/storage/types/counted_nmap.rs | 666 ++++++++++++++++++ frame/support/src/storage/types/mod.rs | 2 + frame/support/src/storage/types/nmap.rs | 4 +- 3 files changed, 670 insertions(+), 2 deletions(-) create mode 100644 frame/support/src/storage/types/counted_nmap.rs diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs new file mode 100644 index 0000000000000..e6e565f52a26c --- /dev/null +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -0,0 +1,666 @@ +// This file is part of Substrate. + +// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Storage map type. Implements CountedStorageNMap, CountedStorageIterableNMap, +//! CountedStoragePrefixedNMap traits and their methods directly. + +use crate::{ + metadata::{StorageEntryMetadata, StorageEntryType}, + storage::{ + types::{ + EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, OptionQuery, QueryKindTrait, + StorageEntryMetadataBuilder, StorageValue, TupleToEncodedIter, ValueQuery, + }, + KeyGenerator, PrefixIterator, StorageAppend, StorageDecodeLength, StoragePrefixedMap, + }, + traits::{Get, GetDefault, StorageInfo, StorageInstance}, +}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; +use sp_runtime::{traits::Saturating, SaturatedConversion}; +use sp_std::prelude::*; + +/// A wrapper around a `StorageNMap` and a `StorageValue` to keep track of how many items +/// are in a map, without needing to iterate all the values. +/// +/// This storage item has additional storage read and write overhead when manipulating values +/// compared to a regular storage map. +/// +/// For functions where we only add or remove a value, a single storage read is needed to check if +/// that value already exists. For mutate functions, two storage reads are used to check if the +/// value existed before and after the mutation. +/// +/// Whenever the counter needs to be updated, an additional read and write occurs to update that +/// counter. +pub struct CountedStorageNMap< + Prefix, + Key, + Value, + QueryKind = OptionQuery, + OnEmpty = GetDefault, + MaxValues = GetDefault, +>(core::marker::PhantomData<(Prefix, Key, Value, QueryKind, OnEmpty, MaxValues)>); + +/// The requirement for an instance of [`CountedStorageNMap`]. +pub trait CountedStorageNMapInstance: StorageInstance { + /// The prefix to use for the counter storage value. + type CounterPrefix: StorageInstance; +} + +// Private helper trait to access map from counted storage double map +trait MapWrapper { + type Map; +} + +impl MapWrapper + for CountedStorageNMap +{ + type Map = CountedStorageNMap; +} + +type CounterFor

= + StorageValue<

::CounterPrefix, u32, ValueQuery>; + +/// On removal logic for updating counter while draining upon some prefix with +/// [`crate::storage::PrefixIterator`]. +pub struct OnRemovalCounterUpdate(core::marker::PhantomData); + +impl crate::storage::PrefixIteratorOnRemoval + for OnRemovalCounterUpdate +{ + fn on_removal(_key: &[u8], _value: &[u8]) { + CounterFor::::mutate(|value| value.saturating_dec()); + } +} + +impl + crate::storage::generator::StorageNMap + for CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + type Query = QueryKind::Query; + fn module_prefix() -> &'static [u8] { + Prefix::pallet_prefix().as_bytes() + } + fn storage_prefix() -> &'static [u8] { + Prefix::STORAGE_PREFIX.as_bytes() + } + fn from_optional_value_to_query(v: Option) -> Self::Query { + QueryKind::from_optional_value_to_query(v) + } + fn from_query_to_optional_value(v: Self::Query) -> Option { + QueryKind::from_query_to_optional_value(v) + } +} + +impl crate::storage::StoragePrefixedMap + for CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn module_prefix() -> &'static [u8] { + ::Map::module_prefix() + } + fn storage_prefix() -> &'static [u8] { + ::Map::storage_prefix() + } +} + +impl + CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + /// Get the storage key used to fetch a value corresponding to a specific key. + pub fn hashed_key_for + TupleToEncodedIter>( + key: KArg, + ) -> Vec { + ::Map::hashed_key_for(key) + } + + /// Does the value (explicitly) exist in storage? + pub fn contains_key + TupleToEncodedIter>(key: KArg) -> bool { + ::Map::contains_key(key) + } + + /// Load the value associated with the given key from the map. + pub fn get + TupleToEncodedIter>( + key: KArg, + ) -> QueryKind::Query { + ::Map::get(key) + } + + /// Try to get the value for the given key from the map. + /// + /// Returns `Ok` if it exists, `Err` if not. + pub fn try_get + TupleToEncodedIter>( + key: KArg, + ) -> Result { + ::Map::try_get(key) + } + + /// Store or remove the value to be associated with `key` so that `get` returns the `query`. + pub fn set + TupleToEncodedIter>( + key: KArg, + query: QueryKind::Query, + ) { + // TODO: implement + ::Map::set(key, query) + } + + /// Take a value from storage, removing it afterwards. + pub fn take + TupleToEncodedIter>( + key: KArg, + ) -> QueryKind::Query { + let removed_value = + ::Map::mutate_exists(key, |value| core::mem::replace(value, None)); + if removed_value.is_some() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + QueryKind::from_optional_value_to_query(removed_value) + } + + /// Swap the values of two key-pairs. + pub fn swap(key1: KArg1, key2: KArg2) + where + KOther: KeyGenerator, + KArg1: EncodeLikeTuple + TupleToEncodedIter, + KArg2: EncodeLikeTuple + TupleToEncodedIter, + { + ::Map::swap::(key1, key2) + } + + /// Store a value to be associated with the given keys from the map. + pub fn insert(key: KArg, val: VArg) + where + KArg: EncodeLikeTuple + TupleToEncodedIter + Clone, + VArg: EncodeLike, + { + if !::Map::contains_key(key.clone()) { + CounterFor::::mutate(|value| value.saturating_inc()); + } + ::Map::insert(key, val) + } + + /// Remove the value under the given keys. + pub fn remove + TupleToEncodedIter + Clone>(key: KArg) { + if ::Map::contains_key(key.clone()) { + CounterFor::::mutate(|value| value.saturating_dec()); + } + ::Map::remove(key) + } + + /// Attempt to remove items from the map matching a `partial_key` prefix. + /// + /// 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 + /// empty when the resultant `maybe_cursor` is `None`. + /// + /// # Limit + /// + /// A `limit` must be provided in order to cap the maximum + /// amount of deletions done in a single call. This is one fewer than the + /// maximum number of backend iterations which may be done by this operation and as such + /// represents the maximum number of backend deletions which may happen. A `limit` of zero + /// implies that no keys will be deleted, though there may be a single iteration done. + /// + /// # Cursor + /// + /// A *cursor* may be passed in to this operation with `maybe_cursor`. `None` should only be + /// passed once (in the initial call) for any given storage map and `partial_key`. Subsequent + /// calls operating on the same map/`partial_key` should always pass `Some`, and this should be + /// equal to the previous call result's `maybe_cursor` field. + pub fn clear_prefix( + partial_key: KP, + limit: u32, + maybe_cursor: Option<&[u8]>, + ) -> sp_io::MultiRemovalResults + where + Key: HasKeyPrefix, + { + let mut on_remove = 0; + Self::iter_prefix_values(partial_key.clone()).for_each(|_| { + on_remove += 1; + }); + CounterFor::::mutate(|value| { + *value = value.saturating_sub(on_remove); + }); + ::Map::clear_prefix(partial_key, limit, maybe_cursor) + } + + /// Iterate over values that share the first key. + pub fn iter_prefix_values(partial_key: KP) -> PrefixIterator + where + Key: HasKeyPrefix, + { + ::Map::iter_prefix_values(partial_key) + } + + /// Mutate the value under the given keys. + pub fn mutate(key: KArg, f: F) -> R + where + KArg: EncodeLikeTuple + TupleToEncodedIter, + F: FnOnce(&mut QueryKind::Query) -> R, + { + ::Map::mutate(key, f) + } + + /// Mutate the value under the given keys when the closure returns `Ok`. + pub fn try_mutate(key: KArg, f: F) -> Result + where + KArg: EncodeLikeTuple + TupleToEncodedIter, + F: FnOnce(&mut QueryKind::Query) -> Result, + { + ::Map::try_mutate(key, f) + } + + /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. + pub fn mutate_exists(key: KArg, f: F) -> R + where + KArg: EncodeLikeTuple + TupleToEncodedIter, + F: FnOnce(&mut Option) -> R, + { + ::Map::mutate_exists(key, f) + } + + /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. + /// `f` will always be called with an option representing if the storage item exists (`Some`) + /// or if the storage item does not exist (`None`), independent of the `QueryType`. + pub fn try_mutate_exists(key: KArg, f: F) -> Result + where + KArg: EncodeLikeTuple + TupleToEncodedIter, + F: FnOnce(&mut Option) -> Result, + { + ::Map::try_mutate_exists(key, |option_value| { + let existed = option_value.is_some(); + let res = f(option_value); + let exist = option_value.is_some(); + + if res.is_ok() { + if existed && !exist { + // Value was deleted + CounterFor::::mutate(|value| value.saturating_dec()); + } else if !existed && exist { + // Value was added + CounterFor::::mutate(|value| value.saturating_inc()); + } + } + res + }) + } + + /// Append the given item to the value in the storage. + /// + /// `Value` is required to implement [`StorageAppend`]. + /// + /// # Warning + /// + /// If the storage item is not encoded properly, the storage will be overwritten + /// and set to `[item]`. Any default value set for the storage item will be ignored + /// on overwrite. + pub fn append(key: KArg, item: EncodeLikeItem) + where + KArg: EncodeLikeTuple + TupleToEncodedIter + Clone, + Item: Encode, + EncodeLikeItem: EncodeLike, + Value: StorageAppend, + { + if !::Map::contains_key(key.clone()) { + CounterFor::::mutate(|value| value.saturating_inc()); + } + ::Map::append(key, item) + } + + /// Read the length of the storage value without decoding the entire value under the + /// given `key1` and `key2`. + /// + /// `Value` is required to implement [`StorageDecodeLength`]. + /// + /// If the value does not exists or it fails to decode the length, `None` is returned. + /// Otherwise `Some(len)` is returned. + /// + /// # Warning + /// + /// `None` does not mean that `get()` does not return a value. The default value is completly + /// ignored by this function. + pub fn decode_len + TupleToEncodedIter>( + key: KArg, + ) -> Option + where + Value: StorageDecodeLength, + { + ::Map::decode_len(key) + } + + /// Migrate an item with the given `key` from defunct `hash_fns` to the current hashers. + /// + /// If the key doesn't exist, then it's a no-op. If it does, then it returns its value. + pub fn migrate_keys(key: KArg, hash_fns: Key::HArg) -> Option + where + KArg: EncodeLikeTuple + TupleToEncodedIter, + { + ::Map::migrate_keys::<_>(key, hash_fns) + } + + /// Attempt to remove all items from the map. + /// + /// 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 + /// `maybe_cursor` is `None`. + /// + /// # Limit + /// + /// A `limit` must always be provided through in order to cap the maximum + /// amount of deletions done in a single call. This is one fewer than the + /// maximum number of backend iterations which may be done by this operation and as such + /// represents the maximum number of backend deletions which may happen. A `limit` of zero + /// implies that no keys will be deleted, though there may be a single iteration done. + /// + /// # Cursor + /// + /// A *cursor* may be passed in to this operation with `maybe_cursor`. `None` should only be + /// 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::MultiRemovalResults { + CounterFor::::set(0u32); + ::Map::clear(limit, maybe_cursor) + } + + /// Iter over all value of the storage. + /// + /// NOTE: If a value failed to decode because storage is corrupted then it is skipped. + pub fn iter_values() -> crate::storage::PrefixIterator { + ::Map::iter_values() + } + + /// Translate the values of all elements by a function `f`, in the map in no particular order. + /// By returning `None` from `f` for an element, you'll remove it from the map. + /// + /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. + /// + /// # Warning + /// + /// This function must be used with care, before being updated the storage still contains the + /// old type, thus other calls (such as `get`) will fail at decoding it. + /// + /// # Usage + /// + /// This would typically be called inside the module implementation of on_runtime_upgrade. + pub fn translate_values Option>(mut f: F) { + ::Map::translate_values(|old_value| { + let res = f(old_value); + if res.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + res + }) + } + + /// Initialize the counter with the actual number of items in the map. + /// + /// This function iterates through all the items in the map and sets the counter. This operation + /// can be very heavy, so use with caution. + /// + /// Returns the number of items in the map which is used to set the counter. + pub fn initialize_counter() -> u32 { + let count = Self::iter_values().count() as u32; + CounterFor::::set(count); + count + } + + /// Return the count. + pub fn count() -> u32 { + CounterFor::::get() + } +} + +impl + CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::ReversibleKeyGenerator, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + /// Enumerate all elements in the map with prefix key `kp` in no particular order. + /// + /// If you add or remove values whose prefix key is `kp` to the map while doing this, you'll get + /// undefined results. + pub fn iter_prefix( + kp: KP, + ) -> crate::storage::PrefixIterator<(>::Suffix, Value)> + where + Key: HasReversibleKeyPrefix, + { + ::Map::iter_prefix(kp) + } + + /// Enumerate all elements in the map with prefix key `kp` after a specified `starting_raw_key` + /// in no particular order. + /// + /// If you add or remove values whose prefix key is `kp` to the map while doing this, you'll get + /// undefined results. + pub fn iter_prefix_from( + kp: KP, + starting_raw_key: Vec, + ) -> crate::storage::PrefixIterator<(>::Suffix, Value)> + where + Key: HasReversibleKeyPrefix, + { + ::Map::iter_prefix_from(kp, starting_raw_key).convert_on_removal() + } + + /// Enumerate all suffix keys in the map with prefix key `kp` in no particular order. + /// + /// If you add or remove values whose prefix key is `kp` to the map while doing this, you'll get + /// undefined results. + pub fn iter_key_prefix( + kp: KP, + ) -> crate::storage::KeyPrefixIterator<>::Suffix> + where + Key: HasReversibleKeyPrefix, + { + ::Map::iter_key_prefix(kp) + } + + /// Enumerate all suffix keys in the map with prefix key `kp` after a specified + /// `starting_raw_key` in no particular order. + /// + /// If you add or remove values whose prefix key is `kp` to the map while doing this, you'll get + /// undefined results. + pub fn iter_key_prefix_from( + kp: KP, + starting_raw_key: Vec, + ) -> crate::storage::KeyPrefixIterator<>::Suffix> + where + Key: HasReversibleKeyPrefix, + { + ::Map::iter_key_prefix_from(kp, starting_raw_key) + } + + /// Remove all elements from the map with prefix key `kp` and iterate through them in no + /// particular order. + /// + /// If you add elements with prefix key `k1` to the map while doing this, you'll get undefined + /// results. + pub fn drain_prefix( + kp: KP, + ) -> crate::storage::PrefixIterator<(>::Suffix, Value)> + where + Key: HasReversibleKeyPrefix, + { + ::Map::drain_prefix(kp).convert_on_removal() + } + + /// Enumerate all elements in the map in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter() -> crate::storage::PrefixIterator<(Key::Key, Value)> { + ::Map::iter().convert_on_removal() + } + + /// Enumerate all elements in the map after a specified `starting_key` in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_from( + starting_raw_key: Vec, + ) -> crate::storage::PrefixIterator<(Key::Key, Value)> { + ::Map::iter_from(starting_raw_key).convert_on_removal() + } + + /// Enumerate all keys in the map in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_keys() -> crate::storage::KeyPrefixIterator { + ::Map::iter_keys() + } + + /// Enumerate all keys in the map after a specified `starting_raw_key` in no particular order. + /// + /// If you add or remove values to the map while doing this, you'll get undefined results. + pub fn iter_keys_from( + starting_raw_key: Vec, + ) -> crate::storage::KeyPrefixIterator { + ::Map::iter_keys_from(starting_raw_key) + } + + /// Remove all elements from the map and iterate through them in no particular order. + /// + /// If you add elements to the map while doing this, you'll get undefined results. + pub fn drain() -> crate::storage::PrefixIterator<(Key::Key, Value)> { + ::Map::drain().convert_on_removal() + } + + /// Translate the values of all elements by a function `f`, in the map in no particular order. + /// + /// By returning `None` from `f` for an element, you'll remove it from the map. + /// + /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. + pub fn translate Option>(mut f: F) { + ::Map::translate(|key, old_value| { + let res = f(key, old_value); + if res.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + res + }) + } +} + +impl StorageEntryMetadataBuilder + for CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator, + Value: FullCodec + scale_info::StaticTypeInfo, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn build_metadata(docs: Vec<&'static str>, entries: &mut Vec) { + ::Map::build_metadata(docs, entries); + CounterFor::::build_metadata( + vec![&"Counter for the related counted storage map"], + entries, + ); + } +} + +impl crate::traits::StorageInfoTrait + for CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator + super::key::KeyGeneratorMaxEncodedLen, + Value: FullCodec + MaxEncodedLen, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn storage_info() -> Vec { + [::Map::storage_info(), CounterFor::::storage_info()].concat() + } +} + +/// It doesn't require to implement `MaxEncodedLen` and give no information for `max_size`. +impl crate::traits::PartialStorageInfoTrait + for CountedStorageNMap +where + Prefix: CountedStorageNMapInstance, + Key: super::key::KeyGenerator, + Value: FullCodec, + QueryKind: QueryKindTrait, + OnEmpty: Get + 'static, + MaxValues: Get>, +{ + fn partial_storage_info() -> Vec { + [ + ::Map::partial_storage_info(), + CounterFor::::partial_storage_info(), + ] + .concat() + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::{ + hash::{StorageHasher as _, *}, + metadata::{StorageEntryModifier, StorageHasher}, + storage::types::{Key as NMapKey, ValueQuery}, + }; + use sp_io::{hashing::twox_128, TestExternalities}; + + struct Prefix; + impl StorageInstance for Prefix { + fn pallet_prefix() -> &'static str { + "test" + } + const STORAGE_PREFIX: &'static str = "Foo"; + } + + struct ADefault; + impl crate::traits::Get for ADefault { + fn get() -> u32 { + 98 + } + } +} diff --git a/frame/support/src/storage/types/mod.rs b/frame/support/src/storage/types/mod.rs index bd5cec9299a7e..6921f250e6a97 100644 --- a/frame/support/src/storage/types/mod.rs +++ b/frame/support/src/storage/types/mod.rs @@ -24,6 +24,7 @@ use sp_std::prelude::*; mod counted_double_map; mod counted_map; +mod counted_nmap; mod double_map; mod key; mod map; @@ -32,6 +33,7 @@ mod value; pub use counted_double_map::{CountedStorageDoubleMap, CountedStorageDoubleMapInstance}; pub use counted_map::{CountedStorageMap, CountedStorageMapInstance}; +pub use counted_nmap::{CountedStorageNMap, CountedStorageNMapInstance}; pub use double_map::StorageDoubleMap; pub use key::{ EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, Key, KeyGenerator, diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index dcbdac761fe15..73b9176d12bb7 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Storage map type. Implements StorageDoubleMap, StorageIterableDoubleMap, -//! StoragePrefixedDoubleMap traits and their methods directly. +//! Storage map type. Implements StorageNMap, StorageIterableNMap, +//! StoragePrefixedNMap traits and their methods directly. use crate::{ metadata::{StorageEntryMetadata, StorageEntryType}, From 311534e175d974328ed1e2042cee10f372b11cc2 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Wed, 17 Aug 2022 23:36:04 +0300 Subject: [PATCH 18/50] add tests, fixes --- .../support/src/storage/types/counted_nmap.rs | 755 +++++++++++++++++- 1 file changed, 739 insertions(+), 16 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index e6e565f52a26c..abf6f9a401cfe 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -19,18 +19,19 @@ //! CountedStoragePrefixedNMap traits and their methods directly. use crate::{ - metadata::{StorageEntryMetadata, StorageEntryType}, + metadata::StorageEntryMetadata, storage::{ types::{ EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, OptionQuery, QueryKindTrait, - StorageEntryMetadataBuilder, StorageValue, TupleToEncodedIter, ValueQuery, + StorageEntryMetadataBuilder, StorageNMap, StorageValue, TupleToEncodedIter, ValueQuery, }, - KeyGenerator, PrefixIterator, StorageAppend, StorageDecodeLength, StoragePrefixedMap, + KeyGenerator, PrefixIterator, StorageAppend, StorageDecodeLength, }, traits::{Get, GetDefault, StorageInfo, StorageInstance}, + Never, }; -use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; -use sp_runtime::{traits::Saturating, SaturatedConversion}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; +use sp_runtime::traits::Saturating; use sp_std::prelude::*; /// A wrapper around a `StorageNMap` and a `StorageValue` to keep track of how many items @@ -68,7 +69,7 @@ trait MapWrapper { impl MapWrapper for CountedStorageNMap { - type Map = CountedStorageNMap; + type Map = StorageNMap; } type CounterFor

= @@ -274,7 +275,8 @@ where KArg: EncodeLikeTuple + TupleToEncodedIter, F: FnOnce(&mut QueryKind::Query) -> R, { - ::Map::mutate(key, f) + Self::try_mutate(key, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") } /// Mutate the value under the given keys when the closure returns `Ok`. @@ -283,7 +285,14 @@ where KArg: EncodeLikeTuple + TupleToEncodedIter, F: FnOnce(&mut QueryKind::Query) -> Result, { - ::Map::try_mutate(key, f) + Self::try_mutate_exists(key, |option_value_ref| { + let option_value = core::mem::replace(option_value_ref, None); + let mut query = QueryKind::from_optional_value_to_query(option_value); + let res = f(&mut query); + let option_value = QueryKind::from_query_to_optional_value(query); + let _ = core::mem::replace(option_value_ref, option_value); + res + }) } /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. @@ -292,7 +301,8 @@ where KArg: EncodeLikeTuple + TupleToEncodedIter, F: FnOnce(&mut Option) -> R, { - ::Map::mutate_exists(key, f) + Self::try_mutate_exists(key, |v| Ok::(f(v))) + .expect("`Never` can not be constructed; qed") } /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. @@ -481,7 +491,10 @@ where pub fn iter_prefix_from( kp: KP, starting_raw_key: Vec, - ) -> crate::storage::PrefixIterator<(>::Suffix, Value)> + ) -> crate::storage::PrefixIterator< + (>::Suffix, Value), + OnRemovalCounterUpdate, + > where Key: HasReversibleKeyPrefix, { @@ -523,7 +536,10 @@ where /// results. pub fn drain_prefix( kp: KP, - ) -> crate::storage::PrefixIterator<(>::Suffix, Value)> + ) -> crate::storage::PrefixIterator< + (>::Suffix, Value), + OnRemovalCounterUpdate, + > where Key: HasReversibleKeyPrefix, { @@ -533,7 +549,8 @@ where /// Enumerate all elements in the map in no particular order. /// /// If you add or remove values to the map while doing this, you'll get undefined results. - pub fn iter() -> crate::storage::PrefixIterator<(Key::Key, Value)> { + pub fn iter( + ) -> crate::storage::PrefixIterator<(Key::Key, Value), OnRemovalCounterUpdate> { ::Map::iter().convert_on_removal() } @@ -542,7 +559,7 @@ where /// If you add or remove values to the map while doing this, you'll get undefined results. pub fn iter_from( starting_raw_key: Vec, - ) -> crate::storage::PrefixIterator<(Key::Key, Value)> { + ) -> crate::storage::PrefixIterator<(Key::Key, Value), OnRemovalCounterUpdate> { ::Map::iter_from(starting_raw_key).convert_on_removal() } @@ -565,7 +582,8 @@ where /// Remove all elements from the map and iterate through them in no particular order. /// /// If you add elements to the map while doing this, you'll get undefined results. - pub fn drain() -> crate::storage::PrefixIterator<(Key::Key, Value)> { + pub fn drain( + ) -> crate::storage::PrefixIterator<(Key::Key, Value), OnRemovalCounterUpdate> { ::Map::drain().convert_on_removal() } @@ -644,7 +662,7 @@ mod test { use super::*; use crate::{ hash::{StorageHasher as _, *}, - metadata::{StorageEntryModifier, StorageHasher}, + metadata::{StorageEntryModifier, StorageEntryType, StorageHasher}, storage::types::{Key as NMapKey, ValueQuery}, }; use sp_io::{hashing::twox_128, TestExternalities}; @@ -656,11 +674,716 @@ mod test { } const STORAGE_PREFIX: &'static str = "Foo"; } + impl CountedStorageNMapInstance for Prefix { + type CounterPrefix = Prefix; + } - struct ADefault; + struct ADefault; impl crate::traits::Get for ADefault { fn get() -> u32 { 98 } } + + #[test] + fn test_1_key() { + type A = CountedStorageNMap, u32, OptionQuery>; + type AValueQueryWithAnOnEmpty = + CountedStorageNMap, u32, ValueQuery, ADefault>; + type B = CountedStorageNMap, u32, ValueQuery>; + type C = CountedStorageNMap, u8, ValueQuery>; + type WithLen = CountedStorageNMap, Vec>; + + TestExternalities::default().execute_with(|| { + let mut k: Vec = vec![]; + k.extend(&twox_128(b"test")); + k.extend(&twox_128(b"Foo")); + k.extend(&3u16.blake2_128_concat()); + assert_eq!(A::hashed_key_for((&3,)).to_vec(), k); + + assert_eq!(A::contains_key((3,)), false); + assert_eq!(A::get((3,)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 98); + assert_eq!(A::count(), 0); + + A::insert((3,), 10); + assert_eq!(A::contains_key((3,)), true); + assert_eq!(A::get((3,)), Some(10)); + assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 10); + assert_eq!(A::count(), 1); + + // { + // #[crate::storage_alias] + // type Foo = CountedStorageNMap), u32>; + + // assert_eq!(Foo::contains_key((3,)), true); + // assert_eq!(Foo::get((3,)), Some(10)); + // assert_eq!(A::count(), 1); + // } + + A::swap::, _, _>((3,), (2,)); + assert_eq!(A::contains_key((3,)), false); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((3,)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 98); + assert_eq!(A::get((2,)), Some(10)); + assert_eq!(AValueQueryWithAnOnEmpty::get((2,)), 10); + assert_eq!(A::count(), 1); + + A::remove((2,)); + assert_eq!(A::contains_key((2,)), false); + assert_eq!(A::get((2,)), None); + assert_eq!(A::count(), 0); + + AValueQueryWithAnOnEmpty::mutate((2,), |v| *v = *v * 2); + AValueQueryWithAnOnEmpty::mutate((2,), |v| *v = *v * 2); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(98 * 4)); + assert_eq!(A::count(), 1); + + A::remove((2,)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2,), |v| { + *v = *v * 2; + Ok(()) + }); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2,), |v| { + *v = *v * 2; + Ok(()) + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(98 * 4)); + assert_eq!(A::count(), 1); + + A::remove((2,)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2,), |v| { + *v = *v * 2; + Err(()) + }); + assert_eq!(A::contains_key((2,)), false); + assert_eq!(A::count(), 0); + + A::remove((2,)); + AValueQueryWithAnOnEmpty::mutate_exists((2,), |v| { + assert!(v.is_none()); + *v = Some(10); + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(10)); + AValueQueryWithAnOnEmpty::mutate_exists((2,), |v| { + *v = Some(v.unwrap() * 10); + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(100)); + assert_eq!(A::count(), 1); + + A::remove((2,)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2,), |v| { + assert!(v.is_none()); + *v = Some(10); + Ok(()) + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(10)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2,), |v| { + *v = Some(v.unwrap() * 10); + Ok(()) + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(100)); + assert_eq!(A::try_get((2,)), Ok(100)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2,), |v| { + *v = Some(v.unwrap() * 10); + Err(()) + }); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(100)); + assert_eq!(A::count(), 1); + + A::insert((2,), 10); + assert_eq!(A::take((2,)), Some(10)); + assert_eq!(A::contains_key((2,)), false); + assert_eq!(AValueQueryWithAnOnEmpty::take((2,)), 98); + assert_eq!(A::contains_key((2,)), false); + assert_eq!(A::try_get((2,)), Err(())); + assert_eq!(A::count(), 0); + + B::insert((2,), 10); + assert_eq!( + A::migrate_keys((2,), (Box::new(|key| Blake2_256::hash(key).to_vec()),),), + Some(10) + ); + assert_eq!(A::contains_key((2,)), true); + assert_eq!(A::get((2,)), Some(10)); + assert_eq!(A::count(), 1); + + A::insert((3,), 10); + A::insert((4,), 10); + let _ = A::clear(u32::max_value(), None); + assert_eq!(A::contains_key((3,)), false); + assert_eq!(A::contains_key((4,)), false); + assert_eq!(A::count(), 0); + + A::insert((3,), 10); + A::insert((4,), 10); + assert_eq!(A::iter_values().collect::>(), vec![10, 10]); + assert_eq!(A::count(), 2); + + C::insert((3,), 10); + C::insert((4,), 10); + A::translate_values::(|v| Some((v * 2).into())); + assert_eq!(A::iter().collect::>(), vec![(4, 20), (3, 20)]); + assert_eq!(A::count(), 2); + + A::insert((3,), 10); + A::insert((4,), 10); + assert_eq!(A::iter().collect::>(), vec![(4, 10), (3, 10)]); + assert_eq!(A::drain().collect::>(), vec![(4, 10), (3, 10)]); + assert_eq!(A::iter().collect::>(), vec![]); + assert_eq!(A::count(), 0); + + C::insert((3,), 10); + C::insert((4,), 10); + A::translate::(|k1, v| Some((k1 as u16 * v as u16).into())); + assert_eq!(A::iter().collect::>(), vec![(4, 40), (3, 30)]); + assert_eq!(A::count(), 2); + + let mut entries = vec![]; + A::build_metadata(vec![], &mut entries); + AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); + // TODO: fix metadata test + // assert_eq!( + // entries, + // vec![ + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Optional, + // ty: StorageEntryType::Map { + // hashers: vec![StorageHasher::Blake2_128Concat], + // key: scale_info::meta_type::(), + // value: scale_info::meta_type::(), + // }, + // default: Option::::None.encode(), + // docs: vec![], + // }, + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Default, + // ty: StorageEntryType::Map { + // hashers: vec![StorageHasher::Blake2_128Concat], + // key: scale_info::meta_type::(), + // value: scale_info::meta_type::(), + // }, + // default: 98u32.encode(), + // docs: vec![], + // } + // ] + // ); + + let _ = WithLen::clear(u32::max_value(), None); + assert_eq!(WithLen::decode_len((3,)), None); + WithLen::append((0,), 10); + assert_eq!(WithLen::decode_len((0,)), Some(1)); + }); + } + + #[test] + fn test_2_keys() { + type A = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey), + u32, + OptionQuery, + >; + type AValueQueryWithAnOnEmpty = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey), + u32, + ValueQuery, + ADefault, + >; + type B = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey), + u32, + ValueQuery, + >; + type C = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey), + u8, + ValueQuery, + >; + type WithLen = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey), + Vec, + >; + + TestExternalities::default().execute_with(|| { + let mut k: Vec = vec![]; + k.extend(&twox_128(b"test")); + k.extend(&twox_128(b"Foo")); + k.extend(&3u16.blake2_128_concat()); + k.extend(&30u8.twox_64_concat()); + assert_eq!(A::hashed_key_for((3, 30)).to_vec(), k); + + assert_eq!(A::contains_key((3, 30)), false); + assert_eq!(A::get((3, 30)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((3, 30)), 98); + assert_eq!(A::count(), 0); + + A::insert((3, 30), 10); + assert_eq!(A::contains_key((3, 30)), true); + assert_eq!(A::get((3, 30)), Some(10)); + assert_eq!(AValueQueryWithAnOnEmpty::get((3, 30)), 10); + assert_eq!(A::count(), 1); + + A::swap::<(NMapKey, NMapKey), _, _>( + (3, 30), + (2, 20), + ); + assert_eq!(A::contains_key((3, 30)), false); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((3, 30)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((3, 30)), 98); + assert_eq!(A::get((2, 20)), Some(10)); + assert_eq!(AValueQueryWithAnOnEmpty::get((2, 20)), 10); + assert_eq!(A::count(), 1); + + A::remove((2, 20)); + assert_eq!(A::contains_key((2, 20)), false); + assert_eq!(A::get((2, 20)), None); + assert_eq!(A::count(), 0); + + AValueQueryWithAnOnEmpty::mutate((2, 20), |v| *v = *v * 2); + AValueQueryWithAnOnEmpty::mutate((2, 20), |v| *v = *v * 2); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(98 * 4)); + assert_eq!(A::count(), 1); + + A::remove((2, 20)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2, 20), |v| { + *v = *v * 2; + Err(()) + }); + assert_eq!(A::contains_key((2, 20)), false); + assert_eq!(A::count(), 0); + + A::remove((2, 20)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2, 20), |v| { + *v = *v * 2; + Err(()) + }); + assert_eq!(A::contains_key((2, 20)), false); + assert_eq!(A::count(), 0); + + A::remove((2, 20)); + AValueQueryWithAnOnEmpty::mutate_exists((2, 20), |v| { + assert!(v.is_none()); + *v = Some(10); + }); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(10)); + assert_eq!(A::count(), 1); + AValueQueryWithAnOnEmpty::mutate_exists((2, 20), |v| { + *v = Some(v.unwrap() * 10); + }); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(100)); + assert_eq!(A::count(), 1); + + A::remove((2, 20)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20), |v| { + assert!(v.is_none()); + *v = Some(10); + Ok(()) + }); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(10)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20), |v| { + *v = Some(v.unwrap() * 10); + Ok(()) + }); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(100)); + assert_eq!(A::try_get((2, 20)), Ok(100)); + assert_eq!(A::count(), 1); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20), |v| { + *v = Some(v.unwrap() * 10); + Err(()) + }); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(100)); + assert_eq!(A::count(), 1); + + A::insert((2, 20), 10); + assert_eq!(A::take((2, 20)), Some(10)); + assert_eq!(A::contains_key((2, 20)), false); + assert_eq!(AValueQueryWithAnOnEmpty::take((2, 20)), 98); + assert_eq!(A::contains_key((2, 20)), false); + assert_eq!(A::try_get((2, 20)), Err(())); + assert_eq!(A::count(), 0); + + B::insert((2, 20), 10); + assert_eq!( + A::migrate_keys( + (2, 20), + ( + Box::new(|key| Blake2_256::hash(key).to_vec()), + Box::new(|key| Twox128::hash(key).to_vec()), + ), + ), + Some(10) + ); + assert_eq!(A::contains_key((2, 20)), true); + assert_eq!(A::get((2, 20)), Some(10)); + assert_eq!(A::count(), 1); + + A::insert((3, 30), 10); + A::insert((4, 40), 10); + let _ = A::clear(u32::max_value(), None); + assert_eq!(A::contains_key((3, 30)), false); + assert_eq!(A::contains_key((4, 40)), false); + assert_eq!(A::count(), 0); + + A::insert((3, 30), 10); + A::insert((4, 40), 10); + assert_eq!(A::iter_values().collect::>(), vec![10, 10]); + assert_eq!(A::count(), 2); + + C::insert((3, 30), 10); + C::insert((4, 40), 10); + A::translate_values::(|v| Some((v * 2).into())); + assert_eq!(A::iter().collect::>(), vec![((4, 40), 20), ((3, 30), 20)]); + assert_eq!(A::count(), 2); + + A::insert((3, 30), 10); + A::insert((4, 40), 10); + assert_eq!(A::iter().collect::>(), vec![((4, 40), 10), ((3, 30), 10)]); + assert_eq!(A::drain().collect::>(), vec![((4, 40), 10), ((3, 30), 10)]); + assert_eq!(A::iter().collect::>(), vec![]); + assert_eq!(A::count(), 0); + + C::insert((3, 30), 10); + C::insert((4, 40), 10); + A::translate::(|(k1, k2), v| Some((k1 * k2 as u16 * v as u16).into())); + assert_eq!(A::iter().collect::>(), vec![((4, 40), 1600), ((3, 30), 900)]); + assert_eq!(A::count(), 2); + + let mut entries = vec![]; + A::build_metadata(vec![], &mut entries); + AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); + // TODO: fix metadata + // assert_eq!( + // entries, + // vec![ + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Optional, + // ty: StorageEntryType::Map { + // hashers: vec![ + // StorageHasher::Blake2_128Concat, + // StorageHasher::Twox64Concat + // ], + // key: scale_info::meta_type::<(u16, u8)>(), + // value: scale_info::meta_type::(), + // }, + // default: Option::::None.encode(), + // docs: vec![], + // }, + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Default, + // ty: StorageEntryType::Map { + // hashers: vec![ + // StorageHasher::Blake2_128Concat, + // StorageHasher::Twox64Concat + // ], + // key: scale_info::meta_type::<(u16, u8)>(), + // value: scale_info::meta_type::(), + // }, + // default: 98u32.encode(), + // docs: vec![], + // } + // ] + // ); + + let _ = WithLen::clear(u32::max_value(), None); + assert_eq!(WithLen::decode_len((3, 30)), None); + WithLen::append((0, 100), 10); + assert_eq!(WithLen::decode_len((0, 100)), Some(1)); + + A::insert((3, 30), 11); + A::insert((3, 31), 12); + A::insert((4, 40), 13); + A::insert((4, 41), 14); + assert_eq!(A::iter_prefix_values((3,)).collect::>(), vec![12, 11]); + assert_eq!(A::iter_prefix_values((4,)).collect::>(), vec![13, 14]); + assert_eq!(A::count(), 5); + }); + } + + #[test] + fn test_3_keys() { + type A = CountedStorageNMap< + Prefix, + ( + NMapKey, + NMapKey, + NMapKey, + ), + u32, + OptionQuery, + >; + type AValueQueryWithAnOnEmpty = CountedStorageNMap< + Prefix, + ( + NMapKey, + NMapKey, + NMapKey, + ), + u32, + ValueQuery, + ADefault, + >; + type B = CountedStorageNMap< + Prefix, + (NMapKey, NMapKey, NMapKey), + u32, + ValueQuery, + >; + type C = CountedStorageNMap< + Prefix, + ( + NMapKey, + NMapKey, + NMapKey, + ), + u8, + ValueQuery, + >; + type WithLen = CountedStorageNMap< + Prefix, + ( + NMapKey, + NMapKey, + NMapKey, + ), + Vec, + >; + + TestExternalities::default().execute_with(|| { + let mut k: Vec = vec![]; + k.extend(&twox_128(b"test")); + k.extend(&twox_128(b"Foo")); + k.extend(&1u16.blake2_128_concat()); + k.extend(&10u16.blake2_128_concat()); + k.extend(&100u16.twox_64_concat()); + assert_eq!(A::hashed_key_for((1, 10, 100)).to_vec(), k); + + assert_eq!(A::contains_key((1, 10, 100)), false); + assert_eq!(A::get((1, 10, 100)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((1, 10, 100)), 98); + assert_eq!(A::count(), 0); + + A::insert((1, 10, 100), 30); + assert_eq!(A::contains_key((1, 10, 100)), true); + assert_eq!(A::get((1, 10, 100)), Some(30)); + assert_eq!(AValueQueryWithAnOnEmpty::get((1, 10, 100)), 30); + assert_eq!(A::count(), 1); + + A::swap::< + ( + NMapKey, + NMapKey, + NMapKey, + ), + _, + _, + >((1, 10, 100), (2, 20, 200)); + assert_eq!(A::contains_key((1, 10, 100)), false); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((1, 10, 100)), None); + assert_eq!(AValueQueryWithAnOnEmpty::get((1, 10, 100)), 98); + assert_eq!(A::get((2, 20, 200)), Some(30)); + assert_eq!(AValueQueryWithAnOnEmpty::get((2, 20, 200)), 30); + assert_eq!(A::count(), 1); + + A::remove((2, 20, 200)); + assert_eq!(A::contains_key((2, 20, 200)), false); + assert_eq!(A::get((2, 20, 200)), None); + assert_eq!(A::count(), 0); + + AValueQueryWithAnOnEmpty::mutate((2, 20, 200), |v| *v = *v * 2); + AValueQueryWithAnOnEmpty::mutate((2, 20, 200), |v| *v = *v * 2); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(98 * 4)); + assert_eq!(A::count(), 1); + + A::remove((2, 20, 200)); + let _: Result<(), ()> = AValueQueryWithAnOnEmpty::try_mutate((2, 20, 200), |v| { + *v = *v * 2; + Err(()) + }); + assert_eq!(A::contains_key((2, 20, 200)), false); + assert_eq!(A::count(), 0); + + A::remove((2, 20, 200)); + AValueQueryWithAnOnEmpty::mutate_exists((2, 20, 200), |v| { + assert!(v.is_none()); + *v = Some(10); + }); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(10)); + assert_eq!(A::count(), 1); + AValueQueryWithAnOnEmpty::mutate_exists((2, 20, 200), |v| { + *v = Some(v.unwrap() * 10); + }); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(100)); + assert_eq!(A::count(), 1); + + A::remove((2, 20, 200)); + let _: Result<(), ()> = + AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20, 200), |v| { + assert!(v.is_none()); + *v = Some(10); + Ok(()) + }); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(10)); + let _: Result<(), ()> = + AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20, 200), |v| { + *v = Some(v.unwrap() * 10); + Ok(()) + }); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(100)); + assert_eq!(A::try_get((2, 20, 200)), Ok(100)); + assert_eq!(A::count(), 1); + let _: Result<(), ()> = + AValueQueryWithAnOnEmpty::try_mutate_exists((2, 20, 200), |v| { + *v = Some(v.unwrap() * 10); + Err(()) + }); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(100)); + assert_eq!(A::count(), 1); + + A::insert((2, 20, 200), 10); + assert_eq!(A::take((2, 20, 200)), Some(10)); + assert_eq!(A::contains_key((2, 20, 200)), false); + assert_eq!(AValueQueryWithAnOnEmpty::take((2, 20, 200)), 98); + assert_eq!(A::contains_key((2, 20, 200)), false); + assert_eq!(A::try_get((2, 20, 200)), Err(())); + assert_eq!(A::count(), 0); + + B::insert((2, 20, 200), 10); + assert_eq!( + A::migrate_keys( + (2, 20, 200), + ( + Box::new(|key| Blake2_256::hash(key).to_vec()), + Box::new(|key| Blake2_256::hash(key).to_vec()), + Box::new(|key| Twox128::hash(key).to_vec()), + ), + ), + Some(10) + ); + assert_eq!(A::contains_key((2, 20, 200)), true); + assert_eq!(A::get((2, 20, 200)), Some(10)); + assert_eq!(A::count(), 1); + + A::insert((3, 30, 300), 10); + A::insert((4, 40, 400), 10); + let _ = A::clear(u32::max_value(), None); + assert_eq!(A::contains_key((3, 30, 300)), false); + assert_eq!(A::contains_key((4, 40, 400)), false); + assert_eq!(A::count(), 0); + + A::insert((3, 30, 300), 10); + A::insert((4, 40, 400), 10); + assert_eq!(A::iter_values().collect::>(), vec![10, 10]); + assert_eq!(A::count(), 2); + + C::insert((3, 30, 300), 10); + C::insert((4, 40, 400), 10); + A::translate_values::(|v| Some((v * 2).into())); + assert_eq!(A::iter().collect::>(), vec![((4, 40, 400), 20), ((3, 30, 300), 20)]); + assert_eq!(A::count(), 2); + + A::insert((3, 30, 300), 10); + A::insert((4, 40, 400), 10); + assert_eq!(A::iter().collect::>(), vec![((4, 40, 400), 10), ((3, 30, 300), 10)]); + assert_eq!( + A::drain().collect::>(), + vec![((4, 40, 400), 10), ((3, 30, 300), 10)] + ); + assert_eq!(A::iter().collect::>(), vec![]); + assert_eq!(A::count(), 0); + + C::insert((3, 30, 300), 10); + C::insert((4, 40, 400), 10); + A::translate::(|(k1, k2, k3), v| { + Some((k1 * k2 as u16 * v as u16 / k3 as u16).into()) + }); + assert_eq!(A::iter().collect::>(), vec![((4, 40, 400), 4), ((3, 30, 300), 3)]); + assert_eq!(A::count(), 2); + + let mut entries = vec![]; + A::build_metadata(vec![], &mut entries); + AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); + // TODO: fix metadata + // assert_eq!( + // entries, + // vec![ + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Optional, + // ty: StorageEntryType::Map { + // hashers: vec![ + // StorageHasher::Blake2_128Concat, + // StorageHasher::Blake2_128Concat, + // StorageHasher::Twox64Concat + // ], + // key: scale_info::meta_type::<(u16, u16, u16)>(), + // value: scale_info::meta_type::(), + // }, + // default: Option::::None.encode(), + // docs: vec![], + // }, + // StorageEntryMetadata { + // name: "Foo", + // modifier: StorageEntryModifier::Default, + // ty: StorageEntryType::Map { + // hashers: vec![ + // StorageHasher::Blake2_128Concat, + // StorageHasher::Blake2_128Concat, + // StorageHasher::Twox64Concat + // ], + // key: scale_info::meta_type::<(u16, u16, u16)>(), + // value: scale_info::meta_type::(), + // }, + // default: 98u32.encode(), + // docs: vec![], + // } + // ] + // ); + + let _ = WithLen::clear(u32::max_value(), None); + assert_eq!(WithLen::decode_len((3, 30, 300)), None); + WithLen::append((0, 100, 1000), 10); + assert_eq!(WithLen::decode_len((0, 100, 1000)), Some(1)); + + A::insert((3, 30, 300), 11); + A::insert((3, 30, 301), 12); + A::insert((4, 40, 400), 13); + A::insert((4, 40, 401), 14); + assert_eq!(A::iter_prefix_values((3,)).collect::>(), vec![11, 12]); + assert_eq!(A::iter_prefix_values((4,)).collect::>(), vec![14, 13]); + assert_eq!(A::iter_prefix_values((3, 30)).collect::>(), vec![11, 12]); + assert_eq!(A::iter_prefix_values((4, 40)).collect::>(), vec![14, 13]); + assert_eq!(A::count(), 5); + }); + } } From 050d18289e4bd86ee35a9f748e1d52ea792a87b0 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Wed, 17 Aug 2022 23:39:13 +0300 Subject: [PATCH 19/50] remove counted double map impl --- .../src/storage/types/counted_double_map.rs | 1266 ----------------- frame/support/src/storage/types/mod.rs | 2 - 2 files changed, 1268 deletions(-) delete mode 100644 frame/support/src/storage/types/counted_double_map.rs diff --git a/frame/support/src/storage/types/counted_double_map.rs b/frame/support/src/storage/types/counted_double_map.rs deleted file mode 100644 index a85ea5d41441f..0000000000000 --- a/frame/support/src/storage/types/counted_double_map.rs +++ /dev/null @@ -1,1266 +0,0 @@ -use crate::{ - metadata::StorageEntryMetadata, - storage::{ - types::{ - OptionQuery, QueryKindTrait, StorageDoubleMap, StorageEntryMetadataBuilder, - StorageValue, ValueQuery, - }, - StorageAppend, StorageDecodeLength, StorageTryAppend, - }, - traits::{ - Get, GetDefault, PartialStorageInfoTrait, StorageInfo, StorageInfoTrait, StorageInstance, - }, - Never, -}; -use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; -use sp_runtime::traits::Saturating; -use sp_std::prelude::*; - -pub struct CountedStorageDoubleMap< - Prefix, - Hasher1, - Key1, - Hasher2, - Key2, - Value, - QueryKind = OptionQuery, - OnEmpty = GetDefault, - MaxValues = GetDefault, ->( - core::marker::PhantomData<( - Prefix, - Hasher1, - Key1, - Hasher2, - Key2, - Value, - QueryKind, - OnEmpty, - MaxValues, - )>, -); - -/// The requirement for an instance of [`CountedStorageDoubleMap`]. -pub trait CountedStorageDoubleMapInstance: StorageInstance { - /// The prefix to use for the counter storage value. - type CounterPrefix: StorageInstance; -} - -// Private helper trait to access map from counted storage double map -trait MapWrapper { - type Map; -} - -impl MapWrapper - for CountedStorageDoubleMap -{ - type Map = StorageDoubleMap; -} - -type CounterFor

= - StorageValue<

::CounterPrefix, u32, ValueQuery>; - -/// On removal logic for updating counter while draining upon some prefix with -/// [`crate::storage::PrefixIterator`]. -pub struct OnRemovalCounterUpdate(core::marker::PhantomData); - -impl crate::storage::PrefixIteratorOnRemoval - for OnRemovalCounterUpdate -{ - fn on_removal(_key: &[u8], _value: &[u8]) { - CounterFor::::mutate(|value| value.saturating_dec()); - } -} - -impl - CountedStorageDoubleMap -where - Prefix: CountedStorageDoubleMapInstance, - Hasher1: crate::hash::StorageHasher, - Key1: FullCodec, - Hasher2: crate::hash::StorageHasher, - Key2: FullCodec, - Value: FullCodec, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - /// The key used to store the counter of the map. - pub fn counter_storage_final_key() -> [u8; 32] { - CounterFor::::hashed_key() - } - - /// The prefix used to generate the key of the map. - pub fn map_storage_final_prefix() -> Vec { - use crate::storage::generator::StorageDoubleMap; - ::Map::prefix_hash() - } - - /// Get the storage key used to fetch a value corresponding to a specific key. - pub fn hashed_key_for(k1: KArg1, k2: KArg2) -> Vec - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - ::Map::hashed_key_for(k1, k2) - } - - /// Does the value (explicitly) exist in storage? - pub fn contains_key(k1: KArg1, k2: KArg2) -> bool - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - ::Map::contains_key(k1, k2) - } - - /// Load the value associated with the given key from the double map. - pub fn get(k1: KArg1, k2: KArg2) -> QueryKind::Query - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - ::Map::get(k1, k2) - } - - /// Try to get the value for the given key from the double map. - /// - /// Returns `Ok` if it exists, `Err` if not. - pub fn try_get(k1: KArg1, k2: KArg2) -> Result - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - ::Map::try_get(k1, k2) - } - - /// Take a value from storage, removing it afterwards. - pub fn take(k1: KArg1, k2: KArg2) -> QueryKind::Query - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - let removed_value = ::Map::mutate_exists(k1, k2, |value| { - core::mem::replace(value, None) - }); - if removed_value.is_some() { - CounterFor::::mutate(|value| value.saturating_dec()); - } - QueryKind::from_optional_value_to_query(removed_value) - } - - /// Swap the values of two key-pairs. - pub fn swap( - x_k1: XKArg1, - x_k2: XKArg2, - y_k1: YKArg1, - y_k2: YKArg2, - ) where - XKArg1: EncodeLike, - XKArg2: EncodeLike, - YKArg1: EncodeLike, - YKArg2: EncodeLike, - { - ::Map::swap(x_k1, x_k2, y_k1, y_k2) - } - - /// Store a value to be associated with the given keys from the double map. - pub fn insert(k1: KArg1, k2: KArg2, val: VArg) - where - KArg1: EncodeLike, - KArg2: EncodeLike, - VArg: EncodeLike, - { - if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { - CounterFor::::mutate(|value| value.saturating_inc()); - } - ::Map::insert(k1, k2, val) - } - - /// Remove the value under the given keys. - pub fn remove(k1: KArg1, k2: KArg2) - where - KArg1: EncodeLike, - KArg2: EncodeLike, - { - if ::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { - CounterFor::::mutate(|value| value.saturating_dec()); - } - ::Map::remove(k1, k2) - } - - /// Remove all values under the first key. - /// - /// # Warning - /// - /// Expensive operation, need to iterate over all 'k1' prefixes to calculate how many values - /// need to remove - pub fn remove_prefix(k1: KArg1) - where - KArg1: ?Sized + EncodeLike, - { - let mut on_remove = 0; - Self::iter_prefix_values(Ref::from(&k1)).for_each(|_| { - on_remove += 1; - }); - CounterFor::::mutate(|value| { - *value = value.saturating_sub(on_remove); - }); - ::Map::remove_prefix(k1, None); - } - - /// Iterate over values that share the first key. - pub fn iter_prefix_values( - k1: KArg1, - ) -> crate::storage::PrefixIterator> - where - KArg1: ?Sized + EncodeLike, - { - ::Map::iter_prefix_values(k1).convert_on_removal() - } - - /// Mutate the value under the given keys. - pub fn mutate(k1: KArg1, k2: KArg2, f: F) -> R - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut QueryKind::Query) -> R, - { - Self::try_mutate(k1, k2, |v| Ok::(f(v))) - .expect("`Never` can not be constructed; qed") - } - - /// Mutate the value under the given keys when the closure returns `Ok`. - pub fn try_mutate(k1: KArg1, k2: KArg2, f: F) -> Result - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut QueryKind::Query) -> Result, - { - Self::try_mutate_exists(k1, k2, |option_value_ref| { - let option_value = core::mem::replace(option_value_ref, None); - let mut query = QueryKind::from_optional_value_to_query(option_value); - let res = f(&mut query); - let option_value = QueryKind::from_query_to_optional_value(query); - let _ = core::mem::replace(option_value_ref, option_value); - res - }) - } - - /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. - pub fn mutate_exists(k1: KArg1, k2: KArg2, f: F) -> R - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut Option) -> R, - { - Self::try_mutate_exists(k1, k2, |v| Ok::(f(v))) - .expect("`Never` can not be constructed; qed") - } - - /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - pub fn try_mutate_exists(k1: KArg1, k2: KArg2, f: F) -> Result - where - KArg1: EncodeLike, - KArg2: EncodeLike, - F: FnOnce(&mut Option) -> Result, - { - ::Map::try_mutate_exists(k1, k2, |option_value| { - let existed = option_value.is_some(); - let res = f(option_value); - let exist = option_value.is_some(); - - if res.is_ok() { - if existed && !exist { - // Value was deleted - CounterFor::::mutate(|value| value.saturating_dec()); - } else if !existed && exist { - // Value was added - CounterFor::::mutate(|value| value.saturating_inc()); - } - } - res - }) - } - - /// Append the given item to the value in the storage. - /// - /// `Value` is required to implement [`StorageAppend`]. - /// - /// # Warning - /// - /// If the storage item is not encoded properly, the storage will be overwritten - /// and set to `[item]`. Any default value set for the storage item will be ignored - /// on overwrite. - pub fn append(k1: KArg1, k2: KArg2, item: EncodeLikeItem) - where - KArg1: EncodeLike, - KArg2: EncodeLike, - Item: Encode, - EncodeLikeItem: EncodeLike, - Value: StorageAppend, - { - if !::Map::contains_key(Ref::from(&k1), Ref::from(&k2)) { - CounterFor::::mutate(|value| value.saturating_inc()); - } - ::Map::append(k1, k2, item) - } - - /// Read the length of the storage value without decoding the entire value under the - /// given `key1` and `key2`. - /// - /// `Value` is required to implement [`StorageDecodeLength`]. - /// - /// If the value does not exists or it fails to decode the length, `None` is returned. - /// Otherwise `Some(len)` is returned. - /// - /// # Warning - /// - /// `None` does not mean that `get()` does not return a value. The default value is completly - /// ignored by this function. - pub fn decode_len(key1: KArg1, key2: KArg2) -> Option - where - KArg1: EncodeLike, - KArg2: EncodeLike, - Value: StorageDecodeLength, - { - ::Map::decode_len(key1, key2) - } - - /// Migrate an item with the given `key1` and `key2` from defunct `OldHasher1` and - /// `OldHasher2` to the current hashers. - /// - /// If the key doesn't exist, then it's a no-op. If it does, then it returns its value. - pub fn migrate_keys< - OldHasher1: crate::StorageHasher, - OldHasher2: crate::StorageHasher, - KeyArg1: EncodeLike, - KeyArg2: EncodeLike, - >( - key1: KeyArg1, - key2: KeyArg2, - ) -> Option { - ::Map::migrate_keys::(key1, key2) - } - - /// Remove all value of the storage. - pub fn remove_all() { - // NOTE: it is not possible to remove up to some limit because - // `sp_io::storage::clear_prefix` and `StorageMap::remove_all` don't give the number of - // value removed from the overlay. - CounterFor::::set(0u32); - ::Map::remove_all(None); - } - - /// Iter over all value of the storage. - /// - /// NOTE: If a value failed to decode because storage is corrupted then it is skipped. - pub fn iter_values() -> crate::storage::PrefixIterator> { - ::Map::iter_values().convert_on_removal() - } - - /// Translate the values of all elements by a function `f`, in the map in no particular order. - /// By returning `None` from `f` for an element, you'll remove it from the map. - /// - /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. - /// - /// # Warning - /// - /// This function must be used with care, before being updated the storage still contains the - /// old type, thus other calls (such as `get`) will fail at decoding it. - /// - /// # Usage - /// - /// This would typically be called inside the module implementation of on_runtime_upgrade. - pub fn translate_values Option>(mut f: F) { - ::Map::translate_values(|old_value| { - let res = f(old_value); - if res.is_none() { - CounterFor::::mutate(|value| value.saturating_dec()); - } - res - }) - } - - /// Try and append the given item to the value in the storage. - /// - /// Is only available if `Value` of the storage implements [`StorageTryAppend`]. - pub fn try_append( - key1: KArg1, - key2: KArg2, - item: EncodeLikeItem, - ) -> Result<(), ()> - where - KArg1: EncodeLike + Clone, - KArg2: EncodeLike + Clone, - Item: Encode, - EncodeLikeItem: EncodeLike, - Value: StorageTryAppend, - { - let bound = Value::bound(); - let current = ::Map::decode_len(Ref::from(&key1), Ref::from(&key2)) - .unwrap_or_default(); - if current < bound { - CounterFor::::mutate(|value| value.saturating_inc()); - let key = ::Map::hashed_key_for(key1, key2); - sp_io::storage::append(&key, item.encode()); - Ok(()) - } else { - Err(()) - } - } - - /// Initialize the counter with the actual number of items in the map. - /// - /// This function iterates through all the items in the map and sets the counter. This operation - /// can be very heavy, so use with caution. - /// - /// Returns the number of items in the map which is used to set the counter. - pub fn initialize_counter() -> u32 { - let count = Self::iter_values().count() as u32; - CounterFor::::set(count); - count - } - - /// Return the count. - pub fn count() -> u32 { - CounterFor::::get() - } -} - -impl - CountedStorageDoubleMap -where - Prefix: CountedStorageDoubleMapInstance, - Hasher1: crate::hash::StorageHasher + crate::ReversibleStorageHasher, - Key1: FullCodec, - Hasher2: crate::hash::StorageHasher + crate::ReversibleStorageHasher, - Key2: FullCodec, - Value: FullCodec, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - /// Enumerate all elements in the map with first key `k1` in no particular order. - /// - /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get - /// undefined results. - pub fn iter_prefix( - k1: impl EncodeLike, - ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - ::Map::iter_prefix(k1).convert_on_removal() - } - - /// Enumerate all elements in the map with first key `k1` after a specified `starting_raw_key` - /// in no particular order. - /// - /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get - /// undefined results. - pub fn iter_prefix_from( - k1: impl EncodeLike, - starting_raw_key: Vec, - ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - ::Map::iter_prefix_from(k1, starting_raw_key).convert_on_removal() - } - - /// Enumerate all second keys `k2` in the map with the same first key `k1` in no particular - /// order. - /// - /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get - /// undefined results. - pub fn iter_key_prefix(k1: impl EncodeLike) -> crate::storage::KeyPrefixIterator { - ::Map::iter_key_prefix(k1) - } - - /// Enumerate all second keys `k2` in the map with the same first key `k1` after a specified - /// `starting_raw_key` in no particular order. - /// - /// If you add or remove values whose first key is `k1` to the map while doing this, you'll get - /// undefined results. - pub fn iter_key_prefix_from( - k1: impl EncodeLike, - starting_raw_key: Vec, - ) -> crate::storage::KeyPrefixIterator { - ::Map::iter_key_prefix_from(k1, starting_raw_key) - } - - /// Remove all elements from the map with first key `k1` and iterate through them in no - /// particular order. - /// - /// If you add elements with first key `k1` to the map while doing this, you'll get undefined - /// results. - pub fn drain_prefix( - k1: impl EncodeLike, - ) -> crate::storage::PrefixIterator<(Key2, Value), OnRemovalCounterUpdate> { - ::Map::drain_prefix(k1).convert_on_removal() - } - - /// Enumerate all elements in the map in no particular order. - /// - /// If you add or remove values to the map while doing this, you'll get undefined results. - pub fn iter( - ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - ::Map::iter().convert_on_removal() - } - - /// Enumerate all elements in the map after a specified `starting_raw_key` in no particular - /// order. - /// - /// If you add or remove values to the map while doing this, you'll get undefined results. - pub fn iter_from( - starting_raw_key: Vec, - ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - ::Map::iter_from(starting_raw_key).convert_on_removal() - } - - /// Enumerate all keys `k1` and `k2` in the map in no particular order. - /// - /// If you add or remove values to the map while doing this, you'll get undefined results. - pub fn iter_keys() -> crate::storage::KeyPrefixIterator<(Key1, Key2)> { - ::Map::iter_keys() - } - - /// Enumerate all keys `k1` and `k2` in the map after a specified `starting_raw_key` in no - /// particular order. - /// - /// If you add or remove values to the map while doing this, you'll get undefined results. - pub fn iter_keys_from( - starting_raw_key: Vec, - ) -> crate::storage::KeyPrefixIterator<(Key1, Key2)> { - ::Map::iter_keys_from(starting_raw_key) - } - - /// Remove all elements from the map and iterate through them in no particular order. - /// - /// If you add elements to the map while doing this, you'll get undefined results. - pub fn drain( - ) -> crate::storage::PrefixIterator<(Key1, Key2, Value), OnRemovalCounterUpdate> { - ::Map::drain().convert_on_removal() - } - - /// Translate the values of all elements by a function `f`, in the map in no particular order. - /// - /// By returning `None` from `f` for an element, you'll remove it from the map. - /// - /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. - pub fn translate Option>(mut f: F) { - ::Map::translate(|k1, k2, old_value| { - let res = f(k1, k2, old_value); - if res.is_none() { - CounterFor::::mutate(|value| value.saturating_dec()); - } - res - }) - } -} - -impl - StorageEntryMetadataBuilder - for CountedStorageDoubleMap< - Prefix, - Hasher1, - Key1, - Hasher2, - Key2, - Value, - QueryKind, - OnEmpty, - MaxValues, - > where - Prefix: CountedStorageDoubleMapInstance, - Hasher1: crate::hash::StorageHasher, - Hasher2: crate::hash::StorageHasher, - Key1: FullCodec + scale_info::StaticTypeInfo, - Key2: FullCodec + scale_info::StaticTypeInfo, - Value: FullCodec + scale_info::StaticTypeInfo, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - fn build_metadata(docs: Vec<&'static str>, entries: &mut Vec) { - ::Map::build_metadata(docs, entries); - CounterFor::::build_metadata( - vec![&"Counter for the related counted storage map"], - entries, - ); - } -} - -impl StorageInfoTrait - for CountedStorageDoubleMap< - Prefix, - Hasher1, - Key1, - Hasher2, - Key2, - Value, - QueryKind, - OnEmpty, - MaxValues, - > where - Prefix: CountedStorageDoubleMapInstance, - Hasher1: crate::hash::StorageHasher, - Hasher2: crate::hash::StorageHasher, - Key1: FullCodec + MaxEncodedLen, - Key2: FullCodec + MaxEncodedLen, - Value: FullCodec + MaxEncodedLen, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - fn storage_info() -> Vec { - [::Map::storage_info(), CounterFor::::storage_info()].concat() - } -} - -/// It doesn't require to implement `MaxEncodedLen` and give no information for `max_size`. -impl - PartialStorageInfoTrait - for CountedStorageDoubleMap< - Prefix, - Hasher1, - Key1, - Hasher2, - Key2, - Value, - QueryKind, - OnEmpty, - MaxValues, - > where - Prefix: CountedStorageDoubleMapInstance, - Hasher1: crate::hash::StorageHasher, - Hasher2: crate::hash::StorageHasher, - Key1: FullCodec, - Key2: FullCodec, - Value: FullCodec, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - fn partial_storage_info() -> Vec { - [::Map::partial_storage_info(), CounterFor::::storage_info()] - .concat() - } -} - -#[cfg(test)] -mod test { - use super::*; - use crate::{ - hash::*, - metadata::{StorageEntryModifier, StorageEntryType, StorageHasher}, - storage::bounded_vec::BoundedVec, - traits::ConstU32, - }; - use sp_io::{hashing::twox_128, TestExternalities}; - - struct Prefix; - impl StorageInstance for Prefix { - fn pallet_prefix() -> &'static str { - "test" - } - const STORAGE_PREFIX: &'static str = "foo"; - } - - struct CounterPrefix; - impl StorageInstance for CounterPrefix { - fn pallet_prefix() -> &'static str { - "test" - } - const STORAGE_PREFIX: &'static str = "counter_for_foo"; - } - impl CountedStorageDoubleMapInstance for Prefix { - type CounterPrefix = CounterPrefix; - } - - struct ADefault; - impl crate::traits::Get for ADefault { - fn get() -> u32 { - 97 - } - } - - #[test] - fn test_value_query() { - type A = CountedStorageDoubleMap< - Prefix, - Blake2_128Concat, - u16, - Twox64Concat, - u8, - u32, - ValueQuery, - ADefault, - >; - TestExternalities::default().execute_with(|| { - let mut k: Vec = vec![]; - k.extend(&twox_128(b"test")); - k.extend(&twox_128(b"foo")); - k.extend(&3u16.blake2_128_concat()); - k.extend(&30u8.twox_64_concat()); - assert_eq!(A::hashed_key_for(3, 30).to_vec(), k); - - assert_eq!(A::contains_key(3, 30), false); - assert_eq!(A::get(3, 30), ADefault::get()); - assert_eq!(A::try_get(3, 30), Err(())); - assert_eq!(A::count(), 0); - - A::insert(3, 30, 10); - assert_eq!(A::contains_key(3, 30), true); - assert_eq!(A::get(3, 30), 10); - assert_eq!(A::try_get(3, 30), Ok(10)); - assert_eq!(A::count(), 1); - - A::swap(3, 30, 2, 20); - assert_eq!(A::contains_key(3, 30), false); - assert_eq!(A::contains_key(2, 20), true); - assert_eq!(A::get(3, 30), ADefault::get()); - assert_eq!(A::try_get(3, 30), Err(())); - assert_eq!(A::get(2, 20), 10); - assert_eq!(A::try_get(2, 20), Ok(10)); - assert_eq!(A::count(), 1); - - A::swap(3, 30, 2, 20); - assert_eq!(A::contains_key(3, 30), true); - assert_eq!(A::contains_key(2, 20), false); - assert_eq!(A::get(3, 30), 10); - assert_eq!(A::try_get(3, 30), Ok(10)); - assert_eq!(A::get(2, 20), ADefault::get()); - assert_eq!(A::try_get(2, 20), Err(())); - assert_eq!(A::count(), 1); - - A::insert(4, 40, 11); - assert_eq!(A::try_get(3, 30), Ok(10)); - assert_eq!(A::try_get(4, 40), Ok(11)); - assert_eq!(A::count(), 2); - - // Swap 2 existing. - A::swap(3, 30, 4, 40); - - assert_eq!(A::try_get(3, 30), Ok(11)); - assert_eq!(A::try_get(4, 40), Ok(10)); - assert_eq!(A::count(), 2); - - // Insert an existing key, shouldn't increment counted values. - A::insert(3, 30, 12); - assert_eq!(A::try_get(3, 30), Ok(12)); - assert_eq!(A::count(), 2); - - // Remove non-existing. - A::remove(2, 20); - assert_eq!(A::contains_key(2, 20), false); - assert_eq!(A::count(), 2); - - // Remove existing. - A::remove(3, 30); - - assert_eq!(A::try_get(3, 30), Err(())); - assert_eq!(A::count(), 1); - - // Mutate non-existing to existing. - A::mutate(3, 30, |query| { - assert_eq!(*query, ADefault::get()); - *query = 40; - }); - - assert_eq!(A::try_get(3, 30), Ok(40)); - assert_eq!(A::count(), 2); - - // Try fail mutate non-existing to existing. - A::try_mutate(2, 20, |query| { - assert_eq!(*query, ADefault::get()); - *query = 4; - Result::<(), ()>::Err(()) - }) - .err() - .unwrap(); - - assert_eq!(A::try_get(2, 20), Err(())); - assert_eq!(A::count(), 2); - - // Try succeed mutate non-existing to existing. - A::try_mutate(2, 20, |query| { - assert_eq!(*query, ADefault::get()); - *query = 41; - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(A::try_get(2, 20), Ok(41)); - assert_eq!(A::count(), 3); - - // Try succeed mutate existing to existing. - A::try_mutate(2, 20, |query| { - assert_eq!(*query, 41); - *query = 41; - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(A::try_get(2, 20), Ok(41)); - assert_eq!(A::count(), 3); - - // Try fail mutate non-existing to existing. - A::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, None); - *query = Some(4); - Result::<(), ()>::Err(()) - }) - .err() - .unwrap(); - - assert_eq!(A::try_get(1, 10), Err(())); - assert_eq!(A::count(), 3); - - // Try succeed mutate non-existing to existing. - A::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, None); - *query = Some(43); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(A::try_get(1, 10), Ok(43)); - assert_eq!(A::count(), 4); - - // Try succeed mutate existing to existing. - A::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, Some(43)); - *query = Some(45); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(A::try_get(1, 10), Ok(45)); - assert_eq!(A::count(), 4); - - // Try succeed mutate existing to non-existing. - A::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, Some(45)); - *query = None; - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(A::try_get(1, 10), Err(())); - assert_eq!(A::count(), 3); - - // Take exsisting. - assert_eq!(A::take(4, 40), 10); - - assert_eq!(A::try_get(4, 40), Err(())); - assert_eq!(A::count(), 2); - - // Take non-exsisting. - assert_eq!(A::take(4, 40), ADefault::get()); - - assert_eq!(A::try_get(4, 40), Err(())); - assert_eq!(A::count(), 2); - - // Remove all. - A::remove_all(); - - assert_eq!(A::count(), 0); - assert_eq!(A::initialize_counter(), 0); - - A::insert(1, 10, 1); - A::insert(2, 20, 2); - - // Iter values. - assert_eq!(A::iter_values().collect::>(), vec![2, 1]); - - // Iter drain values. - assert_eq!(A::iter_values().drain().collect::>(), vec![2, 1]); - assert_eq!(A::count(), 0); - - A::insert(1, 10, 1); - A::insert(2, 20, 2); - - // Test initialize_counter. - assert_eq!(A::initialize_counter(), 2); - }) - } - - #[test] - fn test_option_query() { - type B = CountedStorageDoubleMap; - TestExternalities::default().execute_with(|| { - let mut k: Vec = vec![]; - k.extend(&twox_128(b"test")); - k.extend(&twox_128(b"foo")); - k.extend(&3u16.blake2_256()); - k.extend(&30u8.twox_64_concat()); - assert_eq!(B::hashed_key_for(3, 30).to_vec(), k); - - assert_eq!(B::contains_key(3, 30), false); - assert_eq!(B::get(3, 30), None); - assert_eq!(B::try_get(3, 30), Err(())); - assert_eq!(B::count(), 0); - - // Insert non-existing. - B::insert(3, 30, 10); - - assert_eq!(B::contains_key(3, 30), true); - assert_eq!(B::get(3, 30), Some(10)); - assert_eq!(B::try_get(3, 30), Ok(10)); - assert_eq!(B::count(), 1); - - // Swap non-existing with existing. - B::swap(4, 40, 3, 30); - - assert_eq!(B::contains_key(3, 30), false); - assert_eq!(B::get(3, 30), None); - assert_eq!(B::try_get(3, 30), Err(())); - assert_eq!(B::contains_key(4, 40), true); - assert_eq!(B::get(4, 40), Some(10)); - assert_eq!(B::try_get(4, 40), Ok(10)); - assert_eq!(B::count(), 1); - - // Swap existing with non-existing. - B::swap(4, 40, 3, 30); - - assert_eq!(B::try_get(3, 30), Ok(10)); - assert_eq!(B::contains_key(4, 40), false); - assert_eq!(B::get(4, 40), None); - assert_eq!(B::try_get(4, 40), Err(())); - assert_eq!(B::count(), 1); - - B::insert(4, 40, 11); - - assert_eq!(B::try_get(3, 30), Ok(10)); - assert_eq!(B::try_get(4, 40), Ok(11)); - assert_eq!(B::count(), 2); - - // Swap 2 existing. - B::swap(3, 30, 4, 40); - - assert_eq!(B::try_get(3, 30), Ok(11)); - assert_eq!(B::try_get(4, 40), Ok(10)); - assert_eq!(B::count(), 2); - - // Insert an existing key, shouldn't increment counted values. - B::insert(3, 30, 11); - - assert_eq!(B::count(), 2); - - // Remove non-existing. - B::remove(2, 20); - - assert_eq!(B::contains_key(2, 20), false); - assert_eq!(B::count(), 2); - - // Remove existing. - B::remove(3, 30); - - assert_eq!(B::try_get(3, 30), Err(())); - assert_eq!(B::count(), 1); - - // Mutate non-existing to existing. - B::mutate(3, 30, |query| { - assert_eq!(*query, None); - *query = Some(40) - }); - - assert_eq!(B::try_get(3, 30), Ok(40)); - assert_eq!(B::count(), 2); - - // Mutate existing to existing. - B::mutate(3, 30, |query| { - assert_eq!(*query, Some(40)); - *query = Some(40) - }); - - assert_eq!(B::try_get(3, 30), Ok(40)); - assert_eq!(B::count(), 2); - - // Mutate existing to non-existing. - B::mutate(3, 30, |query| { - assert_eq!(*query, Some(40)); - *query = None - }); - - assert_eq!(B::try_get(3, 30), Err(())); - assert_eq!(B::count(), 1); - - B::insert(3, 30, 40); - - // Try fail mutate non-existing to existing. - B::try_mutate(2, 20, |query| { - assert_eq!(*query, None); - *query = Some(4); - Result::<(), ()>::Err(()) - }) - .err() - .unwrap(); - - assert_eq!(B::try_get(2, 20), Err(())); - assert_eq!(B::count(), 2); - - // Try succeed mutate non-existing to existing. - B::try_mutate(2, 20, |query| { - assert_eq!(*query, None); - *query = Some(41); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(2, 20), Ok(41)); - assert_eq!(B::count(), 3); - - // Try succeed mutate existing to existing. - B::try_mutate(2, 20, |query| { - assert_eq!(*query, Some(41)); - *query = Some(41); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(2, 20), Ok(41)); - assert_eq!(B::count(), 3); - - // Try succeed mutate existing to non-existing. - B::try_mutate(2, 20, |query| { - assert_eq!(*query, Some(41)); - *query = None; - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(2, 20), Err(())); - assert_eq!(B::count(), 2); - - B::insert(2, 20, 41); - - // Try fail mutate non-existing to existing. - B::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, None); - *query = Some(4); - Result::<(), ()>::Err(()) - }) - .err() - .unwrap(); - - assert_eq!(B::try_get(1, 10), Err(())); - assert_eq!(B::count(), 3); - - // Try succeed mutate non-existing to existing. - B::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, None); - *query = Some(43); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(1, 10), Ok(43)); - assert_eq!(B::count(), 4); - - // Try succeed mutate existing to existing. - B::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, Some(43)); - *query = Some(43); - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(1, 10), Ok(43)); - assert_eq!(B::count(), 4); - - // Try succeed mutate existing to non-existing. - B::try_mutate_exists(1, 10, |query| { - assert_eq!(*query, Some(43)); - *query = None; - Result::<(), ()>::Ok(()) - }) - .unwrap(); - - assert_eq!(B::try_get(1, 10), Err(())); - assert_eq!(B::count(), 3); - - // Take exsisting. - assert_eq!(B::take(4, 40), Some(10)); - - assert_eq!(B::try_get(4, 40), Err(())); - assert_eq!(B::count(), 2); - - // Take non-exsisting. - assert_eq!(B::take(4, 40), None); - - assert_eq!(B::try_get(4, 40), Err(())); - assert_eq!(B::count(), 2); - - // Remove all. - B::remove_all(); - - assert_eq!(B::count(), 0); - assert_eq!(B::initialize_counter(), 0); - - B::insert(1, 10, 1); - B::insert(2, 20, 2); - - // Iter values. - assert_eq!(B::iter_values().collect::>(), vec![1, 2]); - - // Iter drain values. - assert_eq!(B::iter_values().drain().collect::>(), vec![1, 2]); - assert_eq!(B::count(), 0); - - B::insert(1, 10, 1); - B::insert(2, 20, 2); - - // Test initialize_counter. - assert_eq!(B::initialize_counter(), 2); - }) - } - - #[test] - fn append_decode_len_works() { - type B = CountedStorageDoubleMap>; - TestExternalities::default().execute_with(|| { - assert_eq!(B::decode_len(1, 10), None); - B::append(1, 10, 3); - assert_eq!(B::decode_len(1, 10), Some(1)); - B::append(1, 10, 3); - assert_eq!(B::decode_len(1, 10), Some(2)); - B::append(1, 10, 3); - assert_eq!(B::decode_len(1, 10), Some(3)); - }) - } - - #[test] - fn try_append_decode_len_works() { - type B = CountedStorageDoubleMap< - Prefix, - Blake2_256, - u16, - Twox64Concat, - u8, - BoundedVec>, - >; - TestExternalities::default().execute_with(|| { - assert_eq!(B::decode_len(1, 10), None); - B::try_append(1, 10, 3).unwrap(); - assert_eq!(B::decode_len(1, 10), Some(1)); - B::try_append(1, 10, 3).unwrap(); - assert_eq!(B::decode_len(1, 10), Some(2)); - B::try_append(1, 10, 3).unwrap(); - assert_eq!(B::decode_len(1, 10), Some(3)); - B::try_append(1, 10, 3).err().unwrap(); - assert_eq!(B::decode_len(1, 10), Some(3)); - }) - } - - #[test] - fn migrate_keys_works() { - type A = CountedStorageDoubleMap; - type B = CountedStorageDoubleMap; - TestExternalities::default().execute_with(|| { - A::insert(1, 10, 1); - assert_eq!(B::migrate_keys::(1, 10), Some(1)); - assert_eq!(B::get(1, 10), Some(1)); - }) - } - - #[test] - fn translate_values() { - type A = CountedStorageDoubleMap; - TestExternalities::default().execute_with(|| { - A::insert(1, 10, 1); - A::insert(2, 20, 2); - A::translate_values::(|old_value| if old_value == 1 { None } else { Some(1) }); - assert_eq!(A::count(), 1); - assert_eq!(A::get(2, 20), Some(1)); - }) - } - - #[test] - fn test_iter_drain_translate() { - type A = CountedStorageDoubleMap; - TestExternalities::default().execute_with(|| { - A::insert(1, 10, 1); - A::insert(2, 20, 2); - - assert_eq!(A::iter().collect::>(), vec![(2, 20, 2), (1, 10, 1)]); - - assert_eq!(A::count(), 2); - - A::translate::( - |key1, _key2, value| if key1 == 1 { None } else { Some(key1 as u32 * value) }, - ); - - assert_eq!(A::count(), 1); - - assert_eq!(A::drain().collect::>(), vec![(2, 20, 4)]); - - assert_eq!(A::count(), 0); - }) - } - - #[test] - fn test_iter_drain_prefix() { - type A = CountedStorageDoubleMap; - TestExternalities::default().execute_with(|| { - A::insert(1, 10, 1); - A::insert(1, 11, 2); - A::insert(2, 20, 3); - A::insert(2, 21, 4); - - assert_eq!(A::iter_prefix_values(1).collect::>(), vec![1, 2]); - assert_eq!(A::iter_prefix(1).collect::>(), vec![(10, 1), (11, 2)]); - assert_eq!(A::iter_prefix_values(2).collect::>(), vec![4, 3]); - assert_eq!(A::iter_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); - - assert_eq!(A::count(), 4); - - A::remove_prefix(1); - assert_eq!(A::iter_prefix(1).collect::>(), vec![]); - assert_eq!(A::iter_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); - - assert_eq!(A::count(), 2); - - assert_eq!(A::drain_prefix(2).collect::>(), vec![(21, 4), (20, 3)]); - assert_eq!(A::iter_prefix(2).collect::>(), vec![]); - assert_eq!(A::drain_prefix(2).collect::>(), vec![]); - - assert_eq!(A::count(), 0); - }) - } - - #[test] - fn test_metadata() { - type A = CountedStorageDoubleMap< - Prefix, - Blake2_128Concat, - u16, - Twox64Concat, - u8, - u32, - ValueQuery, - ADefault, - >; - let mut entries = vec![]; - A::build_metadata(vec![], &mut entries); - assert_eq!( - entries, - vec![ - StorageEntryMetadata { - name: "foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Map { - hashers: vec![StorageHasher::Blake2_128Concat, StorageHasher::Twox64Concat], - key: scale_info::meta_type::<(u16, u8)>(), - value: scale_info::meta_type::(), - }, - default: 97u32.encode(), - docs: vec![], - }, - StorageEntryMetadata { - name: "counter_for_foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), - default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], - }, - ] - ); - } -} diff --git a/frame/support/src/storage/types/mod.rs b/frame/support/src/storage/types/mod.rs index 6921f250e6a97..8f9a3142bbefe 100644 --- a/frame/support/src/storage/types/mod.rs +++ b/frame/support/src/storage/types/mod.rs @@ -22,7 +22,6 @@ use crate::metadata::{StorageEntryMetadata, StorageEntryModifier}; use codec::FullCodec; use sp_std::prelude::*; -mod counted_double_map; mod counted_map; mod counted_nmap; mod double_map; @@ -31,7 +30,6 @@ mod map; mod nmap; mod value; -pub use counted_double_map::{CountedStorageDoubleMap, CountedStorageDoubleMapInstance}; pub use counted_map::{CountedStorageMap, CountedStorageMapInstance}; pub use counted_nmap::{CountedStorageNMap, CountedStorageNMapInstance}; pub use double_map::StorageDoubleMap; From 8897c276d72a5ac1715d97ea0180d44fbff86869 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Thu, 18 Aug 2022 16:00:45 +0300 Subject: [PATCH 20/50] fix metadata checks --- .../support/src/storage/types/counted_nmap.rs | 236 ++++++++++-------- 1 file changed, 137 insertions(+), 99 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index abf6f9a401cfe..9299ca9c10310 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -174,7 +174,6 @@ where key: KArg, query: QueryKind::Query, ) { - // TODO: implement ::Map::set(key, query) } @@ -850,34 +849,47 @@ mod test { let mut entries = vec![]; A::build_metadata(vec![], &mut entries); AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); - // TODO: fix metadata test - // assert_eq!( - // entries, - // vec![ - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Optional, - // ty: StorageEntryType::Map { - // hashers: vec![StorageHasher::Blake2_128Concat], - // key: scale_info::meta_type::(), - // value: scale_info::meta_type::(), - // }, - // default: Option::::None.encode(), - // docs: vec![], - // }, - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Default, - // ty: StorageEntryType::Map { - // hashers: vec![StorageHasher::Blake2_128Concat], - // key: scale_info::meta_type::(), - // value: scale_info::meta_type::(), - // }, - // default: 98u32.encode(), - // docs: vec![], - // } - // ] - // ); + assert_eq!( + entries, + vec![ + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + hashers: vec![StorageHasher::Blake2_128Concat], + key: scale_info::meta_type::(), + value: scale_info::meta_type::(), + }, + default: Option::::None.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Map { + hashers: vec![StorageHasher::Blake2_128Concat], + key: scale_info::meta_type::(), + value: scale_info::meta_type::(), + }, + default: 98u32.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + ] + ); let _ = WithLen::clear(u32::max_value(), None); assert_eq!(WithLen::decode_len((3,)), None); @@ -1073,40 +1085,53 @@ mod test { let mut entries = vec![]; A::build_metadata(vec![], &mut entries); AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); - // TODO: fix metadata - // assert_eq!( - // entries, - // vec![ - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Optional, - // ty: StorageEntryType::Map { - // hashers: vec![ - // StorageHasher::Blake2_128Concat, - // StorageHasher::Twox64Concat - // ], - // key: scale_info::meta_type::<(u16, u8)>(), - // value: scale_info::meta_type::(), - // }, - // default: Option::::None.encode(), - // docs: vec![], - // }, - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Default, - // ty: StorageEntryType::Map { - // hashers: vec![ - // StorageHasher::Blake2_128Concat, - // StorageHasher::Twox64Concat - // ], - // key: scale_info::meta_type::<(u16, u8)>(), - // value: scale_info::meta_type::(), - // }, - // default: 98u32.encode(), - // docs: vec![], - // } - // ] - // ); + assert_eq!( + entries, + vec![ + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat + ], + key: scale_info::meta_type::<(u16, u8)>(), + value: scale_info::meta_type::(), + }, + default: Option::::None.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Map { + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat + ], + key: scale_info::meta_type::<(u16, u8)>(), + value: scale_info::meta_type::(), + }, + default: 98u32.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + ] + ); let _ = WithLen::clear(u32::max_value(), None); assert_eq!(WithLen::decode_len((3, 30)), None); @@ -1333,42 +1358,55 @@ mod test { let mut entries = vec![]; A::build_metadata(vec![], &mut entries); AValueQueryWithAnOnEmpty::build_metadata(vec![], &mut entries); - // TODO: fix metadata - // assert_eq!( - // entries, - // vec![ - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Optional, - // ty: StorageEntryType::Map { - // hashers: vec![ - // StorageHasher::Blake2_128Concat, - // StorageHasher::Blake2_128Concat, - // StorageHasher::Twox64Concat - // ], - // key: scale_info::meta_type::<(u16, u16, u16)>(), - // value: scale_info::meta_type::(), - // }, - // default: Option::::None.encode(), - // docs: vec![], - // }, - // StorageEntryMetadata { - // name: "Foo", - // modifier: StorageEntryModifier::Default, - // ty: StorageEntryType::Map { - // hashers: vec![ - // StorageHasher::Blake2_128Concat, - // StorageHasher::Blake2_128Concat, - // StorageHasher::Twox64Concat - // ], - // key: scale_info::meta_type::<(u16, u16, u16)>(), - // value: scale_info::meta_type::(), - // }, - // default: 98u32.encode(), - // docs: vec![], - // } - // ] - // ); + assert_eq!( + entries, + vec![ + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat + ], + key: scale_info::meta_type::<(u16, u16, u16)>(), + value: scale_info::meta_type::(), + }, + default: Option::::None.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Map { + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat + ], + key: scale_info::meta_type::<(u16, u16, u16)>(), + value: scale_info::meta_type::(), + }, + default: 98u32.encode(), + docs: vec![], + }, + StorageEntryMetadata { + name: "Foo", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(scale_info::meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + ] + ); let _ = WithLen::clear(u32::max_value(), None); assert_eq!(WithLen::decode_len((3, 30, 300)), None); From 71f78b21e59777bca85125d6468af27f006d9e98 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 13 Sep 2022 21:57:43 +0300 Subject: [PATCH 21/50] update clear func --- .../support/src/storage/types/counted_nmap.rs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 9299ca9c10310..9489c5e26d9fc 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -31,6 +31,7 @@ use crate::{ Never, }; use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; +use sp_arithmetic::traits::Zero; use sp_runtime::traits::Saturating; use sp_std::prelude::*; @@ -407,7 +408,13 @@ where /// 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::MultiRemovalResults { - CounterFor::::set(0u32); + let mut current = CounterFor::::get(); + current = current.saturating_sub(limit); + if current.is_zero() { + CounterFor::::kill(); + } else { + CounterFor::::set(current); + } ::Map::clear(limit, maybe_cursor) } @@ -817,6 +824,13 @@ mod test { A::insert((3,), 10); A::insert((4,), 10); + assert_eq!(A::count(), 3); + let _ = A::clear(1, None); + // one of the item has been removed + assert!(!A::contains_key((2,)) || !A::contains_key((3,)) || !A::contains_key((4,))); + assert!(A::contains_key((2,)) || A::contains_key((3,)) || A::contains_key((4,))); + assert_eq!(A::count(), 2); + let _ = A::clear(u32::max_value(), None); assert_eq!(A::contains_key((3,)), false); assert_eq!(A::contains_key((4,)), false); @@ -1053,6 +1067,14 @@ mod test { A::insert((3, 30), 10); A::insert((4, 40), 10); + assert_eq!(A::count(), 3); + let _ = A::clear(1, None); + // one of the item has been removed + assert!( + !A::contains_key((2, 20)) || !A::contains_key((3, 30)) || !A::contains_key((4, 40)) + ); + assert_eq!(A::count(), 2); + let _ = A::clear(u32::max_value(), None); assert_eq!(A::contains_key((3, 30)), false); assert_eq!(A::contains_key((4, 40)), false); @@ -1321,6 +1343,21 @@ mod test { A::insert((3, 30, 300), 10); A::insert((4, 40, 400), 10); + assert_eq!(A::count(), 3); + let _ = A::clear(1, None); + // one of the item has been removed + assert!( + !A::contains_key((2, 20, 200)) || + !A::contains_key((3, 30, 300)) || + !A::contains_key((4, 40, 400)) + ); + assert!( + A::contains_key((2, 20, 200)) || + A::contains_key((3, 30, 300)) || + A::contains_key((4, 40, 400)) + ); + assert_eq!(A::count(), 2); + let _ = A::clear(u32::max_value(), None); assert_eq!(A::contains_key((3, 30, 300)), false); assert_eq!(A::contains_key((4, 40, 400)), false); From 4b2fded1f557f1c38de46aa8416b46bbfa5e61d3 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 2 Oct 2022 18:40:55 +0300 Subject: [PATCH 22/50] fix clear, clear with prefix --- .../support/src/storage/types/counted_nmap.rs | 73 ++++++------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 9489c5e26d9fc..40a0c3e37692c 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -31,7 +31,6 @@ use crate::{ Never, }; use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; -use sp_arithmetic::traits::Zero; use sp_runtime::traits::Saturating; use sp_std::prelude::*; @@ -251,14 +250,12 @@ where where Key: HasKeyPrefix, { - let mut on_remove = 0; - Self::iter_prefix_values(partial_key.clone()).for_each(|_| { - on_remove += 1; - }); - CounterFor::::mutate(|value| { - *value = value.saturating_sub(on_remove); - }); - ::Map::clear_prefix(partial_key, limit, maybe_cursor) + let result = ::Map::clear_prefix(partial_key, limit, maybe_cursor); + match result.maybe_cursor { + None => CounterFor::::kill(), + Some(_) => CounterFor::::mutate(|x| x.saturating_reduce(result.unique)), + } + result } /// Iterate over values that share the first key. @@ -408,14 +405,12 @@ where /// 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::MultiRemovalResults { - let mut current = CounterFor::::get(); - current = current.saturating_sub(limit); - if current.is_zero() { - CounterFor::::kill(); - } else { - CounterFor::::set(current); + let result = ::Map::clear(limit, maybe_cursor); + match result.maybe_cursor { + None => CounterFor::::kill(), + Some(_) => CounterFor::::mutate(|x| x.saturating_reduce(result.unique)), } - ::Map::clear(limit, maybe_cursor) + result } /// Iter over all value of the storage. @@ -825,15 +820,8 @@ mod test { A::insert((3,), 10); A::insert((4,), 10); assert_eq!(A::count(), 3); - let _ = A::clear(1, None); - // one of the item has been removed - assert!(!A::contains_key((2,)) || !A::contains_key((3,)) || !A::contains_key((4,))); - assert!(A::contains_key((2,)) || A::contains_key((3,)) || A::contains_key((4,))); - assert_eq!(A::count(), 2); - let _ = A::clear(u32::max_value(), None); - assert_eq!(A::contains_key((3,)), false); - assert_eq!(A::contains_key((4,)), false); + assert!(!A::contains_key((2,)) && !A::contains_key((3,)) && !A::contains_key((4,))); assert_eq!(A::count(), 0); A::insert((3,), 10); @@ -882,7 +870,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, StorageEntryMetadata { name: "Foo", @@ -900,7 +888,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, ] ); @@ -1068,16 +1056,13 @@ mod test { A::insert((3, 30), 10); A::insert((4, 40), 10); assert_eq!(A::count(), 3); - let _ = A::clear(1, None); + let _ = A::clear(u32::max_value(), None); // one of the item has been removed assert!( - !A::contains_key((2, 20)) || !A::contains_key((3, 30)) || !A::contains_key((4, 40)) + !A::contains_key((2, 20)) && !A::contains_key((3, 30)) && !A::contains_key((4, 40)) ); - assert_eq!(A::count(), 2); + assert_eq!(A::count(), 0); - let _ = A::clear(u32::max_value(), None); - assert_eq!(A::contains_key((3, 30)), false); - assert_eq!(A::contains_key((4, 40)), false); assert_eq!(A::count(), 0); A::insert((3, 30), 10); @@ -1129,7 +1114,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, StorageEntryMetadata { name: "Foo", @@ -1150,7 +1135,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, ] ); @@ -1344,23 +1329,13 @@ mod test { A::insert((3, 30, 300), 10); A::insert((4, 40, 400), 10); assert_eq!(A::count(), 3); - let _ = A::clear(1, None); + let _ = A::clear(u32::max_value(), None); // one of the item has been removed assert!( - !A::contains_key((2, 20, 200)) || - !A::contains_key((3, 30, 300)) || + !A::contains_key((2, 20, 200)) && + !A::contains_key((3, 30, 300)) && !A::contains_key((4, 40, 400)) ); - assert!( - A::contains_key((2, 20, 200)) || - A::contains_key((3, 30, 300)) || - A::contains_key((4, 40, 400)) - ); - assert_eq!(A::count(), 2); - - let _ = A::clear(u32::max_value(), None); - assert_eq!(A::contains_key((3, 30, 300)), false); - assert_eq!(A::contains_key((4, 40, 400)), false); assert_eq!(A::count(), 0); A::insert((3, 30, 300), 10); @@ -1418,7 +1393,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, StorageEntryMetadata { name: "Foo", @@ -1440,7 +1415,7 @@ mod test { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: vec!["Counter for the related counted storage map"], }, ] ); From e9e30a9e0bb6301eeade189fffa241764cecc6a9 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 2 Oct 2022 18:53:36 +0300 Subject: [PATCH 23/50] fix set function --- frame/support/src/storage/types/counted_map.rs | 8 ++++++-- frame/support/src/storage/types/counted_nmap.rs | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index 4c8e1fc72c30b..f15db116bf3b1 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -133,8 +133,12 @@ where } /// Store or remove the value to be associated with `key` so that `get` returns the `query`. - pub fn set>(key: KeyArg, q: QueryKind::Query) { - ::Map::set(key, q) + pub fn set>(key: KeyArg, query: QueryKind::Query) { + let option = QueryKind::from_query_to_optional_value(query); + if option.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + ::Map::set(key, QueryKind::from_optional_value_to_query(option)) } /// Swap the values of two keys. diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 40a0c3e37692c..f2243a2b012fe 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -174,7 +174,11 @@ where key: KArg, query: QueryKind::Query, ) { - ::Map::set(key, query) + let option = QueryKind::from_query_to_optional_value(query); + if option.is_none() { + CounterFor::::mutate(|value| value.saturating_dec()); + } + ::Map::set(key, QueryKind::from_optional_value_to_query(option)) } /// Take a value from storage, removing it afterwards. From 09583a983add3fc443a408ca0670e6112d570905 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Mon, 24 Oct 2022 12:44:55 +0300 Subject: [PATCH 24/50] update --- frame/support/src/storage/types/counted_map.rs | 5 +---- frame/support/src/storage/types/counted_nmap.rs | 6 +++--- frame/support/src/storage/types/key.rs | 14 +++++++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index f15db116bf3b1..9f7ee3e3bde2f 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -147,10 +147,7 @@ where } /// Store a value to be associated with the given key from the map. - pub fn insert + Clone, ValArg: EncodeLike>( - key: KeyArg, - val: ValArg, - ) { + pub fn insert, ValArg: EncodeLike>(key: KeyArg, val: ValArg) { if !::Map::contains_key(Ref::from(&key)) { CounterFor::::mutate(|value| value.saturating_inc()); } diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index f2243a2b012fe..1dcbbd523de78 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -30,7 +30,7 @@ use crate::{ traits::{Get, GetDefault, StorageInfo, StorageInstance}, Never, }; -use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; use sp_runtime::traits::Saturating; use sp_std::prelude::*; @@ -209,7 +209,7 @@ where KArg: EncodeLikeTuple + TupleToEncodedIter + Clone, VArg: EncodeLike, { - if !::Map::contains_key(key.clone()) { + if !::Map::contains_key(Ref::from(&key)) { CounterFor::::mutate(|value| value.saturating_inc()); } ::Map::insert(key, val) @@ -246,7 +246,7 @@ where /// passed once (in the initial call) for any given storage map and `partial_key`. Subsequent /// calls operating on the same map/`partial_key` should always pass `Some`, and this should be /// equal to the previous call result's `maybe_cursor` field. - pub fn clear_prefix( + pub fn clear_prefix( partial_key: KP, limit: u32, maybe_cursor: Option<&[u8]>, diff --git a/frame/support/src/storage/types/key.rs b/frame/support/src/storage/types/key.rs index 182ddbedd9b8e..ef1431cef579a 100755 --- a/frame/support/src/storage/types/key.rs +++ b/frame/support/src/storage/types/key.rs @@ -37,7 +37,7 @@ pub struct Key(core::marker::PhantomData<(Hasher, KeyType)>); /// A trait that contains the current key as an associated type. pub trait KeyGenerator { type Key: EncodeLike + StaticTypeInfo; - type KArg: Encode; + type KArg: Encode + EncodeLike; type HashFn: FnOnce(&[u8]) -> Vec; type HArg; @@ -196,6 +196,9 @@ impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P); impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P, Q); impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P, Q, R); +impl<'a, T: EncodeLike, U: Encode> EncodeLikeTuple for codec::Ref<'a, T, U> {} +impl<'a, T: EncodeLike, U: Encode> crate::storage::private::Sealed for codec::Ref<'a, T, U> {} + /// Trait to indicate that a tuple can be converted into an iterator of a vector of encoded bytes. pub trait TupleToEncodedIter { fn to_encoded_iter(&self) -> sp_std::vec::IntoIter>; @@ -215,6 +218,15 @@ impl TupleToEncodedIter for &T { } } +impl<'a, T: EncodeLike + TupleToEncodedIter, U: Encode> TupleToEncodedIter + for codec::Ref<'a, T, U> +{ + fn to_encoded_iter(&self) -> sp_std::vec::IntoIter> { + use core::ops::Deref as _; + self.deref().to_encoded_iter() + } +} + /// A trait that indicates the hashers for the keys generated are all reversible. pub trait ReversibleKeyGenerator: KeyGenerator { type ReversibleHasher; From 235a6056048b1c7dd5cf42a0df87640fcf9b146b Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Thu, 17 Nov 2022 23:37:37 +0200 Subject: [PATCH 25/50] final fix --- frame/support/src/storage/types/counted_nmap.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 1dcbbd523de78..a5ceb26618875 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -206,7 +206,7 @@ where /// Store a value to be associated with the given keys from the map. pub fn insert(key: KArg, val: VArg) where - KArg: EncodeLikeTuple + TupleToEncodedIter + Clone, + KArg: EncodeLikeTuple + EncodeLike + TupleToEncodedIter, VArg: EncodeLike, { if !::Map::contains_key(Ref::from(&key)) { @@ -216,8 +216,10 @@ where } /// Remove the value under the given keys. - pub fn remove + TupleToEncodedIter + Clone>(key: KArg) { - if ::Map::contains_key(key.clone()) { + pub fn remove + EncodeLike + TupleToEncodedIter>( + key: KArg, + ) { + if ::Map::contains_key(Ref::from(&key)) { CounterFor::::mutate(|value| value.saturating_dec()); } ::Map::remove(key) @@ -343,12 +345,12 @@ where /// on overwrite. pub fn append(key: KArg, item: EncodeLikeItem) where - KArg: EncodeLikeTuple + TupleToEncodedIter + Clone, + KArg: EncodeLikeTuple + EncodeLike + TupleToEncodedIter, Item: Encode, EncodeLikeItem: EncodeLike, Value: StorageAppend, { - if !::Map::contains_key(key.clone()) { + if !::Map::contains_key(Ref::from(&key)) { CounterFor::::mutate(|value| value.saturating_inc()); } ::Map::append(key, item) From cfc599f8b4fd78a52f30658b1af670dcff4a8e7c Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Thu, 29 Dec 2022 14:10:21 +0200 Subject: [PATCH 26/50] Update frame/support/src/storage/types/counted_nmap.rs Co-authored-by: Anton --- frame/support/src/storage/types/counted_nmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index a5ceb26618875..367b869e1ecb7 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -35,7 +35,7 @@ use sp_runtime::traits::Saturating; use sp_std::prelude::*; /// A wrapper around a `StorageNMap` and a `StorageValue` to keep track of how many items -/// are in a map, without needing to iterate all the values. +/// are in a map, without needing to iterate over all of the values. /// /// This storage item has additional storage read and write overhead when manipulating values /// compared to a regular storage map. From 9b800c5235986171d76b287bd76437257c02c808 Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Thu, 29 Dec 2022 14:11:14 +0200 Subject: [PATCH 27/50] Update frame/support/src/storage/types/counted_nmap.rs Co-authored-by: Anton --- frame/support/src/storage/types/counted_nmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 367b869e1ecb7..cd2a14be5899f 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -37,7 +37,7 @@ use sp_std::prelude::*; /// A wrapper around a `StorageNMap` and a `StorageValue` to keep track of how many items /// are in a map, without needing to iterate over all of the values. /// -/// This storage item has additional storage read and write overhead when manipulating values +/// This storage item has some additional storage read and write overhead when manipulating values /// compared to a regular storage map. /// /// For functions where we only add or remove a value, a single storage read is needed to check if From e86cb1131ae9d9eb9558ebb0b19c76fdc400ecfb Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Thu, 29 Dec 2022 14:11:29 +0200 Subject: [PATCH 28/50] Update frame/support/src/storage/types/counted_nmap.rs Co-authored-by: Anton --- frame/support/src/storage/types/counted_nmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index cd2a14be5899f..ed52127a6f4a2 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -598,7 +598,7 @@ where /// /// By returning `None` from `f` for an element, you'll remove it from the map. /// - /// NOTE: If a value fail to decode because storage is corrupted then it is skipped. + /// NOTE: If a value can't be decoded because the storage is corrupted, then it is skipped. pub fn translate Option>(mut f: F) { ::Map::translate(|key, old_value| { let res = f(key, old_value); From 8a3b79dc90efcd6e1fb5f6c532261987a3273333 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 1 Jan 2023 12:04:45 +0200 Subject: [PATCH 29/50] fix comments --- frame/support/src/storage/types/counted_map.rs | 1 + frame/support/src/storage/types/counted_nmap.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/frame/support/src/storage/types/counted_map.rs b/frame/support/src/storage/types/counted_map.rs index 883c5f52b74ed..752709d5346a5 100644 --- a/frame/support/src/storage/types/counted_map.rs +++ b/frame/support/src/storage/types/counted_map.rs @@ -133,6 +133,7 @@ where } /// Store or remove the value to be associated with `key` so that `get` returns the `query`. + /// It decrements the counter when the value is removed pub fn set>(key: KeyArg, query: QueryKind::Query) { let option = QueryKind::from_query_to_optional_value(query); if option.is_none() { diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index ed52127a6f4a2..90edc7334c479 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -170,6 +170,7 @@ where } /// Store or remove the value to be associated with `key` so that `get` returns the `query`. + /// It decrements the counter when the value is removed. pub fn set + TupleToEncodedIter>( key: KArg, query: QueryKind::Query, From e23814637ccc8fbc1b5185138bfff0420a5dc64f Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 10 Feb 2023 19:10:45 +0200 Subject: [PATCH 30/50] fix suggestion --- Cargo.lock | 671 +++++++++++++------------ frame/support/src/storage/types/key.rs | 10 +- 2 files changed, 347 insertions(+), 334 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e5ab65c0ce20..f9f0724d8b483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.1", + "gimli 0.27.0", ] [[package]] @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.69" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "approx" @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "arbitrary" -version = "1.2.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e90af4de65aa7b293ef2d09daff88501eb254f58edde2e1ac02c82d873eadad" +checksum = "29d47fbf90d5149a107494b15a7dc8d69b351be2db3bb9691740e88ec17fd880" [[package]] name = "arc-swap" @@ -308,11 +308,11 @@ checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" [[package]] name = "assert_cmd" -version = "2.0.8" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9834fcc22e0874394a010230586367d4a3e9f11b560f469262678547e1d2575e" +checksum = "fa3d466004a8b4cb1bc34044240a2fd29d17607e2e3bd613eb44fd48e8100da3" dependencies = [ - "bstr", + "bstr 1.1.0", "doc-comment", "predicates", "predicates-core", @@ -379,9 +379,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.64" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" +checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" dependencies = [ "proc-macro2", "quote", @@ -403,9 +403,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" [[package]] name = "atty" @@ -435,7 +435,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object 0.30.3", + "object 0.30.0", "rustc-demangle", ] @@ -463,27 +463,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" - [[package]] name = "base64ct" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" -[[package]] -name = "basic-toml" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e819b667739967cd44d308b8c7b71305d8bb0729ac44a248aa08f33d01950b4" -dependencies = [ - "serde", -] - [[package]] name = "beef" version = "0.5.2" @@ -561,7 +546,7 @@ name = "binary-merkle-tree" version = "4.0.0-dev" dependencies = [ "array-bytes", - "env_logger 0.9.3", + "env_logger", "hash-db", "log", "sp-core", @@ -733,9 +718,18 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.2.0" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + +[[package]] +name = "bstr" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" +checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b" dependencies = [ "memchr", "once_cell", @@ -754,9 +748,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-slice-cast" @@ -784,9 +778,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "bzip2-sys" @@ -801,9 +795,9 @@ dependencies = [ [[package]] name = "camino" -version = "1.1.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77df041dc383319cc661b428b6961a005db4d6808d5e12536931b1ca9556055" +checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" dependencies = [ "serde", ] @@ -839,9 +833,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" dependencies = [ "jobserver", ] @@ -917,7 +911,7 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 4.1.4", + "clap 4.0.32", "node-cli", "rand 0.8.5", "sc-chain-spec", @@ -1033,13 +1027,13 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.4" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", "clap_derive", - "clap_lex 0.3.1", + "clap_lex 0.3.0", "is-terminal", "once_cell", "strsim", @@ -1048,18 +1042,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.1.1" +version = "4.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75" +checksum = "10861370d2ba66b0f5989f83ebf35db6421713fd92351790e7fdd6c36774c56b" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", ] [[package]] name = "clap_derive" -version = "4.1.0" +version = "4.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" dependencies = [ "heck", "proc-macro-error", @@ -1079,9 +1073,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -1109,9 +1103,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.1.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" dependencies = [ "crossbeam-utils", ] @@ -1284,18 +1278,18 @@ dependencies = [ [[package]] name = "crc" -version = "3.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" [[package]] name = "crc32fast" @@ -1501,9 +1495,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-rc.0" +version = "4.0.0-pre.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da00a7a9a4eb92a0a0f8e75660926d48f0d0f3c537e455c457bcdaa1e16b1ac" +checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" dependencies = [ "cfg-if", "fiat-crypto", @@ -1515,9 +1509,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.89" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9" +checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" dependencies = [ "cc", "cxxbridge-flags", @@ -1527,9 +1521,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.89" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d" +checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" dependencies = [ "cc", "codespan-reporting", @@ -1542,15 +1536,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.89" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a" +checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" [[package]] name = "cxxbridge-macro" -version = "1.0.89" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" +checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" dependencies = [ "proc-macro2", "quote", @@ -1559,9 +1553,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.3" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" +checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" dependencies = [ "darling_core", "darling_macro", @@ -1569,9 +1563,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.3" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" +checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" dependencies = [ "fnv", "ident_case", @@ -1583,9 +1577,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.3" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" +checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" dependencies = [ "darling_core", "quote", @@ -1805,9 +1799,9 @@ dependencies = [ [[package]] name = "dissimilar" -version = "1.0.6" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e" +checksum = "bd5f0c7e4bd266b8ab2550e6238d2e74977c23c15536ac7be45e9c95e2e3fbbb" [[package]] name = "doc-comment" @@ -1874,9 +1868,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.3" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" dependencies = [ "signature", ] @@ -1911,9 +1905,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "elliptic-curve" @@ -1982,19 +1976,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "env_logger" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "environmental" version = "1.1.4" @@ -2085,11 +2066,11 @@ checksum = "a214f5bb88731d436478f3ae1f8a277b62124089ba9fb67f4f93fb100ef73c90" [[package]] name = "file-per-thread-logger" -version = "0.1.6" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" +checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" dependencies = [ - "env_logger 0.10.0", + "env_logger", "log", ] @@ -2222,7 +2203,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.1.4", + "clap 4.0.32", "comfy-table", "frame-benchmarking", "frame-support", @@ -2313,7 +2294,7 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", @@ -2558,9 +2539,9 @@ dependencies = [ [[package]] name = "fs_extra" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "funty" @@ -2570,9 +2551,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" dependencies = [ "futures-channel", "futures-core", @@ -2585,9 +2566,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", "futures-sink", @@ -2595,15 +2576,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-executor" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" dependencies = [ "futures-core", "futures-task", @@ -2613,9 +2594,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-lite" @@ -2634,9 +2615,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" dependencies = [ "proc-macro2", "quote", @@ -2650,21 +2631,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" dependencies = [ "futures-io", - "rustls 0.20.8", + "rustls 0.20.7", "webpki 0.22.0", ] [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-timer" @@ -2674,9 +2655,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-channel", "futures-core", @@ -2796,9 +2777,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" +checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" [[package]] name = "git2" @@ -2815,18 +2796,18 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.10" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ "aho-corasick", - "bstr", + "bstr 0.2.17", "fnv", "log", "regex", @@ -2914,9 +2895,9 @@ checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" [[package]] name = "heck" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -2936,12 +2917,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01" - [[package]] name = "hex" version = "0.4.3" @@ -3078,9 +3053,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.24" +version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ "bytes", "futures-channel", @@ -3109,7 +3084,7 @@ dependencies = [ "http", "hyper", "log", - "rustls 0.20.8", + "rustls 0.20.7", "rustls-native-certs", "tokio", "tokio-rustls", @@ -3280,12 +3255,12 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.5" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys 0.45.0", + "windows-sys 0.42.0", ] [[package]] @@ -3308,20 +3283,20 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" [[package]] name = "is-terminal" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "hermit-abi 0.3.0", + "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys 0.45.0", + "windows-sys 0.42.0", ] [[package]] @@ -3350,9 +3325,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -3938,7 +3913,7 @@ dependencies = [ "parking_lot 0.12.1", "quinn-proto", "rand 0.8.5", - "rustls 0.20.8", + "rustls 0.20.7", "thiserror", "tokio", ] @@ -4021,7 +3996,7 @@ dependencies = [ "libp2p-core", "rcgen 0.10.0", "ring", - "rustls 0.20.8", + "rustls 0.20.7", "thiserror", "webpki 0.22.0", "x509-parser 0.14.0", @@ -4128,7 +4103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64 0.13.1", + "base64", "digest 0.9.0", "hmac-drbg", "libsecp256k1-core", @@ -4330,9 +4305,9 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "matrixmultiply" @@ -4563,9 +4538,9 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" +checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -4659,9 +4634,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" +checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" dependencies = [ "anyhow", "byteorder", @@ -4686,9 +4661,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e21fbb6f3d253a14df90eb0000a6066780a15dd901a7519ce02d77a94985b" +checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027" dependencies = [ "bytes", "futures", @@ -4728,7 +4703,7 @@ name = "node-bench" version = "0.9.0-dev" dependencies = [ "array-bytes", - "clap 4.1.4", + "clap 4.0.32", "derive_more", "fs_extra", "futures", @@ -4765,7 +4740,7 @@ version = "3.0.0-dev" dependencies = [ "array-bytes", "assert_cmd", - "clap 4.1.4", + "clap 4.0.32", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4884,7 +4859,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4943,7 +4918,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "generate-bags", "kitchensink-runtime", ] @@ -4952,7 +4927,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -5071,9 +5046,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.3" +version = "7.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c" dependencies = [ "memchr", "minimal-lexical", @@ -5108,9 +5083,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" dependencies = [ "num-traits", ] @@ -5181,9 +5156,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.3" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb" dependencies = [ "memchr", ] @@ -5607,7 +5582,7 @@ dependencies = [ "array-bytes", "assert_matches", "bitflags", - "env_logger 0.9.3", + "env_logger", "frame-benchmarking", "frame-support", "frame-system", @@ -5972,7 +5947,7 @@ name = "pallet-mmr" version = "4.0.0-dev" dependencies = [ "array-bytes", - "env_logger 0.9.3", + "env_logger", "frame-benchmarking", "frame-support", "frame-system", @@ -6751,9 +6726,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed" +checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" dependencies = [ "arrayvec 0.7.2", "bitvec", @@ -6812,7 +6787,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.7", + "parking_lot_core 0.9.5", ] [[package]] @@ -6831,15 +6806,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys 0.45.0", + "windows-sys 0.42.0", ] [[package]] @@ -6874,11 +6849,11 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "pem" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +checksum = "03c64931a1a212348ec4f3b4362585eca7159d0d09cbdf4a7f74f02173596fd4" dependencies = [ - "base64 0.13.1", + "base64", ] [[package]] @@ -6898,9 +6873,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.4" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f" +checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" dependencies = [ "thiserror", "ucd-trie", @@ -6908,9 +6883,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.4" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea" +checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" dependencies = [ "pest", "pest_generator", @@ -6918,9 +6893,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.4" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f" +checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" dependencies = [ "pest", "pest_meta", @@ -6931,20 +6906,20 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.4" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" +checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" dependencies = [ "once_cell", "pest", - "sha2 0.10.6", + "sha1", ] [[package]] name = "petgraph" -version = "0.6.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" dependencies = [ "fixedbitset", "indexmap", @@ -7142,9 +7117,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.1.23" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" +checksum = "2c8992a85d8e93a28bdf76137db888d3874e3b230dee5ed8bebac4c9f7617773" dependencies = [ "proc-macro2", "syn", @@ -7165,10 +7140,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.1.3" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" +checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" dependencies = [ + "once_cell", "thiserror", "toml", ] @@ -7199,9 +7175,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] @@ -7245,9 +7221,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21dc42e00223fc37204bd4aa177e69420c604ca4a183209a8f9de30c6d934698" +checksum = "c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592" dependencies = [ "bytes", "prost-derive", @@ -7255,9 +7231,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f8ad728fb08fe212df3c05169e940fbb6d9d16a877ddde14644a983ba2012e" +checksum = "cb5320c680de74ba083512704acb90fe00f28f79207286a848e730c45dd73ed6" dependencies = [ "bytes", "heck", @@ -7290,9 +7266,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda8c0881ea9f722eb9629376db3d0b903b462477c1aafcb0566610ac28ac5d" +checksum = "c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720" dependencies = [ "anyhow", "itertools", @@ -7303,9 +7279,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e0526209433e96d83d750dd81a99118edbc55739e7e61a46764fd2ad537788" +checksum = "017f79637768cde62820bc2d4fe0e45daaa027755c323ad077767c6c5f173091" dependencies = [ "bytes", "prost", @@ -7356,7 +7332,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.20.8", + "rustls 0.20.7", "slab", "thiserror", "tinyvec", @@ -7487,9 +7463,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.2" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" +checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -7576,9 +7552,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -7763,16 +7739,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.8" +version = "0.36.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.42.0", ] [[package]] @@ -7781,7 +7757,7 @@ version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64 0.13.1", + "base64", "log", "ring", "sct 0.6.1", @@ -7790,9 +7766,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" dependencies = [ "log", "ring", @@ -7814,11 +7790,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" dependencies = [ - "base64 0.21.0", + "base64", ] [[package]] @@ -7992,7 +7968,7 @@ version = "0.10.0-dev" dependencies = [ "array-bytes", "chrono", - "clap 4.1.4", + "clap 4.0.32", "fdlimit", "futures", "futures-timer", @@ -8329,7 +8305,7 @@ dependencies = [ "array-bytes", "assert_matches", "criterion", - "env_logger 0.9.3", + "env_logger", "lru", "num_cpus", "parity-scale-codec", @@ -8801,7 +8777,7 @@ name = "sc-rpc" version = "4.0.0-dev" dependencies = [ "assert_matches", - "env_logger 0.9.3", + "env_logger", "futures", "jsonrpsee", "log", @@ -9026,7 +9002,7 @@ dependencies = [ name = "sc-storage-monitor" version = "0.1.0" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "futures", "log", "nix 0.26.2", @@ -9223,11 +9199,12 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ - "windows-sys 0.42.0", + "lazy_static", + "windows-sys 0.36.1", ] [[package]] @@ -9319,9 +9296,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.3" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +checksum = "d9512ffd81e3a3503ed401f79c33168b9148c75038956039166cd750eaa037c3" dependencies = [ "secp256k1-sys", ] @@ -9346,9 +9323,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.8.2" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -9359,9 +9336,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.8.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -9422,9 +9399,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.92" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa", "ryu", @@ -9444,6 +9421,17 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.6", +] + [[package]] name = "sha2" version = "0.8.2" @@ -9566,14 +9554,14 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ba5f4d4ff12bdb6a169ed51b7c48c0e0ac4b0b4b31012b2571e97d78d3201d" +checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" dependencies = [ "aes-gcm 0.9.4", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-rc.0", + "curve25519-dalek 4.0.0-pre.5", "rand_core 0.6.4", "ring", "rustc_version 0.4.0", @@ -9597,7 +9585,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ - "base64 0.13.1", + "base64", "bytes", "flate2", "futures", @@ -10085,7 +10073,7 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "honggfuzz", "parity-scale-codec", "rand 0.8.5", @@ -10458,9 +10446,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.38.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e40c020d72bc0a9c5660bb71e4a6fdef081493583062c474740a7d59f55f0e7b" +checksum = "23d92659e7d18d82b803824a9ba5a6022cff101c3491d027c1c1d8d30e749284" dependencies = [ "Inflector", "num-format", @@ -10545,7 +10533,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7e94b1ec00bad60e6410e058b52f1c66de3dc5fe4d62d09b3e52bb7d3b73e25" dependencies = [ - "base64 0.13.1", + "base64", "crc", "lazy_static", "md-5", @@ -10562,7 +10550,7 @@ dependencies = [ name = "subkey" version = "2.0.2" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "sc-cli", ] @@ -10590,7 +10578,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "frame-support", "frame-system", "sc-cli", @@ -10920,9 +10908,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] @@ -10985,11 +10973,12 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.5.3+5.3.0-patched" +version = "0.5.2+5.3.0-patched" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8" +checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3" dependencies = [ "cc", + "fs_extra", "libc", ] @@ -11080,15 +11069,15 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.25.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" +checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" dependencies = [ "autocfg", "bytes", @@ -11121,7 +11110,7 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.8", + "rustls 0.20.7", "tokio", "webpki 0.22.0", ] @@ -11168,9 +11157,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.11" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" dependencies = [ "serde", ] @@ -11418,15 +11407,15 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ - "clap 4.1.4", + "clap 4.0.32", "frame-remote-externalities", "frame-try-runtime", "hex", @@ -11455,11 +11444,10 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.77" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44da5a6f2164c8e14d3bbc0657d69c5966af9f5f6930d4f600b1f5c4a673413" +checksum = "654bfc024d30963fce210f22f98956407fe8c8365eb85a1fa530f6f8844137ed" dependencies = [ - "basic-toml", "dissimilar", "glob", "once_cell", @@ -11467,6 +11455,7 @@ dependencies = [ "serde_derive", "serde_json", "termcolor", + "toml", ] [[package]] @@ -11482,7 +11471,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4712ee30d123ec7ae26d1e1b218395a16c87cdbaf4b3925d170d684af62ea5e8" dependencies = [ "async-trait", - "base64 0.13.1", + "base64", "futures", "log", "md-5", @@ -11532,9 +11521,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.10" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" @@ -11604,9 +11593,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.0" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ "getrandom 0.2.8", ] @@ -11700,9 +11689,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -11710,9 +11699,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -11725,9 +11714,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -11737,9 +11726,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11747,9 +11736,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -11760,15 +11749,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wasm-encoder" -version = "0.22.1" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a584273ccc2d9311f1dd19dc3fb26054661fa3e373d53ede5d1144ba07a9acd" +checksum = "05632e0a66a6ed8cca593c24223aabd6262f256c3693ad9822c315285f010614" dependencies = [ "leb128", ] @@ -11972,7 +11961,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830570847f905b8f6d2ca635c33cf42ce701dd8e4abd7d1806c631f8f06e9e4b" dependencies = [ "anyhow", - "base64 0.13.1", + "base64", "bincode", "directories-next", "file-per-thread-logger", @@ -12109,9 +12098,9 @@ dependencies = [ [[package]] name = "wast" -version = "52.0.3" +version = "50.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15942180f265280eede7bc38b239e9770031d1821c02d905284216c645316430" +checksum = "a2cbb59d4ac799842791fe7e806fa5dbbf6b5554d538e51cc8e176db6ff0ae34" dependencies = [ "leb128", "memchr", @@ -12121,18 +12110,18 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.57" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37212100d4cbe6f0f6ff6e707f1e5a5b5b675f0451231ed9e4235e234e127ed3" +checksum = "584aaf7a1ecf4d383bbe1a25eeab0cbb8ff96acc6796707ff65cde48f4632f15" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -12390,9 +12379,9 @@ dependencies = [ [[package]] name = "which" -version = "4.4.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", "libc", @@ -12461,48 +12450,37 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.1", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.42.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.1", + "windows_x86_64_msvc 0.42.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" [[package]] name = "windows_aarch64_msvc" @@ -12512,9 +12490,15 @@ checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" @@ -12524,9 +12508,15 @@ checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" @@ -12536,9 +12526,15 @@ checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" @@ -12548,15 +12544,21 @@ checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" @@ -12566,9 +12568,15 @@ checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "winreg" @@ -12617,7 +12625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fb9bace5b5589ffead1afb76e43e34cff39cd0f3ce7e170ae0c29e53b88eb1c" dependencies = [ "asn1-rs 0.3.1", - "base64 0.13.1", + "base64", "data-encoding", "der-parser 7.0.0", "lazy_static", @@ -12636,7 +12644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0ecbeb7b67ce215e40e3cc7f2ff902f94a223acf44995934763467e7b1febc8" dependencies = [ "asn1-rs 0.5.1", - "base64 0.13.1", + "base64", "data-encoding", "der-parser 8.1.0", "lazy_static", @@ -12718,11 +12726,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.6+zstd.1.5.2" +version = "2.0.4+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" +checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" dependencies = [ "cc", "libc", - "pkg-config", ] diff --git a/frame/support/src/storage/types/key.rs b/frame/support/src/storage/types/key.rs index ef1431cef579a..cf61588ed3a0b 100755 --- a/frame/support/src/storage/types/key.rs +++ b/frame/support/src/storage/types/key.rs @@ -196,8 +196,14 @@ impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P); impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P, Q); impl_encode_like_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, O, P, Q, R); -impl<'a, T: EncodeLike, U: Encode> EncodeLikeTuple for codec::Ref<'a, T, U> {} -impl<'a, T: EncodeLike, U: Encode> crate::storage::private::Sealed for codec::Ref<'a, T, U> {} +impl<'a, T: EncodeLike + EncodeLikeTuple, U: Encode> EncodeLikeTuple + for codec::Ref<'a, T, U> +{ +} +impl<'a, T: EncodeLike + EncodeLikeTuple, U: Encode> crate::storage::private::Sealed + for codec::Ref<'a, T, U> +{ +} /// Trait to indicate that a tuple can be converted into an iterator of a vector of encoded bytes. pub trait TupleToEncodedIter { From f8e411b0679258e4e4be53afbe29c28cce880afe Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 10 Feb 2023 19:11:48 +0200 Subject: [PATCH 31/50] cargo update --- Cargo.lock | 712 ++++++++++++++++++++++++++--------------------------- 1 file changed, 350 insertions(+), 362 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9f0724d8b483..57acd7a73fbe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.0", + "gimli 0.27.1", ] [[package]] @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" +checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "approx" @@ -199,9 +199,9 @@ dependencies = [ [[package]] name = "arbitrary" -version = "1.2.0" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d47fbf90d5149a107494b15a7dc8d69b351be2db3bb9691740e88ec17fd880" +checksum = "3e90af4de65aa7b293ef2d09daff88501eb254f58edde2e1ac02c82d873eadad" [[package]] name = "arc-swap" @@ -308,11 +308,11 @@ checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" [[package]] name = "assert_cmd" -version = "2.0.7" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3d466004a8b4cb1bc34044240a2fd29d17607e2e3bd613eb44fd48e8100da3" +checksum = "9834fcc22e0874394a010230586367d4a3e9f11b560f469262678547e1d2575e" dependencies = [ - "bstr 1.1.0", + "bstr", "doc-comment", "predicates", "predicates-core", @@ -379,9 +379,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.60" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", @@ -403,9 +403,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" [[package]] name = "atty" @@ -435,7 +435,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object 0.30.0", + "object 0.30.3", "rustc-demangle", ] @@ -463,12 +463,27 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "base64ct" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" +[[package]] +name = "basic-toml" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e819b667739967cd44d308b8c7b71305d8bb0729ac44a248aa08f33d01950b4" +dependencies = [ + "serde", +] + [[package]] name = "beef" version = "0.5.2" @@ -546,7 +561,7 @@ name = "binary-merkle-tree" version = "4.0.0-dev" dependencies = [ "array-bytes", - "env_logger", + "env_logger 0.9.3", "hash-db", "log", "sp-core", @@ -564,9 +579,9 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.60.1" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags", "cexpr", @@ -579,6 +594,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn", ] [[package]] @@ -610,24 +626,24 @@ dependencies = [ [[package]] name = "blake2b_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" +checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] name = "blake2s_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" +checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] @@ -640,7 +656,7 @@ dependencies = [ "arrayvec 0.7.2", "cc", "cfg-if", - "constant_time_eq 0.2.4", + "constant_time_eq", ] [[package]] @@ -718,18 +734,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "memchr", -] - -[[package]] -name = "bstr" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b" +checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" dependencies = [ "memchr", "once_cell", @@ -748,9 +755,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byte-slice-cast" @@ -778,9 +785,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bzip2-sys" @@ -795,9 +802,9 @@ dependencies = [ [[package]] name = "camino" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" +checksum = "c77df041dc383319cc661b428b6961a005db4d6808d5e12536931b1ca9556055" dependencies = [ "serde", ] @@ -833,9 +840,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] @@ -911,7 +918,7 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 4.0.32", + "clap 4.1.4", "node-cli", "rand 0.8.5", "sc-chain-spec", @@ -1027,13 +1034,13 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.32" +version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ "bitflags", "clap_derive", - "clap_lex 0.3.0", + "clap_lex 0.3.1", "is-terminal", "once_cell", "strsim", @@ -1042,18 +1049,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.0.7" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10861370d2ba66b0f5989f83ebf35db6421713fd92351790e7fdd6c36774c56b" +checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", ] [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck", "proc-macro-error", @@ -1073,9 +1080,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" dependencies = [ "os_str_bytes", ] @@ -1103,9 +1110,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ "crossbeam-utils", ] @@ -1116,12 +1123,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "constant_time_eq" version = "0.2.4" @@ -1278,18 +1279,18 @@ dependencies = [ [[package]] name = "crc" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" +checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" [[package]] name = "crc32fast" @@ -1495,9 +1496,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-pre.5" +version = "4.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" +checksum = "8da00a7a9a4eb92a0a0f8e75660926d48f0d0f3c537e455c457bcdaa1e16b1ac" dependencies = [ "cfg-if", "fiat-crypto", @@ -1509,9 +1510,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" +checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9" dependencies = [ "cc", "cxxbridge-flags", @@ -1521,9 +1522,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" +checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d" dependencies = [ "cc", "codespan-reporting", @@ -1536,15 +1537,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" +checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a" [[package]] name = "cxxbridge-macro" -version = "1.0.85" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" +checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" dependencies = [ "proc-macro2", "quote", @@ -1553,9 +1554,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" +checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" dependencies = [ "darling_core", "darling_macro", @@ -1563,9 +1564,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" +checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ "fnv", "ident_case", @@ -1577,9 +1578,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" +checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ "darling_core", "quote", @@ -1799,9 +1800,9 @@ dependencies = [ [[package]] name = "dissimilar" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd5f0c7e4bd266b8ab2550e6238d2e74977c23c15536ac7be45e9c95e2e3fbbb" +checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e" [[package]] name = "doc-comment" @@ -1868,9 +1869,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -1905,9 +1906,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" @@ -1976,6 +1977,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "environmental" version = "1.1.4" @@ -2066,24 +2080,24 @@ checksum = "a214f5bb88731d436478f3ae1f8a277b62124089ba9fb67f4f93fb100ef73c90" [[package]] name = "file-per-thread-logger" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" +checksum = "84f2e425d9790201ba4af4630191feac6dcc98765b118d4d18e91d23c2353866" dependencies = [ - "env_logger", + "env_logger 0.10.0", "log", ] [[package]] name = "filetime" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" +checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -2203,7 +2217,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.0.32", + "clap 4.1.4", "comfy-table", "frame-benchmarking", "frame-support", @@ -2294,7 +2308,7 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", @@ -2539,9 +2553,9 @@ dependencies = [ [[package]] name = "fs_extra" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" [[package]] name = "funty" @@ -2551,9 +2565,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -2566,9 +2580,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -2576,15 +2590,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -2594,9 +2608,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-lite" @@ -2615,9 +2629,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", @@ -2631,21 +2645,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" dependencies = [ "futures-io", - "rustls 0.20.7", + "rustls 0.20.8", "webpki 0.22.0", ] [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-timer" @@ -2655,9 +2669,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", @@ -2777,9 +2791,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" [[package]] name = "git2" @@ -2796,18 +2810,18 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ "aho-corasick", - "bstr 0.2.17", + "bstr", "fnv", "log", "regex", @@ -2895,9 +2909,9 @@ checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -2917,6 +2931,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -3053,9 +3073,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -3084,7 +3104,7 @@ dependencies = [ "http", "hyper", "log", - "rustls 0.20.7", + "rustls 0.20.8", "rustls-native-certs", "tokio", "tokio-rustls", @@ -3255,12 +3275,12 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -3283,20 +3303,20 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.1", "io-lifetimes", "rustix", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -3325,9 +3345,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -3913,7 +3933,7 @@ dependencies = [ "parking_lot 0.12.1", "quinn-proto", "rand 0.8.5", - "rustls 0.20.7", + "rustls 0.20.8", "thiserror", "tokio", ] @@ -3996,7 +4016,7 @@ dependencies = [ "libp2p-core", "rcgen 0.10.0", "ring", - "rustls 0.20.7", + "rustls 0.20.8", "thiserror", "webpki 0.22.0", "x509-parser 0.14.0", @@ -4083,9 +4103,9 @@ dependencies = [ [[package]] name = "librocksdb-sys" -version = "0.8.0+7.4.4" +version = "0.8.3+7.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611804e4666a25136fcc5f8cf425ab4d26c7f74ea245ffe92ea23b85b6420b5d" +checksum = "557b255ff04123fcc176162f56ed0c9cd42d8f357cf55b3fabeb60f7413741b3" dependencies = [ "bindgen", "bzip2-sys", @@ -4103,7 +4123,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64", + "base64 0.13.1", "digest 0.9.0", "hmac-drbg", "libsecp256k1-core", @@ -4305,9 +4325,9 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "matrixmultiply" @@ -4538,9 +4558,9 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -4634,9 +4654,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" dependencies = [ "anyhow", "byteorder", @@ -4661,9 +4681,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027" +checksum = "260e21fbb6f3d253a14df90eb0000a6066780a15dd901a7519ce02d77a94985b" dependencies = [ "bytes", "futures", @@ -4703,7 +4723,7 @@ name = "node-bench" version = "0.9.0-dev" dependencies = [ "array-bytes", - "clap 4.0.32", + "clap 4.1.4", "derive_more", "fs_extra", "futures", @@ -4740,7 +4760,7 @@ version = "3.0.0-dev" dependencies = [ "array-bytes", "assert_cmd", - "clap 4.0.32", + "clap 4.1.4", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4859,7 +4879,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4918,7 +4938,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "generate-bags", "kitchensink-runtime", ] @@ -4927,7 +4947,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -5046,9 +5066,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.2" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -5083,9 +5103,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", ] @@ -5156,9 +5176,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.0" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] @@ -5582,7 +5602,7 @@ dependencies = [ "array-bytes", "assert_matches", "bitflags", - "env_logger", + "env_logger 0.9.3", "frame-benchmarking", "frame-support", "frame-system", @@ -5947,7 +5967,7 @@ name = "pallet-mmr" version = "4.0.0-dev" dependencies = [ "array-bytes", - "env_logger", + "env_logger 0.9.3", "frame-benchmarking", "frame-support", "frame-system", @@ -6787,7 +6807,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.5", + "parking_lot_core 0.9.7", ] [[package]] @@ -6806,15 +6826,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -6849,11 +6869,11 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "pem" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c64931a1a212348ec4f3b4362585eca7159d0d09cbdf4a7f74f02173596fd4" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" dependencies = [ - "base64", + "base64 0.13.1", ] [[package]] @@ -6873,9 +6893,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" dependencies = [ "thiserror", "ucd-trie", @@ -6883,9 +6903,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" +checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69" dependencies = [ "pest", "pest_generator", @@ -6893,9 +6913,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" dependencies = [ "pest", "pest_meta", @@ -6906,20 +6926,20 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616" dependencies = [ "once_cell", "pest", - "sha1", + "sha2 0.10.6", ] [[package]] name = "petgraph" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" dependencies = [ "fixedbitset", "indexmap", @@ -7117,9 +7137,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8992a85d8e93a28bdf76137db888d3874e3b230dee5ed8bebac4c9f7617773" +checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" dependencies = [ "proc-macro2", "syn", @@ -7140,11 +7160,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", "thiserror", "toml", ] @@ -7175,9 +7194,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] @@ -7221,9 +7240,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592" +checksum = "21dc42e00223fc37204bd4aa177e69420c604ca4a183209a8f9de30c6d934698" dependencies = [ "bytes", "prost-derive", @@ -7231,9 +7250,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5320c680de74ba083512704acb90fe00f28f79207286a848e730c45dd73ed6" +checksum = "a3f8ad728fb08fe212df3c05169e940fbb6d9d16a877ddde14644a983ba2012e" dependencies = [ "bytes", "heck", @@ -7266,9 +7285,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720" +checksum = "8bda8c0881ea9f722eb9629376db3d0b903b462477c1aafcb0566610ac28ac5d" dependencies = [ "anyhow", "itertools", @@ -7279,9 +7298,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017f79637768cde62820bc2d4fe0e45daaa027755c323ad077767c6c5f173091" +checksum = "a5e0526209433e96d83d750dd81a99118edbc55739e7e61a46764fd2ad537788" dependencies = [ "bytes", "prost", @@ -7332,7 +7351,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.20.7", + "rustls 0.20.8", "slab", "thiserror", "tinyvec", @@ -7463,9 +7482,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -7552,9 +7571,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -7739,16 +7758,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.6" +version = "0.36.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -7757,7 +7776,7 @@ version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64", + "base64 0.13.1", "log", "ring", "sct 0.6.1", @@ -7766,9 +7785,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.7" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", "ring", @@ -7790,11 +7809,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -7968,7 +7987,7 @@ version = "0.10.0-dev" dependencies = [ "array-bytes", "chrono", - "clap 4.0.32", + "clap 4.1.4", "fdlimit", "futures", "futures-timer", @@ -8305,7 +8324,7 @@ dependencies = [ "array-bytes", "assert_matches", "criterion", - "env_logger", + "env_logger 0.9.3", "lru", "num_cpus", "parity-scale-codec", @@ -8777,7 +8796,7 @@ name = "sc-rpc" version = "4.0.0-dev" dependencies = [ "assert_matches", - "env_logger", + "env_logger 0.9.3", "futures", "jsonrpsee", "log", @@ -9002,7 +9021,7 @@ dependencies = [ name = "sc-storage-monitor" version = "0.1.0" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "futures", "log", "nix 0.26.2", @@ -9199,12 +9218,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -9296,9 +9314,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9512ffd81e3a3503ed401f79c33168b9148c75038956039166cd750eaa037c3" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" dependencies = [ "secp256k1-sys", ] @@ -9323,9 +9341,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -9336,9 +9354,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -9399,9 +9417,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", @@ -9421,17 +9439,6 @@ dependencies = [ "opaque-debug 0.3.0", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.6", -] - [[package]] name = "sha2" version = "0.8.2" @@ -9554,14 +9561,14 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" +checksum = "12ba5f4d4ff12bdb6a169ed51b7c48c0e0ac4b0b4b31012b2571e97d78d3201d" dependencies = [ "aes-gcm 0.9.4", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-pre.5", + "curve25519-dalek 4.0.0-rc.0", "rand_core 0.6.4", "ring", "rustc_version 0.4.0", @@ -9585,7 +9592,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ - "base64", + "base64 0.13.1", "bytes", "flate2", "futures", @@ -10073,7 +10080,7 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "honggfuzz", "parity-scale-codec", "rand 0.8.5", @@ -10430,9 +10437,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc" [[package]] name = "spki" @@ -10446,9 +10453,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.36.0" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d92659e7d18d82b803824a9ba5a6022cff101c3491d027c1c1d8d30e749284" +checksum = "e40c020d72bc0a9c5660bb71e4a6fdef081493583062c474740a7d59f55f0e7b" dependencies = [ "Inflector", "num-format", @@ -10533,7 +10540,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7e94b1ec00bad60e6410e058b52f1c66de3dc5fe4d62d09b3e52bb7d3b73e25" dependencies = [ - "base64", + "base64 0.13.1", "crc", "lazy_static", "md-5", @@ -10550,7 +10557,7 @@ dependencies = [ name = "subkey" version = "2.0.2" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "sc-cli", ] @@ -10578,7 +10585,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "frame-support", "frame-system", "sc-cli", @@ -10908,9 +10915,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -10973,12 +10980,11 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.5.2+5.3.0-patched" +version = "0.5.3+5.3.0-patched" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3" +checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8" dependencies = [ "cc", - "fs_extra", "libc", ] @@ -11069,15 +11075,15 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.23.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", @@ -11110,7 +11116,7 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.7", + "rustls 0.20.8", "tokio", "webpki 0.22.0", ] @@ -11142,9 +11148,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +checksum = "bc6a3b08b64e6dfad376fa2432c7b1f01522e37a623c3050bc95db2d3ff21583" dependencies = [ "bytes", "futures-core", @@ -11157,9 +11163,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] @@ -11407,15 +11413,15 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ - "clap 4.0.32", + "clap 4.1.4", "frame-remote-externalities", "frame-try-runtime", "hex", @@ -11444,10 +11450,11 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.74" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "654bfc024d30963fce210f22f98956407fe8c8365eb85a1fa530f6f8844137ed" +checksum = "a44da5a6f2164c8e14d3bbc0657d69c5966af9f5f6930d4f600b1f5c4a673413" dependencies = [ + "basic-toml", "dissimilar", "glob", "once_cell", @@ -11455,7 +11462,6 @@ dependencies = [ "serde_derive", "serde_json", "termcolor", - "toml", ] [[package]] @@ -11471,7 +11477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4712ee30d123ec7ae26d1e1b218395a16c87cdbaf4b3925d170d684af62ea5e8" dependencies = [ "async-trait", - "base64", + "base64 0.13.1", "futures", "log", "md-5", @@ -11521,9 +11527,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" @@ -11593,9 +11599,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom 0.2.8", ] @@ -11689,9 +11695,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -11699,9 +11705,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -11714,9 +11720,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -11726,9 +11732,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11736,9 +11742,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -11749,15 +11755,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-encoder" -version = "0.20.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05632e0a66a6ed8cca593c24223aabd6262f256c3693ad9822c315285f010614" +checksum = "1c3e4bc09095436c8e7584d86d33e6c3ee67045af8fb262cbb9cc321de553428" dependencies = [ "leb128", ] @@ -11853,7 +11859,7 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729" dependencies = [ - "spin 0.9.4", + "spin 0.9.5", "wasmi_arena", "wasmi_core 0.5.0", "wasmparser-nostd", @@ -11961,7 +11967,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830570847f905b8f6d2ca635c33cf42ce701dd8e4abd7d1806c631f8f06e9e4b" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "bincode", "directories-next", "file-per-thread-logger", @@ -12098,9 +12104,9 @@ dependencies = [ [[package]] name = "wast" -version = "50.0.0" +version = "53.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2cbb59d4ac799842791fe7e806fa5dbbf6b5554d538e51cc8e176db6ff0ae34" +checksum = "8244fa24196b1d8fd3ca4a96a3a164c40f846498c5deab6caf414c67340ca4af" dependencies = [ "leb128", "memchr", @@ -12110,18 +12116,18 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.52" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584aaf7a1ecf4d383bbe1a25eeab0cbb8ff96acc6796707ff65cde48f4632f15" +checksum = "4620f1059add6dad511decb9d5d88b4a0a0d3e2e315ed34f79b0dc0dce18aa4b" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", @@ -12379,9 +12385,9 @@ dependencies = [ [[package]] name = "which" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", "libc", @@ -12450,37 +12456,48 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" @@ -12490,15 +12507,9 @@ checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" @@ -12508,15 +12519,9 @@ checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" [[package]] name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" @@ -12526,15 +12531,9 @@ checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" [[package]] name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" @@ -12544,21 +12543,15 @@ checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" @@ -12568,15 +12561,9 @@ checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winreg" @@ -12625,7 +12612,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fb9bace5b5589ffead1afb76e43e34cff39cd0f3ce7e170ae0c29e53b88eb1c" dependencies = [ "asn1-rs 0.3.1", - "base64", + "base64 0.13.1", "data-encoding", "der-parser 7.0.0", "lazy_static", @@ -12644,7 +12631,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0ecbeb7b67ce215e40e3cc7f2ff902f94a223acf44995934763467e7b1febc8" dependencies = [ "asn1-rs 0.5.1", - "base64", + "base64 0.13.1", "data-encoding", "der-parser 8.1.0", "lazy_static", @@ -12726,10 +12713,11 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.4+zstd.1.5.2" +version = "2.0.7+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", "libc", + "pkg-config", ] From 226c24be3c91bfa0e513197ab4462728d21e333a Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 17 Feb 2023 22:23:10 -0800 Subject: [PATCH 32/50] Relocate impl of Sealed for Ref to module root --- frame/support/src/storage/mod.rs | 1 + frame/support/src/storage/types/key.rs | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index dd91d8cc2a335..6a88eb676ea2c 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -1324,6 +1324,7 @@ mod private { impl Sealed for bounded_btree_map::BoundedBTreeMap {} impl Sealed for bounded_btree_set::BoundedBTreeSet {} impl Sealed for BTreeSet {} + impl<'a, T: EncodeLike, U: Encode> Sealed for codec::Ref<'a, T, U> {} macro_rules! impl_sealed_for_tuple { ($($elem:ident),+) => { diff --git a/frame/support/src/storage/types/key.rs b/frame/support/src/storage/types/key.rs index cf61588ed3a0b..3d2e21f30f43c 100755 --- a/frame/support/src/storage/types/key.rs +++ b/frame/support/src/storage/types/key.rs @@ -200,10 +200,6 @@ impl<'a, T: EncodeLike + EncodeLikeTuple, U: Encode> EncodeLikeTuple for codec::Ref<'a, T, U> { } -impl<'a, T: EncodeLike + EncodeLikeTuple, U: Encode> crate::storage::private::Sealed - for codec::Ref<'a, T, U> -{ -} /// Trait to indicate that a tuple can be converted into an iterator of a vector of encoded bytes. pub trait TupleToEncodedIter { From 7b08187ffce74e4c3d6fd9f9c4baf74543317d3c Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 18 Jun 2023 19:35:21 +0300 Subject: [PATCH 33/50] fix StorageEntryMetadata type --- frame/support/src/storage/types/counted_nmap.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 90edc7334c479..c89eafc3824a9 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -19,7 +19,6 @@ //! CountedStoragePrefixedNMap traits and their methods directly. use crate::{ - metadata::StorageEntryMetadata, storage::{ types::{ EncodeLikeTuple, HasKeyPrefix, HasReversibleKeyPrefix, OptionQuery, QueryKindTrait, @@ -31,6 +30,7 @@ use crate::{ Never, }; use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen, Ref}; +use sp_api::metadata_ir::StorageEntryMetadataIR; use sp_runtime::traits::Saturating; use sp_std::prelude::*; @@ -621,7 +621,7 @@ where OnEmpty: Get + 'static, MaxValues: Get>, { - fn build_metadata(docs: Vec<&'static str>, entries: &mut Vec) { + fn build_metadata(docs: Vec<&'static str>, entries: &mut Vec) { ::Map::build_metadata(docs, entries); CounterFor::::build_metadata( vec![&"Counter for the related counted storage map"], @@ -1339,9 +1339,9 @@ mod test { let _ = A::clear(u32::max_value(), None); // one of the item has been removed assert!( - !A::contains_key((2, 20, 200)) && - !A::contains_key((3, 30, 300)) && - !A::contains_key((4, 40, 400)) + !A::contains_key((2, 20, 200)) + && !A::contains_key((3, 30, 300)) + && !A::contains_key((4, 40, 400)) ); assert_eq!(A::count(), 0); From 9c8b3487e837b67c69050f93d4bfa48494ae35b3 Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Sun, 18 Jun 2023 19:35:39 +0300 Subject: [PATCH 34/50] Update frame/support/src/storage/types/nmap.rs Co-authored-by: Guillaume Yu Thiolliere --- frame/support/src/storage/types/nmap.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index c9cd13bc0d402..0fac1fc933706 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Storage map type. Implements StorageNMap, StorageIterableNMap, -//! StoragePrefixedNMap traits and their methods directly. +//! Storage n-map type. Particularly implements `StorageNMap` and `StoragePrefixedMap` +//! traits and their methods directly. use crate::{ metadata_ir::{StorageEntryMetadataIR, StorageEntryTypeIR}, From ac99475784a4d5071d4fbc3b794f95205a4fe586 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 18 Jun 2023 20:15:19 +0300 Subject: [PATCH 35/50] removed StorageNMap and StoragePrefixedMap traits impl --- .../support/src/storage/types/counted_nmap.rs | 154 ++++++------------ 1 file changed, 50 insertions(+), 104 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index c89eafc3824a9..bb5865cee2e7b 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -15,8 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Storage map type. Implements CountedStorageNMap, CountedStorageIterableNMap, -//! CountedStoragePrefixedNMap traits and their methods directly. +//! Counted storage n-map type. use crate::{ storage::{ @@ -87,50 +86,6 @@ impl crate::storage::PrefixIteratorOnRemoval } } -impl - crate::storage::generator::StorageNMap - for CountedStorageNMap -where - Prefix: CountedStorageNMapInstance, - Key: super::key::KeyGenerator, - Value: FullCodec, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - type Query = QueryKind::Query; - fn module_prefix() -> &'static [u8] { - Prefix::pallet_prefix().as_bytes() - } - fn storage_prefix() -> &'static [u8] { - Prefix::STORAGE_PREFIX.as_bytes() - } - fn from_optional_value_to_query(v: Option) -> Self::Query { - QueryKind::from_optional_value_to_query(v) - } - fn from_query_to_optional_value(v: Self::Query) -> Option { - QueryKind::from_query_to_optional_value(v) - } -} - -impl crate::storage::StoragePrefixedMap - for CountedStorageNMap -where - Prefix: CountedStorageNMapInstance, - Key: super::key::KeyGenerator, - Value: FullCodec, - QueryKind: QueryKindTrait, - OnEmpty: Get + 'static, - MaxValues: Get>, -{ - fn module_prefix() -> &'static [u8] { - ::Map::module_prefix() - } - fn storage_prefix() -> &'static [u8] { - ::Map::storage_prefix() - } -} - impl CountedStorageNMap where @@ -670,9 +625,9 @@ mod test { use super::*; use crate::{ hash::{StorageHasher as _, *}, - metadata::{StorageEntryModifier, StorageEntryType, StorageHasher}, storage::types::{Key as NMapKey, ValueQuery}, }; + use sp_api::metadata_ir::{StorageEntryModifierIR, StorageEntryTypeIR, StorageHasherIR}; use sp_io::{hashing::twox_128, TestExternalities}; struct Prefix; @@ -720,15 +675,6 @@ mod test { assert_eq!(AValueQueryWithAnOnEmpty::get((3,)), 10); assert_eq!(A::count(), 1); - // { - // #[crate::storage_alias] - // type Foo = CountedStorageNMap), u32>; - - // assert_eq!(Foo::contains_key((3,)), true); - // assert_eq!(Foo::get((3,)), Some(10)); - // assert_eq!(A::count(), 1); - // } - A::swap::, _, _>((3,), (2,)); assert_eq!(A::contains_key((3,)), false); assert_eq!(A::contains_key((2,)), true); @@ -861,39 +807,39 @@ mod test { assert_eq!( entries, vec![ - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Optional, - ty: StorageEntryType::Map { - hashers: vec![StorageHasher::Blake2_128Concat], + modifier: StorageEntryModifierIR::Optional, + ty: StorageEntryTypeIR::Map { + hashers: vec![StorageHasherIR::Blake2_128Concat], key: scale_info::meta_type::(), value: scale_info::meta_type::(), }, default: Option::::None.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Map { - hashers: vec![StorageHasher::Blake2_128Concat], + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Map { + hashers: vec![StorageHasherIR::Blake2_128Concat], key: scale_info::meta_type::(), value: scale_info::meta_type::(), }, default: 98u32.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, @@ -1102,13 +1048,13 @@ mod test { assert_eq!( entries, vec![ - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Optional, - ty: StorageEntryType::Map { + modifier: StorageEntryModifierIR::Optional, + ty: StorageEntryTypeIR::Map { hashers: vec![ - StorageHasher::Blake2_128Concat, - StorageHasher::Twox64Concat + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Twox64Concat ], key: scale_info::meta_type::<(u16, u8)>(), value: scale_info::meta_type::(), @@ -1116,20 +1062,20 @@ mod test { default: Option::::None.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Map { + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Map { hashers: vec![ - StorageHasher::Blake2_128Concat, - StorageHasher::Twox64Concat + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Twox64Concat ], key: scale_info::meta_type::<(u16, u8)>(), value: scale_info::meta_type::(), @@ -1137,10 +1083,10 @@ mod test { default: 98u32.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, @@ -1380,14 +1326,14 @@ mod test { assert_eq!( entries, vec![ - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Optional, - ty: StorageEntryType::Map { + modifier: StorageEntryModifierIR::Optional, + ty: StorageEntryTypeIR::Map { hashers: vec![ - StorageHasher::Blake2_128Concat, - StorageHasher::Blake2_128Concat, - StorageHasher::Twox64Concat + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Twox64Concat ], key: scale_info::meta_type::<(u16, u16, u16)>(), value: scale_info::meta_type::(), @@ -1395,21 +1341,21 @@ mod test { default: Option::::None.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Map { + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Map { hashers: vec![ - StorageHasher::Blake2_128Concat, - StorageHasher::Blake2_128Concat, - StorageHasher::Twox64Concat + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Blake2_128Concat, + StorageHasherIR::Twox64Concat ], key: scale_info::meta_type::<(u16, u16, u16)>(), value: scale_info::meta_type::(), @@ -1417,10 +1363,10 @@ mod test { default: 98u32.encode(), docs: vec![], }, - StorageEntryMetadata { + StorageEntryMetadataIR { name: "Foo", - modifier: StorageEntryModifier::Default, - ty: StorageEntryType::Plain(scale_info::meta_type::()), + modifier: StorageEntryModifierIR::Default, + ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], docs: vec!["Counter for the related counted storage map"], }, From 687ddfadfe61985ab94c852ac99c0b4794ca8391 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Mon, 19 Jun 2023 10:13:37 +0300 Subject: [PATCH 36/50] fix tests --- .../support/src/storage/types/counted_nmap.rs | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index bb5865cee2e7b..200301efc4afa 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -823,7 +823,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, StorageEntryMetadataIR { name: "Foo", @@ -841,7 +845,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, ] ); @@ -1067,7 +1075,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, StorageEntryMetadataIR { name: "Foo", @@ -1088,7 +1100,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, ] ); @@ -1346,7 +1362,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, StorageEntryMetadataIR { name: "Foo", @@ -1368,7 +1388,11 @@ mod test { modifier: StorageEntryModifierIR::Default, ty: StorageEntryTypeIR::Plain(scale_info::meta_type::()), default: vec![0, 0, 0, 0], - docs: vec!["Counter for the related counted storage map"], + docs: if cfg!(feature = "no-metadata-docs") { + vec![] + } else { + vec!["Counter for the related counted storage map"] + }, }, ] ); From 2cfb6ca4ce27a6c45749e14067439957486b0fb4 Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Mon, 19 Jun 2023 20:41:02 +0300 Subject: [PATCH 37/50] Update frame/support/src/storage/types/counted_nmap.rs Co-authored-by: Guillaume Yu Thiolliere --- frame/support/src/storage/types/counted_nmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 200301efc4afa..699f36be9aa9a 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -60,7 +60,7 @@ pub trait CountedStorageNMapInstance: StorageInstance { type CounterPrefix: StorageInstance; } -// Private helper trait to access map from counted storage double map +// Private helper trait to access map from counted storage n-map trait MapWrapper { type Map; } From ff2fa82d0162b044a360039d8fc744c23cbd176d Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Wed, 21 Jun 2023 12:32:41 +0300 Subject: [PATCH 38/50] extend pallet::storage macro with CountedStorageNMap usage --- .../procedural/src/pallet/expand/storage.rs | 81 ++++++++--- .../procedural/src/pallet/parse/storage.rs | 131 ++++++++++++------ 2 files changed, 145 insertions(+), 67 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/storage.rs b/frame/support/procedural/src/pallet/expand/storage.rs index 253b429bb6eb3..b2c75d9cd1eab 100644 --- a/frame/support/procedural/src/pallet/expand/storage.rs +++ b/frame/support/procedural/src/pallet/expand/storage.rs @@ -60,7 +60,7 @@ fn check_prefix_duplicates( if let Some(other_dup_err) = used_prefixes.insert(prefix.clone(), dup_err.clone()) { let mut err = dup_err; err.combine(other_dup_err); - return Err(err) + return Err(err); } if let Metadata::CountedMap { .. } = storage_def.metadata { @@ -77,7 +77,7 @@ fn check_prefix_duplicates( if let Some(other_dup_err) = used_prefixes.insert(counter_prefix, counter_dup_err.clone()) { let mut err = counter_dup_err; err.combine(other_dup_err); - return Err(err) + return Err(err); } } @@ -150,7 +150,7 @@ pub fn process_generics(def: &mut Def) -> syn::Result syn::Result syn::Result { - args.args.push(syn::GenericArgument::Type(hasher)); - args.args.push(syn::GenericArgument::Type(key)); - args.args.push(syn::GenericArgument::Type(value.clone())); - let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); - set_result_query_type_parameter(&mut query_kind)?; - args.args.push(syn::GenericArgument::Type(query_kind)); - let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value)); - args.args.push(syn::GenericArgument::Type(on_empty)); - let max_values = max_values.unwrap_or_else(|| default_max_values.clone()); - args.args.push(syn::GenericArgument::Type(max_values)); - }, - StorageGenerics::CountedMap { + StorageGenerics::Map { hasher, key, value, query_kind, on_empty, max_values } + | StorageGenerics::CountedMap { hasher, key, value, @@ -248,7 +237,14 @@ pub fn process_generics(def: &mut Def) -> syn::Result { + StorageGenerics::NMap { keygen, value, query_kind, on_empty, max_values } + | StorageGenerics::CountedNMap { + keygen, + value, + query_kind, + on_empty, + max_values, + } => { args.args.push(syn::GenericArgument::Type(keygen)); args.args.push(syn::GenericArgument::Type(value.clone())); let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); @@ -265,7 +261,7 @@ pub fn process_generics(def: &mut Def) -> syn::Result (1, 2, 3), - Metadata::NMap { .. } => (2, 3, 4), + Metadata::NMap { .. } | Metadata::CountedNMap { .. } => (2, 3, 4), Metadata::Map { .. } | Metadata::CountedMap { .. } => (3, 4, 5), Metadata::DoubleMap { .. } => (5, 6, 7), }; @@ -295,8 +291,8 @@ pub fn process_generics(def: &mut Def) -> syn::Result= args.args.len() && - matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _))) + if on_empty_idx >= args.args.len() + && matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _))) { let value_ty = match args.args[value_idx].clone() { syn::GenericArgument::Type(ty) => ty, @@ -359,6 +355,17 @@ fn augment_final_docs(def: &mut Def) { ); push_string_literal(&doc_line, storage); }, + Metadata::CountedNMap { keys, value, .. } => { + let doc_line = format!( + "Storage type is [`CountedStorageNMap`] with keys type ({}) and value type {}.", + keys.iter() + .map(|k| k.to_token_stream().to_string()) + .collect::>() + .join(", "), + value.to_token_stream() + ); + push_string_literal(&doc_line, storage); + }, Metadata::CountedMap { key, value } => { let doc_line = format!( "Storage type is [`CountedStorageMap`] with key type {} and value type {}.", @@ -393,7 +400,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { .filter_map(|storage_def| check_prefix_duplicates(storage_def, &mut prefix_set).err()); if let Some(mut final_error) = errors.next() { errors.for_each(|error| final_error.combine(error)); - return final_error.into_compile_error() + return final_error.into_compile_error(); } let frame_support = &def.frame_support; @@ -579,6 +586,36 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { } ) }, + Metadata::CountedNMap { keygen, value, .. } => { + let query = match storage.query_kind.as_ref().expect("Checked by def") { + QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => + Option<#value> + ), + QueryKind::ResultQuery(error_path, _) => { + quote::quote_spanned!(storage.attr_span => + Result<#value, #error_path> + ) + }, + QueryKind::ValueQuery => quote::quote!(#value), + }; + quote::quote_spanned!(storage.attr_span => + #(#cfg_attrs)* + impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { + #[doc = #getter_doc_line] + pub fn #getter(key: KArg) -> #query + where + KArg: #frame_support::storage::types::EncodeLikeTuple< + <#keygen as #frame_support::storage::types::KeyGenerator>::KArg + > + + #frame_support::storage::types::TupleToEncodedIter, + { + // NOTE: we can't use any trait here because CountedStorageNMap + // doesn't implement any. + <#full_ident>::get(key) + } + } + ) + }, } } else { Default::default() diff --git a/frame/support/procedural/src/pallet/parse/storage.rs b/frame/support/procedural/src/pallet/parse/storage.rs index 12e06b214b6b6..80eb2759bb5a0 100644 --- a/frame/support/procedural/src/pallet/parse/storage.rs +++ b/frame/support/procedural/src/pallet/parse/storage.rs @@ -49,10 +49,10 @@ pub enum PalletStorageAttr { impl PalletStorageAttr { fn attr_span(&self) -> proc_macro2::Span { match self { - Self::Getter(_, span) | - Self::StorageName(_, span) | - Self::Unbounded(span) | - Self::WhitelistStorage(span) => *span, + Self::Getter(_, span) + | Self::StorageName(_, span) + | Self::Unbounded(span) + | Self::WhitelistStorage(span) => *span, } } } @@ -115,15 +115,17 @@ impl PalletStorageAttrInfo { for attr in attrs { match attr { PalletStorageAttr::Getter(ident, ..) if getter.is_none() => getter = Some(ident), - PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => - rename_as = Some(name), + PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => { + rename_as = Some(name) + }, PalletStorageAttr::Unbounded(..) if !unbounded => unbounded = true, PalletStorageAttr::WhitelistStorage(..) if !whitelisted => whitelisted = true, - attr => + attr => { return Err(syn::Error::new( attr.attr_span(), "Invalid attribute: Duplicate attribute", - )), + )) + }, } } @@ -138,6 +140,7 @@ pub enum Metadata { CountedMap { value: syn::Type, key: syn::Type }, DoubleMap { value: syn::Type, key1: syn::Type, key2: syn::Type }, NMap { keys: Vec, keygen: syn::Type, value: syn::Type }, + CountedNMap { keys: Vec, keygen: syn::Type, value: syn::Type }, } pub enum QueryKind { @@ -230,6 +233,13 @@ pub enum StorageGenerics { on_empty: Option, max_values: Option, }, + CountedNMap { + keygen: syn::Type, + value: syn::Type, + query_kind: Option, + on_empty: Option, + max_values: Option, + }, } impl StorageGenerics { @@ -240,8 +250,12 @@ impl StorageGenerics { Self::Map { value, key, .. } => Metadata::Map { value, key }, Self::CountedMap { value, key, .. } => Metadata::CountedMap { value, key }, Self::Value { value, .. } => Metadata::Value { value }, - Self::NMap { keygen, value, .. } => - Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value }, + Self::NMap { keygen, value, .. } => { + Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value } + }, + Self::CountedNMap { keygen, value, .. } => { + Metadata::CountedNMap { keys: collect_keys(&keygen)?, keygen, value } + }, }; Ok(res) @@ -250,11 +264,12 @@ impl StorageGenerics { /// Return the query kind from the defined generics fn query_kind(&self) -> Option { match &self { - Self::DoubleMap { query_kind, .. } | - Self::Map { query_kind, .. } | - Self::CountedMap { query_kind, .. } | - Self::Value { query_kind, .. } | - Self::NMap { query_kind, .. } => query_kind.clone(), + Self::DoubleMap { query_kind, .. } + | Self::Map { query_kind, .. } + | Self::CountedMap { query_kind, .. } + | Self::Value { query_kind, .. } + | Self::NMap { query_kind, .. } + | Self::CountedNMap { query_kind, .. } => query_kind.clone(), } } } @@ -265,6 +280,7 @@ enum StorageKind { CountedMap, DoubleMap, NMap, + CountedNMap, } /// Check the generics in the `map` contains the generics in `gen` may contains generics in @@ -295,8 +311,8 @@ fn check_generics( }; for (gen_name, gen_binding) in map { - if !mandatory_generics.contains(&gen_name.as_str()) && - !optional_generics.contains(&gen_name.as_str()) + if !mandatory_generics.contains(&gen_name.as_str()) + && !optional_generics.contains(&gen_name.as_str()) { let msg = format!( "Invalid pallet::storage, Unexpected generic `{}` for `{}`. {}", @@ -342,7 +358,7 @@ fn process_named_generics( let msg = "Invalid pallet::storage, Duplicated named generic"; let mut err = syn::Error::new(arg.ident.span(), msg); err.combine(syn::Error::new(other.ident.span(), msg)); - return Err(err) + return Err(err); } parsed.insert(arg.ident.to_string(), arg.clone()); } @@ -493,6 +509,29 @@ fn process_named_generics( max_values: parsed.remove("MaxValues").map(|binding| binding.ty), } }, + StorageKind::CountedNMap => { + check_generics( + &parsed, + &["Key", "Value"], + &["QueryKind", "OnEmpty", "MaxValues"], + "CountedStorageNMap", + args_span, + )?; + + StorageGenerics::CountedNMap { + keygen: parsed + .remove("Key") + .map(|binding| binding.ty) + .expect("checked above as mandatory generic"), + value: parsed + .remove("Value") + .map(|binding| binding.ty) + .expect("checked above as mandatory generic"), + query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), + on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), + max_values: parsed.remove("MaxValues").map(|binding| binding.ty), + } + }, }; let metadata = generics.metadata()?; @@ -544,20 +583,15 @@ fn process_unnamed_generics( }; let res = match storage { - StorageKind::Value => - (None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false), - StorageKind::Map => ( + StorageKind::Value => { + (None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false) + }, + StorageKind::Map | StorageKind::CountedMap => ( None, Metadata::Map { key: retrieve_arg(2)?, value: retrieve_arg(3)? }, retrieve_arg(4).ok(), use_default_hasher(1)?, ), - StorageKind::CountedMap => ( - None, - Metadata::CountedMap { key: retrieve_arg(2)?, value: retrieve_arg(3)? }, - retrieve_arg(4).ok(), - use_default_hasher(1)?, - ), StorageKind::DoubleMap => ( None, Metadata::DoubleMap { @@ -568,7 +602,7 @@ fn process_unnamed_generics( retrieve_arg(6).ok(), use_default_hasher(1)? && use_default_hasher(3)?, ), - StorageKind::NMap => { + StorageKind::NMap | StorageKind::CountedNMap => { let keygen = retrieve_arg(1)?; let keys = collect_keys(&keygen)?; ( @@ -594,6 +628,7 @@ fn process_generics( "CountedStorageMap" => StorageKind::CountedMap, "StorageDoubleMap" => StorageKind::DoubleMap, "StorageNMap" => StorageKind::NMap, + "CountedStorageNMap" => StorageKind::CountedNMap, found => { let msg = format!( "Invalid pallet::storage, expected ident: `StorageValue` or \ @@ -601,7 +636,7 @@ fn process_generics( in order to expand metadata, found `{}`.", found, ); - return Err(syn::Error::new(segment.ident.span(), msg)) + return Err(syn::Error::new(segment.ident.span(), msg)); }, }; @@ -612,7 +647,7 @@ fn process_generics( _ => { let msg = "Invalid pallet::storage, invalid number of generic generic arguments, \ expect more that 0 generic arguments."; - return Err(syn::Error::new(segment.span(), msg)) + return Err(syn::Error::new(segment.span(), msg)); }, }; @@ -659,7 +694,7 @@ fn extract_key(ty: &syn::Type) -> syn::Result { typ } else { let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(ty.span(), msg)) + return Err(syn::Error::new(ty.span(), msg)); }; let key_struct = typ.path.segments.last().ok_or_else(|| { @@ -668,14 +703,14 @@ fn extract_key(ty: &syn::Type) -> syn::Result { })?; if key_struct.ident != "Key" && key_struct.ident != "NMapKey" { let msg = "Invalid pallet::storage, expected Key or NMapKey struct"; - return Err(syn::Error::new(key_struct.ident.span(), msg)) + return Err(syn::Error::new(key_struct.ident.span(), msg)); } let ty_params = if let syn::PathArguments::AngleBracketed(args) = &key_struct.arguments { args } else { let msg = "Invalid pallet::storage, expected angle bracketed arguments"; - return Err(syn::Error::new(key_struct.arguments.span(), msg)) + return Err(syn::Error::new(key_struct.arguments.span(), msg)); }; if ty_params.args.len() != 2 { @@ -684,14 +719,14 @@ fn extract_key(ty: &syn::Type) -> syn::Result { for Key struct, expected 2 args, found {}", ty_params.args.len() ); - return Err(syn::Error::new(ty_params.span(), msg)) + return Err(syn::Error::new(ty_params.span(), msg)); } let key = match &ty_params.args[1] { syn::GenericArgument::Type(key_ty) => key_ty.clone(), _ => { let msg = "Invalid pallet::storage, expected type"; - return Err(syn::Error::new(ty_params.args[1].span(), msg)) + return Err(syn::Error::new(ty_params.args[1].span(), msg)); }, }; @@ -725,7 +760,7 @@ impl StorageDef { let item = if let syn::Item::Type(item) = item { item } else { - return Err(syn::Error::new(item.span(), "Invalid pallet::storage, expect item type.")) + return Err(syn::Error::new(item.span(), "Invalid pallet::storage, expect item type.")); }; let attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; @@ -745,12 +780,12 @@ impl StorageDef { typ } else { let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(item.ty.span(), msg)) + return Err(syn::Error::new(item.ty.span(), msg)); }; if typ.path.segments.len() != 1 { let msg = "Invalid pallet::storage, expected type path with one segment"; - return Err(syn::Error::new(item.ty.span(), msg)) + return Err(syn::Error::new(item.ty.span(), msg)); } let (named_generics, metadata, query_kind, use_default_hasher) = @@ -770,16 +805,22 @@ impl StorageDef { .segments .last() .map_or(false, |s| s.ident == "OptionQuery") => - return Ok(Some(QueryKind::OptionQuery)), + { + return Ok(Some(QueryKind::OptionQuery)) + }, Type::Path(TypePath { path: Path { segments, .. }, .. }) if segments.last().map_or(false, |s| s.ident == "ResultQuery") => + { segments .last() .expect("segments is checked to have the last value; qed") - .clone(), + .clone() + }, Type::Path(path) if path.path.segments.last().map_or(false, |s| s.ident == "ValueQuery") => - return Ok(Some(QueryKind::ValueQuery)), + { + return Ok(Some(QueryKind::ValueQuery)) + }, _ => return Ok(None), }; @@ -793,7 +834,7 @@ impl StorageDef { for ResultQuery, expected 1 type argument, found {}", args.len(), ); - return Err(syn::Error::new(args.span(), msg)) + return Err(syn::Error::new(args.span(), msg)); } args[0].clone() @@ -804,7 +845,7 @@ impl StorageDef { expected angle-bracketed arguments, found `{}`", args.to_token_stream().to_string() ); - return Err(syn::Error::new(args.span(), msg)) + return Err(syn::Error::new(args.span(), msg)); }, }; @@ -820,7 +861,7 @@ impl StorageDef { segments, found {}", err_variant.len(), ); - return Err(syn::Error::new(err_variant.span(), msg)) + return Err(syn::Error::new(err_variant.span(), msg)); } let mut error = err_variant.clone(); let err_variant = error @@ -856,7 +897,7 @@ impl StorageDef { let msg = "Invalid pallet::storage, cannot generate getter because QueryKind is not \ identifiable. QueryKind must be `OptionQuery`, `ResultQuery`, `ValueQuery`, or default \ one to be identifiable."; - return Err(syn::Error::new(getter.span(), msg)) + return Err(syn::Error::new(getter.span(), msg)); } Ok(StorageDef { From c9c3efedc666cc024680babbaf87ce6bb0be9a79 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Wed, 21 Jun 2023 20:39:04 +0300 Subject: [PATCH 39/50] fix --- .../procedural/src/pallet/parse/storage.rs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/frame/support/procedural/src/pallet/parse/storage.rs b/frame/support/procedural/src/pallet/parse/storage.rs index 80eb2759bb5a0..c98134881041d 100644 --- a/frame/support/procedural/src/pallet/parse/storage.rs +++ b/frame/support/procedural/src/pallet/parse/storage.rs @@ -586,12 +586,18 @@ fn process_unnamed_generics( StorageKind::Value => { (None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false) }, - StorageKind::Map | StorageKind::CountedMap => ( + StorageKind::Map => ( None, Metadata::Map { key: retrieve_arg(2)?, value: retrieve_arg(3)? }, retrieve_arg(4).ok(), use_default_hasher(1)?, ), + StorageKind::CountedMap => ( + None, + Metadata::CountedMap { key: retrieve_arg(2)?, value: retrieve_arg(3)? }, + retrieve_arg(4).ok(), + use_default_hasher(1)?, + ), StorageKind::DoubleMap => ( None, Metadata::DoubleMap { @@ -602,7 +608,7 @@ fn process_unnamed_generics( retrieve_arg(6).ok(), use_default_hasher(1)? && use_default_hasher(3)?, ), - StorageKind::NMap | StorageKind::CountedNMap => { + StorageKind::NMap => { let keygen = retrieve_arg(1)?; let keys = collect_keys(&keygen)?; ( @@ -612,6 +618,16 @@ fn process_unnamed_generics( false, ) }, + StorageKind::CountedNMap => { + let keygen = retrieve_arg(1)?; + let keys = collect_keys(&keygen)?; + ( + None, + Metadata::CountedNMap { keys, keygen, value: retrieve_arg(2)? }, + retrieve_arg(3).ok(), + false, + ) + }, }; Ok(res) @@ -632,7 +648,7 @@ fn process_generics( found => { let msg = format!( "Invalid pallet::storage, expected ident: `StorageValue` or \ - `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` \ + `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` or `CountedStorageNMap` \ in order to expand metadata, found `{}`.", found, ); From 918f8e736bff280ba64ac58becd07ed53efec354 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Thu, 29 Jun 2023 22:51:19 +0300 Subject: [PATCH 40/50] add tests --- frame/support/test/tests/pallet.rs | 35 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index d0efcb3b5c18f..65807c2617f96 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -116,7 +116,7 @@ impl SomeAssociation2 for u64 { #[doc = include_str!("../../README.md")] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + use frame_support::{pallet_prelude::*, storage::types::CountedStorageNMap}; use frame_system::pallet_prelude::*; use sp_runtime::DispatchResult; @@ -365,6 +365,27 @@ pub mod pallet { ResultQuery::NonExistentStorageValue>, >; + #[pallet::storage] + #[pallet::getter(fn nmap)] + pub type CountedNMap = CountedStorageNMap<_, storage::Key, u32>; + + #[pallet::storage] + #[pallet::getter(fn nmap2)] + pub type CountedNMap2 = CountedStorageNMap< + Key = (NMapKey, NMapKey), + Value = u64, + MaxValues = ConstU32<11>, + >; + + #[pallet::storage] + #[pallet::getter(fn nmap3)] + pub type CountedNMap3 = CountedStorageNMap< + _, + (NMapKey, NMapKey), + u128, + ResultQuery::NonExistentStorageValue>, + >; + #[pallet::storage] #[pallet::getter(fn conditional_value)] #[cfg(feature = "frame-feature-testing")] @@ -438,7 +459,7 @@ pub mod pallet { let _ = T::AccountId::from(SomeType1); // Test for where clause let _ = T::AccountId::from(SomeType5); // Test for where clause if matches!(call, Call::foo_storage_layer { .. }) { - return Ok(ValidTransaction::default()) + return Ok(ValidTransaction::default()); } Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) } @@ -1628,9 +1649,9 @@ fn metadata() { }, ]; - let empty_doc = pallets[0].event.as_ref().unwrap().ty.type_info().docs.is_empty() && - pallets[0].error.as_ref().unwrap().ty.type_info().docs.is_empty() && - pallets[0].calls.as_ref().unwrap().ty.type_info().docs.is_empty(); + let empty_doc = pallets[0].event.as_ref().unwrap().ty.type_info().docs.is_empty() + && pallets[0].error.as_ref().unwrap().ty.type_info().docs.is_empty() + && pallets[0].calls.as_ref().unwrap().ty.type_info().docs.is_empty(); if cfg!(feature = "no-metadata-docs") { assert!(empty_doc) @@ -2108,8 +2129,8 @@ fn post_runtime_upgrade_detects_storage_version_issues() { Example::on_genesis(); // The version isn't changed, we should detect it. assert!( - Executive::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost).unwrap_err() == - "On chain and current storage version do not match. Missing runtime upgrade?" + Executive::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost).unwrap_err() + == "On chain and current storage version do not match. Missing runtime upgrade?" .into() ); }); From 2aa851bb3e444f02a29e602572ca8615fdda934b Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 30 Jun 2023 10:22:00 +0300 Subject: [PATCH 41/50] fix --- frame/support/test/tests/pallet.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 65807c2617f96..16225878ca093 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -366,11 +366,11 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn nmap)] + #[pallet::getter(fn counted_nmap)] pub type CountedNMap = CountedStorageNMap<_, storage::Key, u32>; #[pallet::storage] - #[pallet::getter(fn nmap2)] + #[pallet::getter(fn counted_nmap2)] pub type CountedNMap2 = CountedStorageNMap< Key = (NMapKey, NMapKey), Value = u64, @@ -378,7 +378,7 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn nmap3)] + #[pallet::getter(fn counted_nmap3)] pub type CountedNMap3 = CountedStorageNMap< _, (NMapKey, NMapKey), @@ -409,6 +409,15 @@ pub mod pallet { pub type ConditionalNMap = StorageNMap<_, (storage::Key, storage::Key), u32>; + #[cfg(feature = "frame-feature-testing")] + #[pallet::storage] + #[pallet::getter(fn conditional_counted_nmap)] + pub type ConditionalCountedNMap = CountedStorageNMap< + _, + (storage::Key, storage::Key), + u32, + >; + #[pallet::storage] #[pallet::storage_prefix = "RenamedCountedMap"] #[pallet::getter(fn counted_storage_map)] From 1d192b69dc90cb09d5564520be5b9f4e27e6eb25 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Fri, 30 Jun 2023 16:06:42 +0300 Subject: [PATCH 42/50] fix --- .../procedural/src/pallet/expand/storage.rs | 100 ++++++++++++------ frame/support/src/lib.rs | 6 +- frame/support/test/tests/pallet.rs | 2 +- 3 files changed, 71 insertions(+), 37 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/storage.rs b/frame/support/procedural/src/pallet/expand/storage.rs index b2c75d9cd1eab..fcf94b9efa44f 100644 --- a/frame/support/procedural/src/pallet/expand/storage.rs +++ b/frame/support/procedural/src/pallet/expand/storage.rs @@ -632,40 +632,74 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { let cfg_attrs = &storage_def.cfg_attrs; - let maybe_counter = if let Metadata::CountedMap { .. } = storage_def.metadata { - let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); - let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); - - quote::quote_spanned!(storage_def.attr_span => - #(#cfg_attrs)* - #[doc(hidden)] - #prefix_struct_vis struct #counter_prefix_struct_ident<#type_use_gen>( - core::marker::PhantomData<(#type_use_gen,)> - ); - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::traits::StorageInstance - for #counter_prefix_struct_ident<#type_use_gen> - #config_where_clause - { - fn pallet_prefix() -> &'static str { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name::>() - .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") + let maybe_counter = match storage_def.metadata { + Metadata::CountedMap { .. } => { + let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); + let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); + + quote::quote_spanned!(storage_def.attr_span => + #(#cfg_attrs)* + #[doc(hidden)] + #prefix_struct_vis struct #counter_prefix_struct_ident<#type_use_gen>( + core::marker::PhantomData<(#type_use_gen,)> + ); + #(#cfg_attrs)* + impl<#type_impl_gen> #frame_support::traits::StorageInstance + for #counter_prefix_struct_ident<#type_use_gen> + #config_where_clause + { + fn pallet_prefix() -> &'static str { + < + ::PalletInfo + as #frame_support::traits::PalletInfo + >::name::>() + .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") + } + const STORAGE_PREFIX: &'static str = #counter_prefix_struct_const; } - const STORAGE_PREFIX: &'static str = #counter_prefix_struct_const; - } - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::storage::types::CountedStorageMapInstance - for #prefix_struct_ident<#type_use_gen> - #config_where_clause - { - type CounterPrefix = #counter_prefix_struct_ident<#type_use_gen>; - } - ) - } else { - proc_macro2::TokenStream::default() + #(#cfg_attrs)* + impl<#type_impl_gen> #frame_support::storage::types::CountedStorageMapInstance + for #prefix_struct_ident<#type_use_gen> + #config_where_clause + { + type CounterPrefix = #counter_prefix_struct_ident<#type_use_gen>; + } + ) + }, + Metadata::CountedNMap { .. } => { + let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); + let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); + + quote::quote_spanned!(storage_def.attr_span => + #(#cfg_attrs)* + #[doc(hidden)] + #prefix_struct_vis struct #counter_prefix_struct_ident<#type_use_gen>( + core::marker::PhantomData<(#type_use_gen,)> + ); + #(#cfg_attrs)* + impl<#type_impl_gen> #frame_support::traits::StorageInstance + for #counter_prefix_struct_ident<#type_use_gen> + #config_where_clause + { + fn pallet_prefix() -> &'static str { + < + ::PalletInfo + as #frame_support::traits::PalletInfo + >::name::>() + .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") + } + const STORAGE_PREFIX: &'static str = #counter_prefix_struct_const; + } + #(#cfg_attrs)* + impl<#type_impl_gen> #frame_support::storage::types::CountedStorageNMapInstance + for #prefix_struct_ident<#type_use_gen> + #config_where_clause + { + type CounterPrefix = #counter_prefix_struct_ident<#type_use_gen>; + } + ) + }, + _ => proc_macro2::TokenStream::default(), }; quote::quote_spanned!(storage_def.attr_span => diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 0f2b135eed323..1564efe68db1c 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -694,7 +694,7 @@ pub use frame_support_procedural::crate_to_crate_version; #[macro_export] macro_rules! fail { ( $y:expr ) => {{ - return Err($y.into()) + return Err($y.into()); }}; } @@ -1548,8 +1548,8 @@ pub mod pallet_prelude { storage::{ bounded_vec::BoundedVec, types::{ - CountedStorageMap, Key as NMapKey, OptionQuery, ResultQuery, StorageDoubleMap, - StorageMap, StorageNMap, StorageValue, ValueQuery, + CountedStorageMap, CountedStorageNMap, Key as NMapKey, OptionQuery, ResultQuery, + StorageDoubleMap, StorageMap, StorageNMap, StorageValue, ValueQuery, }, }, traits::{ diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 16225878ca093..9975538d899f9 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -116,7 +116,7 @@ impl SomeAssociation2 for u64 { #[doc = include_str!("../../README.md")] pub mod pallet { use super::*; - use frame_support::{pallet_prelude::*, storage::types::CountedStorageNMap}; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_runtime::DispatchResult; From 88d4423ce38219e6c7f5de938678c3fd9bb25960 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 8 Jul 2023 11:38:44 +0300 Subject: [PATCH 43/50] Add counter_storage_final_key(), map_storage_final_prefix() functions --- frame/support/src/storage/types/counted_nmap.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 699f36be9aa9a..5f15437873a56 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -96,6 +96,17 @@ where OnEmpty: Get + 'static, MaxValues: Get>, { + /// The key used to store the counter of the map. + pub fn counter_storage_final_key() -> [u8; 32] { + CounterFor::::hashed_key() + } + + /// The prefix used to generate the key of the map. + pub fn map_storage_final_prefix() -> Vec { + use crate::storage::generator::StorageNMap; + ::Map::prefix_hash() + } + /// Get the storage key used to fetch a value corresponding to a specific key. pub fn hashed_key_for + TupleToEncodedIter>( key: KArg, From 3f72c95cc23ca99d336f2d26605fb9c4b019fc77 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jul 2023 11:37:54 +0300 Subject: [PATCH 44/50] update tests --- frame/support/test/tests/pallet.rs | 167 +++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 046ada16ac868..b6bc5c764d164 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1166,6 +1166,30 @@ fn storage_expand() { Err(pallet::Error::::NonExistentStorageValue), ); + pallet::CountedNMap::::insert((&1,), &3); + let mut k = [twox_128(b"Example"), twox_128(b"CountedNMap")].concat(); + k.extend(1u8.using_encoded(blake2_128_concat)); + assert_eq!(unhashed::get::(&k), Some(3u32)); + assert_eq!(pallet::CountedNMap::::count(), 1); + + pallet::CountedNMap2::::insert((&1, &2), &3); + let mut k = [twox_128(b"Example"), twox_128(b"CountedNMap2")].concat(); + k.extend(1u16.using_encoded(twox_64_concat)); + k.extend(2u32.using_encoded(blake2_128_concat)); + assert_eq!(unhashed::get::(&k), Some(3u64)); + assert_eq!(pallet::CountedNMap2::::count(), 1); + + pallet::CountedNMap3::::insert((&1, &2), &3); + let mut k = [twox_128(b"Example"), twox_128(b"CountedNMap3")].concat(); + k.extend(1u8.using_encoded(blake2_128_concat)); + k.extend(2u16.using_encoded(twox_64_concat)); + assert_eq!(pallet::CountedNMap3::::count(), 1); + assert_eq!(unhashed::get::(&k), Some(3u128)); + assert_eq!( + pallet::CountedNMap3::::get((2, 3)), + Err(pallet::Error::::NonExistentStorageValue), + ); + #[cfg(feature = "frame-feature-testing")] { pallet::ConditionalValue::::put(1); @@ -1486,6 +1510,66 @@ fn metadata() { default: vec![1, 1], docs: vec![], }, + StorageEntryMetadata { + name: "CountedNMap", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + key: meta_type::(), + hashers: vec![StorageHasher::Blake2_128Concat], + value: meta_type::(), + }, + default: vec![0], + docs: vec![], + }, + StorageEntryMetadata { + name: "CounterForCountedNMap", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + StorageEntryMetadata { + name: "CountedNMap2", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + key: meta_type::<(u16, u32)>(), + hashers: vec![ + StorageHasher::Twox64Concat, + StorageHasher::Blake2_128Concat, + ], + value: meta_type::(), + }, + default: vec![0], + docs: vec![], + }, + StorageEntryMetadata { + name: "CounterForCountedNMap2", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, + StorageEntryMetadata { + name: "CountedNMap3", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + key: meta_type::<(u8, u16)>(), + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat, + ], + value: meta_type::(), + }, + default: vec![1, 1], + docs: vec![], + }, + StorageEntryMetadata { + name: "CounterForCountedNMap3", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, #[cfg(feature = "frame-feature-testing")] StorageEntryMetadata { name: "ConditionalValue", @@ -1536,6 +1620,27 @@ fn metadata() { default: vec![0], docs: vec![], }, + StorageEntryMetadata { + name: "ConditionalCountedNMap", + modifier: StorageEntryModifier::Optional, + ty: StorageEntryType::Map { + key: meta_type::<(u8, u16)>(), + hashers: vec![ + StorageHasher::Blake2_128Concat, + StorageHasher::Twox64Concat, + ], + value: meta_type::(), + }, + default: vec![0], + docs: vec![], + }, + StorageEntryMetadata { + name: "CounterForConditionalCountedNMap", + modifier: StorageEntryModifier::Default, + ty: StorageEntryType::Plain(meta_type::()), + default: vec![0, 0, 0, 0], + docs: vec![], + }, StorageEntryMetadata { name: "RenamedCountedMap", modifier: StorageEntryModifier::Optional, @@ -1902,6 +2007,48 @@ fn test_storage_info() { max_values: None, max_size: Some(16 + 1 + 8 + 2 + 16), }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CountedNMap".to_vec(), + prefix: prefix(b"Example", b"CountedNMap").to_vec(), + max_values: None, + max_size: Some(16 + 1 + 4), + }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CounterForCountedNMap".to_vec(), + prefix: prefix(b"Example", b"CounterForCountedNMap").to_vec(), + max_values: Some(1), + max_size: Some(4), + }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CountedNMap2".to_vec(), + prefix: prefix(b"Example", b"CountedNMap2").to_vec(), + max_values: Some(11), + max_size: Some(8 + 2 + 16 + 4 + 8), + }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CounterForCountedNMap2".to_vec(), + prefix: prefix(b"Example", b"CounterForCountedNMap2").to_vec(), + max_values: Some(1), + max_size: Some(4), + }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CountedNMap3".to_vec(), + prefix: prefix(b"Example", b"CountedNMap3").to_vec(), + max_values: None, + max_size: Some(16 + 1 + 8 + 2 + 16), + }, + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CounterForCountedNMap3".to_vec(), + prefix: prefix(b"Example", b"CounterForCountedNMap3").to_vec(), + max_values: Some(1), + max_size: Some(4), + }, #[cfg(feature = "frame-feature-testing")] { StorageInfo { @@ -1942,6 +2089,26 @@ fn test_storage_info() { max_size: Some(16 + 1 + 8 + 2 + 4), } }, + #[cfg(feature = "frame-feature-testing")] + { + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"ConditionalCountedNMap".to_vec(), + prefix: prefix(b"Example", b"ConditionalCountedNMap").to_vec(), + max_values: None, + max_size: Some(16 + 1 + 8 + 2 + 4), + } + }, + #[cfg(feature = "frame-feature-testing")] + { + StorageInfo { + pallet_name: b"Example".to_vec(), + storage_name: b"CounterForConditionalCountedNMap".to_vec(), + prefix: prefix(b"Example", b"CounterForConditionalCountedNMap").to_vec(), + max_values: Some(1), + max_size: Some(4), + } + }, StorageInfo { pallet_name: b"Example".to_vec(), storage_name: b"RenamedCountedMap".to_vec(), From fe9d7332e2703daab3a3c5373fe48fa7da20e04b Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jul 2023 13:14:14 +0300 Subject: [PATCH 45/50] fix --- frame/support/test/tests/pallet.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index b6bc5c764d164..d5ebd9e30c623 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1526,7 +1526,7 @@ fn metadata() { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: maybe_docs(vec!["Counter for the related counted storage map"]), }, StorageEntryMetadata { name: "CountedNMap2", @@ -1547,7 +1547,7 @@ fn metadata() { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: maybe_docs(vec!["Counter for the related counted storage map"]), }, StorageEntryMetadata { name: "CountedNMap3", @@ -1568,7 +1568,7 @@ fn metadata() { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: maybe_docs(vec!["Counter for the related counted storage map"]), }, #[cfg(feature = "frame-feature-testing")] StorageEntryMetadata { @@ -1639,7 +1639,7 @@ fn metadata() { modifier: StorageEntryModifier::Default, ty: StorageEntryType::Plain(meta_type::()), default: vec![0, 0, 0, 0], - docs: vec![], + docs: maybe_docs(vec!["Counter for the related counted storage map"]), }, StorageEntryMetadata { name: "RenamedCountedMap", From 19a70a6f81ef652b03e935fb62ec5b817129a5f9 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jul 2023 19:43:41 +0300 Subject: [PATCH 46/50] fix --- frame/support/test/tests/pallet.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index d5ebd9e30c623..b30f7513726cb 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1620,6 +1620,7 @@ fn metadata() { default: vec![0], docs: vec![], }, + #[cfg(feature = "frame-feature-testing")] StorageEntryMetadata { name: "ConditionalCountedNMap", modifier: StorageEntryModifier::Optional, @@ -1634,6 +1635,7 @@ fn metadata() { default: vec![0], docs: vec![], }, + #[cfg(feature = "frame-feature-testing")] StorageEntryMetadata { name: "CounterForConditionalCountedNMap", modifier: StorageEntryModifier::Default, From 7739ac209164bc651d150c289d53b11bb3f3f967 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sun, 9 Jul 2023 20:44:14 +0300 Subject: [PATCH 47/50] fix --- .../test/tests/pallet_ui/storage_not_storage_type.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/test/tests/pallet_ui/storage_not_storage_type.stderr b/frame/support/test/tests/pallet_ui/storage_not_storage_type.stderr index 223e9cfa3e9f8..3358f00151d50 100644 --- a/frame/support/test/tests/pallet_ui/storage_not_storage_type.stderr +++ b/frame/support/test/tests/pallet_ui/storage_not_storage_type.stderr @@ -1,4 +1,4 @@ -error: Invalid pallet::storage, expected ident: `StorageValue` or `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` in order to expand metadata, found `u8`. +error: Invalid pallet::storage, expected ident: `StorageValue` or `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` or `CountedStorageNMap` in order to expand metadata, found `u8`. --> $DIR/storage_not_storage_type.rs:19:16 | 19 | type Foo = u8; From 48faea8f5fabdda00f05a3f45ac9a119dc988a47 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Sat, 15 Jul 2023 16:23:48 +0300 Subject: [PATCH 48/50] update tests --- frame/support/test/tests/pallet.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index b30f7513726cb..4cd401e50e5d9 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1154,6 +1154,7 @@ fn storage_expand() { k.extend(2u32.using_encoded(blake2_128_concat)); assert_eq!(unhashed::get::(&k), Some(3u64)); assert_eq!(&k[..32], &>::final_prefix()); + assert_eq!(pallet::Pallet::::nmap2((1, 2)), Some(3u64)); pallet::NMap3::::insert((&1, &2), &3); let mut k = [twox_128(b"Example"), twox_128(b"NMap3")].concat(); @@ -1161,6 +1162,7 @@ fn storage_expand() { k.extend(2u16.using_encoded(twox_64_concat)); assert_eq!(unhashed::get::(&k), Some(3u128)); assert_eq!(&k[..32], &>::final_prefix()); + assert_eq!(pallet::Pallet::::nmap3((1, 2)), Ok(3u128)); assert_eq!( pallet::NMap3::::get((2, 3)), Err(pallet::Error::::NonExistentStorageValue), @@ -1171,6 +1173,12 @@ fn storage_expand() { k.extend(1u8.using_encoded(blake2_128_concat)); assert_eq!(unhashed::get::(&k), Some(3u32)); assert_eq!(pallet::CountedNMap::::count(), 1); + assert_eq!( + unhashed::get::( + &[twox_128(b"Example"), twox_128(b"CounterForCountedNMap")].concat() + ), + Some(1u32) + ); pallet::CountedNMap2::::insert((&1, &2), &3); let mut k = [twox_128(b"Example"), twox_128(b"CountedNMap2")].concat(); @@ -1178,6 +1186,13 @@ fn storage_expand() { k.extend(2u32.using_encoded(blake2_128_concat)); assert_eq!(unhashed::get::(&k), Some(3u64)); assert_eq!(pallet::CountedNMap2::::count(), 1); + assert_eq!( + unhashed::get::( + &[twox_128(b"Example"), twox_128(b"CounterForCountedNMap2")].concat() + ), + Some(1u32) + ); + assert_eq!(pallet::Pallet::::counted_nmap2((1, 2)), Some(3u64)); pallet::CountedNMap3::::insert((&1, &2), &3); let mut k = [twox_128(b"Example"), twox_128(b"CountedNMap3")].concat(); @@ -1185,10 +1200,17 @@ fn storage_expand() { k.extend(2u16.using_encoded(twox_64_concat)); assert_eq!(pallet::CountedNMap3::::count(), 1); assert_eq!(unhashed::get::(&k), Some(3u128)); + assert_eq!(pallet::Pallet::::counted_nmap3((1, 2)), Ok(3u128)); assert_eq!( pallet::CountedNMap3::::get((2, 3)), Err(pallet::Error::::NonExistentStorageValue), ); + assert_eq!( + unhashed::get::( + &[twox_128(b"Example"), twox_128(b"CounterForCountedNMap3")].concat() + ), + Some(1u32) + ); #[cfg(feature = "frame-feature-testing")] { From 3ef9de93a326aa3625839a1d183a27ede0f26967 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 1 Aug 2023 13:58:09 +0300 Subject: [PATCH 49/50] fix fmt --- .../procedural/src/pallet/expand/storage.rs | 24 ++--- .../procedural/src/pallet/parse/storage.rs | 91 ++++++++----------- frame/support/src/lib.rs | 2 +- .../support/src/storage/types/counted_nmap.rs | 6 +- frame/support/test/tests/pallet.rs | 12 +-- 5 files changed, 62 insertions(+), 73 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/storage.rs b/frame/support/procedural/src/pallet/expand/storage.rs index fcf94b9efa44f..0be62d08d8cdc 100644 --- a/frame/support/procedural/src/pallet/expand/storage.rs +++ b/frame/support/procedural/src/pallet/expand/storage.rs @@ -60,7 +60,7 @@ fn check_prefix_duplicates( if let Some(other_dup_err) = used_prefixes.insert(prefix.clone(), dup_err.clone()) { let mut err = dup_err; err.combine(other_dup_err); - return Err(err); + return Err(err) } if let Metadata::CountedMap { .. } = storage_def.metadata { @@ -77,7 +77,7 @@ fn check_prefix_duplicates( if let Some(other_dup_err) = used_prefixes.insert(counter_prefix, counter_dup_err.clone()) { let mut err = counter_dup_err; err.combine(other_dup_err); - return Err(err); + return Err(err) } } @@ -150,7 +150,7 @@ pub fn process_generics(def: &mut Def) -> syn::Result syn::Result syn::Result syn::Result syn::Result= args.args.len() - && matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _))) + if on_empty_idx >= args.args.len() && + matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _))) { let value_ty = match args.args[value_idx].clone() { syn::GenericArgument::Type(ty) => ty, @@ -400,7 +400,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { .filter_map(|storage_def| check_prefix_duplicates(storage_def, &mut prefix_set).err()); if let Some(mut final_error) = errors.next() { errors.for_each(|error| final_error.combine(error)); - return final_error.into_compile_error(); + return final_error.into_compile_error() } let frame_support = &def.frame_support; @@ -608,7 +608,7 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { <#keygen as #frame_support::storage::types::KeyGenerator>::KArg > + #frame_support::storage::types::TupleToEncodedIter, - { + { // NOTE: we can't use any trait here because CountedStorageNMap // doesn't implement any. <#full_ident>::get(key) diff --git a/frame/support/procedural/src/pallet/parse/storage.rs b/frame/support/procedural/src/pallet/parse/storage.rs index c98134881041d..3a0ec4747153a 100644 --- a/frame/support/procedural/src/pallet/parse/storage.rs +++ b/frame/support/procedural/src/pallet/parse/storage.rs @@ -49,10 +49,10 @@ pub enum PalletStorageAttr { impl PalletStorageAttr { fn attr_span(&self) -> proc_macro2::Span { match self { - Self::Getter(_, span) - | Self::StorageName(_, span) - | Self::Unbounded(span) - | Self::WhitelistStorage(span) => *span, + Self::Getter(_, span) | + Self::StorageName(_, span) | + Self::Unbounded(span) | + Self::WhitelistStorage(span) => *span, } } } @@ -115,17 +115,15 @@ impl PalletStorageAttrInfo { for attr in attrs { match attr { PalletStorageAttr::Getter(ident, ..) if getter.is_none() => getter = Some(ident), - PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => { - rename_as = Some(name) - }, + PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => + rename_as = Some(name), PalletStorageAttr::Unbounded(..) if !unbounded => unbounded = true, PalletStorageAttr::WhitelistStorage(..) if !whitelisted => whitelisted = true, - attr => { + attr => return Err(syn::Error::new( attr.attr_span(), "Invalid attribute: Duplicate attribute", - )) - }, + )), } } @@ -250,12 +248,10 @@ impl StorageGenerics { Self::Map { value, key, .. } => Metadata::Map { value, key }, Self::CountedMap { value, key, .. } => Metadata::CountedMap { value, key }, Self::Value { value, .. } => Metadata::Value { value }, - Self::NMap { keygen, value, .. } => { - Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value } - }, - Self::CountedNMap { keygen, value, .. } => { - Metadata::CountedNMap { keys: collect_keys(&keygen)?, keygen, value } - }, + Self::NMap { keygen, value, .. } => + Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value }, + Self::CountedNMap { keygen, value, .. } => + Metadata::CountedNMap { keys: collect_keys(&keygen)?, keygen, value }, }; Ok(res) @@ -264,12 +260,12 @@ impl StorageGenerics { /// Return the query kind from the defined generics fn query_kind(&self) -> Option { match &self { - Self::DoubleMap { query_kind, .. } - | Self::Map { query_kind, .. } - | Self::CountedMap { query_kind, .. } - | Self::Value { query_kind, .. } - | Self::NMap { query_kind, .. } - | Self::CountedNMap { query_kind, .. } => query_kind.clone(), + Self::DoubleMap { query_kind, .. } | + Self::Map { query_kind, .. } | + Self::CountedMap { query_kind, .. } | + Self::Value { query_kind, .. } | + Self::NMap { query_kind, .. } | + Self::CountedNMap { query_kind, .. } => query_kind.clone(), } } } @@ -311,8 +307,8 @@ fn check_generics( }; for (gen_name, gen_binding) in map { - if !mandatory_generics.contains(&gen_name.as_str()) - && !optional_generics.contains(&gen_name.as_str()) + if !mandatory_generics.contains(&gen_name.as_str()) && + !optional_generics.contains(&gen_name.as_str()) { let msg = format!( "Invalid pallet::storage, Unexpected generic `{}` for `{}`. {}", @@ -358,7 +354,7 @@ fn process_named_generics( let msg = "Invalid pallet::storage, Duplicated named generic"; let mut err = syn::Error::new(arg.ident.span(), msg); err.combine(syn::Error::new(other.ident.span(), msg)); - return Err(err); + return Err(err) } parsed.insert(arg.ident.to_string(), arg.clone()); } @@ -583,9 +579,8 @@ fn process_unnamed_generics( }; let res = match storage { - StorageKind::Value => { - (None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false) - }, + StorageKind::Value => + (None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false), StorageKind::Map => ( None, Metadata::Map { key: retrieve_arg(2)?, value: retrieve_arg(3)? }, @@ -652,7 +647,7 @@ fn process_generics( in order to expand metadata, found `{}`.", found, ); - return Err(syn::Error::new(segment.ident.span(), msg)); + return Err(syn::Error::new(segment.ident.span(), msg)) }, }; @@ -663,7 +658,7 @@ fn process_generics( _ => { let msg = "Invalid pallet::storage, invalid number of generic generic arguments, \ expect more that 0 generic arguments."; - return Err(syn::Error::new(segment.span(), msg)); + return Err(syn::Error::new(segment.span(), msg)) }, }; @@ -710,7 +705,7 @@ fn extract_key(ty: &syn::Type) -> syn::Result { typ } else { let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(ty.span(), msg)); + return Err(syn::Error::new(ty.span(), msg)) }; let key_struct = typ.path.segments.last().ok_or_else(|| { @@ -719,14 +714,14 @@ fn extract_key(ty: &syn::Type) -> syn::Result { })?; if key_struct.ident != "Key" && key_struct.ident != "NMapKey" { let msg = "Invalid pallet::storage, expected Key or NMapKey struct"; - return Err(syn::Error::new(key_struct.ident.span(), msg)); + return Err(syn::Error::new(key_struct.ident.span(), msg)) } let ty_params = if let syn::PathArguments::AngleBracketed(args) = &key_struct.arguments { args } else { let msg = "Invalid pallet::storage, expected angle bracketed arguments"; - return Err(syn::Error::new(key_struct.arguments.span(), msg)); + return Err(syn::Error::new(key_struct.arguments.span(), msg)) }; if ty_params.args.len() != 2 { @@ -735,14 +730,14 @@ fn extract_key(ty: &syn::Type) -> syn::Result { for Key struct, expected 2 args, found {}", ty_params.args.len() ); - return Err(syn::Error::new(ty_params.span(), msg)); + return Err(syn::Error::new(ty_params.span(), msg)) } let key = match &ty_params.args[1] { syn::GenericArgument::Type(key_ty) => key_ty.clone(), _ => { let msg = "Invalid pallet::storage, expected type"; - return Err(syn::Error::new(ty_params.args[1].span(), msg)); + return Err(syn::Error::new(ty_params.args[1].span(), msg)) }, }; @@ -776,7 +771,7 @@ impl StorageDef { let item = if let syn::Item::Type(item) = item { item } else { - return Err(syn::Error::new(item.span(), "Invalid pallet::storage, expect item type.")); + return Err(syn::Error::new(item.span(), "Invalid pallet::storage, expect item type.")) }; let attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; @@ -796,12 +791,12 @@ impl StorageDef { typ } else { let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(item.ty.span(), msg)); + return Err(syn::Error::new(item.ty.span(), msg)) }; if typ.path.segments.len() != 1 { let msg = "Invalid pallet::storage, expected type path with one segment"; - return Err(syn::Error::new(item.ty.span(), msg)); + return Err(syn::Error::new(item.ty.span(), msg)) } let (named_generics, metadata, query_kind, use_default_hasher) = @@ -821,22 +816,16 @@ impl StorageDef { .segments .last() .map_or(false, |s| s.ident == "OptionQuery") => - { - return Ok(Some(QueryKind::OptionQuery)) - }, + return Ok(Some(QueryKind::OptionQuery)), Type::Path(TypePath { path: Path { segments, .. }, .. }) if segments.last().map_or(false, |s| s.ident == "ResultQuery") => - { segments .last() .expect("segments is checked to have the last value; qed") - .clone() - }, + .clone(), Type::Path(path) if path.path.segments.last().map_or(false, |s| s.ident == "ValueQuery") => - { - return Ok(Some(QueryKind::ValueQuery)) - }, + return Ok(Some(QueryKind::ValueQuery)), _ => return Ok(None), }; @@ -850,7 +839,7 @@ impl StorageDef { for ResultQuery, expected 1 type argument, found {}", args.len(), ); - return Err(syn::Error::new(args.span(), msg)); + return Err(syn::Error::new(args.span(), msg)) } args[0].clone() @@ -861,7 +850,7 @@ impl StorageDef { expected angle-bracketed arguments, found `{}`", args.to_token_stream().to_string() ); - return Err(syn::Error::new(args.span(), msg)); + return Err(syn::Error::new(args.span(), msg)) }, }; @@ -877,7 +866,7 @@ impl StorageDef { segments, found {}", err_variant.len(), ); - return Err(syn::Error::new(err_variant.span(), msg)); + return Err(syn::Error::new(err_variant.span(), msg)) } let mut error = err_variant.clone(); let err_variant = error @@ -913,7 +902,7 @@ impl StorageDef { let msg = "Invalid pallet::storage, cannot generate getter because QueryKind is not \ identifiable. QueryKind must be `OptionQuery`, `ResultQuery`, `ValueQuery`, or default \ one to be identifiable."; - return Err(syn::Error::new(getter.span(), msg)); + return Err(syn::Error::new(getter.span(), msg)) } Ok(StorageDef { diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 19e277052ff47..cefe550bb7ce8 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -686,7 +686,7 @@ pub use frame_support_procedural::crate_to_crate_version; #[macro_export] macro_rules! fail { ( $y:expr ) => {{ - return Err($y.into()); + return Err($y.into()) }}; } diff --git a/frame/support/src/storage/types/counted_nmap.rs b/frame/support/src/storage/types/counted_nmap.rs index 5f15437873a56..43a243cc5d681 100644 --- a/frame/support/src/storage/types/counted_nmap.rs +++ b/frame/support/src/storage/types/counted_nmap.rs @@ -1312,9 +1312,9 @@ mod test { let _ = A::clear(u32::max_value(), None); // one of the item has been removed assert!( - !A::contains_key((2, 20, 200)) - && !A::contains_key((3, 30, 300)) - && !A::contains_key((4, 40, 400)) + !A::contains_key((2, 20, 200)) && + !A::contains_key((3, 30, 300)) && + !A::contains_key((4, 40, 400)) ); assert_eq!(A::count(), 0); diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index b6570ee1ede2f..cb78bded1a358 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -476,7 +476,7 @@ pub mod pallet { let _ = T::AccountId::from(SomeType1); // Test for where clause let _ = T::AccountId::from(SomeType5); // Test for where clause if matches!(call, Call::foo_storage_layer { .. }) { - return Ok(ValidTransaction::default()); + return Ok(ValidTransaction::default()) } Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) } @@ -1799,9 +1799,9 @@ fn metadata() { }, ]; - let empty_doc = pallets[0].event.as_ref().unwrap().ty.type_info().docs.is_empty() - && pallets[0].error.as_ref().unwrap().ty.type_info().docs.is_empty() - && pallets[0].calls.as_ref().unwrap().ty.type_info().docs.is_empty(); + let empty_doc = pallets[0].event.as_ref().unwrap().ty.type_info().docs.is_empty() && + pallets[0].error.as_ref().unwrap().ty.type_info().docs.is_empty() && + pallets[0].calls.as_ref().unwrap().ty.type_info().docs.is_empty(); if cfg!(feature = "no-metadata-docs") { assert!(empty_doc) @@ -2387,8 +2387,8 @@ fn post_runtime_upgrade_detects_storage_version_issues() { Example::on_genesis(); // The version isn't changed, we should detect it. assert!( - Executive::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost).unwrap_err() - == "On chain and current storage version do not match. Missing runtime upgrade?" + Executive::try_runtime_upgrade(UpgradeCheckSelect::PreAndPost).unwrap_err() == + "On chain and current storage version do not match. Missing runtime upgrade?" .into() ); }); From 4c29a0e6ef809e3ea5c2373ead87839f80b1e0cc Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 1 Aug 2023 17:07:38 +0300 Subject: [PATCH 50/50] fix fmt --- frame/support/procedural/src/pallet/expand/storage.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/storage.rs b/frame/support/procedural/src/pallet/expand/storage.rs index 0be62d08d8cdc..f3c394d731f5c 100644 --- a/frame/support/procedural/src/pallet/expand/storage.rs +++ b/frame/support/procedural/src/pallet/expand/storage.rs @@ -636,7 +636,6 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { Metadata::CountedMap { .. } => { let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); - quote::quote_spanned!(storage_def.attr_span => #(#cfg_attrs)* #[doc(hidden)] @@ -669,7 +668,6 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { Metadata::CountedNMap { .. } => { let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); - quote::quote_spanned!(storage_def.attr_span => #(#cfg_attrs)* #[doc(hidden)]