diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 6c1f52a642c03..48b54a8c8677e 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -165,7 +165,7 @@ decl_storage! { trait Store for Module as Example { Accounts get(fn accounts) config(): map H160 => Account; AccountCodes: map H160 => Vec; - AccountStorages: double_map H160, blake2_256(H256) => H256; + AccountStorages: double_map H160, H256 => H256; } } diff --git a/frame/generic-asset/src/lib.rs b/frame/generic-asset/src/lib.rs index ceadd937fc052..0a0209b20f175 100644 --- a/frame/generic-asset/src/lib.rs +++ b/frame/generic-asset/src/lib.rs @@ -492,10 +492,10 @@ decl_storage! { }): map T::AssetId => T::Balance; /// The free balance of a given asset under an account. - pub FreeBalance: double_map T::AssetId, twox_128(T::AccountId) => T::Balance; + pub FreeBalance: double_map T::AssetId, hasher(twox_128) T::AccountId => T::Balance; /// The reserved balance of a given asset under an account. - pub ReservedBalance: double_map T::AssetId, twox_128(T::AccountId) => T::Balance; + pub ReservedBalance: double_map T::AssetId, hasher(twox_128) T::AccountId => T::Balance; /// Next available ID for user-created asset. pub NextAssetId get(fn next_asset_id) config(): T::AssetId; diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 64cd9fae6f420..71406f9b375e2 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -229,13 +229,12 @@ decl_storage! { /// For each session index, we keep a mapping of `AuthIndex` /// to `offchain::OpaqueNetworkState`. - ReceivedHeartbeats get(fn received_heartbeats): double_map SessionIndex, - blake2_256(AuthIndex) => Option>; + ReceivedHeartbeats get(fn received_heartbeats): double_map SessionIndex, AuthIndex + => Option>; /// For each session index, we keep a mapping of `T::ValidatorId` to the /// number of blocks authored by the given authority. - AuthoredBlocks get(fn authored_blocks): double_map SessionIndex, - blake2_256(T::ValidatorId) => u32; + AuthoredBlocks get(fn authored_blocks): double_map SessionIndex, T::ValidatorId => u32; } add_extra_genesis { config(keys): Vec; diff --git a/frame/offences/src/lib.rs b/frame/offences/src/lib.rs index f0a2cb04ee51e..310c018d76134 100644 --- a/frame/offences/src/lib.rs +++ b/frame/offences/src/lib.rs @@ -57,7 +57,7 @@ decl_storage! { Reports get(fn reports): map ReportIdOf => Option>; /// A vector of reports of the same kind that happened at the same time slot. - ConcurrentReportsIndex: double_map Kind, blake2_256(OpaqueTimeSlot) => Vec>; + ConcurrentReportsIndex: double_map Kind, OpaqueTimeSlot => Vec>; /// Enumerates all reports of a kind along with the time they happened. /// diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index 2c5668f6fa9f2..2200221af42fe 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -398,13 +398,15 @@ decl_storage! { /// /// The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of /// the trie. Having all data in the same branch should prevent slowing down other queries. - NextKeys: double_map hasher(twox_64_concat) Vec, blake2_256(T::ValidatorId) => Option; + NextKeys: double_map hasher(twox_64_concat) Vec, hasher(blake2_256) T::ValidatorId + => Option; /// The owner of a key. The second key is the `KeyTypeId` + the encoded key. /// /// The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of /// the trie. Having all data in the same branch should prevent slowing down other queries. - KeyOwner: double_map hasher(twox_64_concat) Vec, blake2_256((KeyTypeId, Vec)) => Option; + KeyOwner: double_map hasher(twox_64_concat) Vec, hasher(blake2_256) (KeyTypeId, Vec) + => Option; } add_extra_genesis { config(keys): Vec<(T::ValidatorId, T::Keys)>; diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index deb451f35c832..1331f869b705a 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -738,11 +738,11 @@ decl_storage! { /// All slashing events on validators, mapped by era to the highest slash proportion /// and slash value of the era. ValidatorSlashInEra: - double_map EraIndex, twox_128(T::AccountId) => Option<(Perbill, BalanceOf)>; + double_map EraIndex, hasher(twox_128) T::AccountId => Option<(Perbill, BalanceOf)>; /// All slashing events on nominators, mapped by era to the highest slash value of the era. NominatorSlashInEra: - double_map EraIndex, twox_128(T::AccountId) => Option>; + double_map EraIndex, hasher(twox_128) T::AccountId => Option>; /// Slashing spans for stash accounts. SlashingSpans: map T::AccountId => Option; diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index faac4baec39f8..7c27bc2a04dcb 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -117,7 +117,7 @@ use proc_macro::TokenStream; /// Twox128(module_prefix) ++ Twox128(head_prefix) /// ``` /// -/// * Double map: `Foo: double_map hasher($hash1) u32, $hash2(u32) => u32`: Implements the +/// * Double map: `Foo: double_map hasher($hash1) u32, hasher($hash2) u32 => u32`: Implements the /// [`StorageDoubleMap`](../frame_support/storage/trait.StorageDoubleMap.html) trait using the /// [`StorageDoubleMap generator`](../frame_support/storage/generator/trait.StorageDoubleMap.html). /// And [`StoragePrefixedMap`](../frame_support/storage/trait.StoragePrefixedMap.html). @@ -126,10 +126,8 @@ use proc_macro::TokenStream; /// [`Hashable`](../frame_support/trait.Hashable.html) trait. They must be choosen with care, see /// generator documentation. /// -/// `hasher($hash)` is optional and its default is `blake2_256`. -/// -/// `hasher($hash)` is optional and its default is `blake2_256`. One should use another hasher -/// with care, see generator documentation. +/// `hasher($hash1)` and `hasher($hash2) are optional and default to `blake2_256`. +/// One should use another hasher with care, see generator documentation. /// /// If the first key is untrusted, a cryptographic `hasher` such as `blake2_256` must be used. /// Otherwise, other values of all storage items can be compromised. diff --git a/frame/support/procedural/src/storage/parse.rs b/frame/support/procedural/src/storage/parse.rs index a2d3c67dd2f8e..5d91fbcc0e912 100644 --- a/frame/support/procedural/src/storage/parse.rs +++ b/frame/support/procedural/src/storage/parse.rs @@ -167,11 +167,11 @@ struct DeclStorageLinkedMap { #[derive(Parse, ToTokens, Debug)] struct DeclStorageDoubleMap { pub map_keyword: keyword::double_map, - pub hasher: ext::Opt, + pub hasher1: ext::Opt, pub key1: syn::Type, pub comma_keyword: Token![,], - pub key2_hasher: Hasher, - pub key2: ext::Parens, + pub hasher2: ext::Opt, + pub key2: syn::Type, pub ass_keyword: Token![=>], pub value: syn::Type, } @@ -380,11 +380,12 @@ fn parse_storage_line_defs( ), DeclStorageType::DoubleMap(map) => super::StorageLineTypeDef::DoubleMap( super::DoubleMapDef { - hasher1: map.hasher.inner.map(Into::into) + hasher1: map.hasher1.inner.map(Into::into) + .unwrap_or(super::HasherKind::Blake2_256), + hasher2: map.hasher2.inner.map(Into::into) .unwrap_or(super::HasherKind::Blake2_256), - hasher2: map.key2_hasher.into(), key1: map.key1, - key2: map.key2.content, + key2: map.key2, value: map.value, } ), diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index af6eea9c73fb3..bfee0a1ccb8b4 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -236,12 +236,12 @@ mod tests { pub GetterNoFnKeyword get(no_fn): Option; pub DataDM config(test_config) build(|_| vec![(15u32, 16u32, 42u64)]): - double_map hasher(twox_64_concat) u32, blake2_256(u32) => u64; + double_map hasher(twox_64_concat) u32, hasher(blake2_256) u32 => u64; pub GenericDataDM: - double_map T::BlockNumber, twox_128(T::BlockNumber) => T::BlockNumber; + double_map T::BlockNumber, hasher(twox_128) T::BlockNumber => T::BlockNumber; pub GenericData2DM: - double_map T::BlockNumber, twox_256(T::BlockNumber) => Option; - pub AppendableDM: double_map u32, blake2_256(T::BlockNumber) => Vec; + double_map T::BlockNumber, hasher(twox_256) T::BlockNumber => Option; + pub AppendableDM: double_map u32, T::BlockNumber => Vec; } } diff --git a/frame/support/test/tests/decl_storage.rs b/frame/support/test/tests/decl_storage.rs index b0974fcb8292a..15a0807fa5701 100644 --- a/frame/support/test/tests/decl_storage.rs +++ b/frame/support/test/tests/decl_storage.rs @@ -562,9 +562,9 @@ mod test_append_and_len { MapVecWithDefault: map u32 => Vec = vec![6, 9]; OptionMapVec: map u32 => Option>; - DoubleMapVec: double_map u32, blake2_256(u32) => Vec; - DoubleMapVecWithDefault: double_map u32, blake2_256(u32) => Vec = vec![6, 9]; - OptionDoubleMapVec: double_map u32, blake2_256(u32) => Option>; + DoubleMapVec: double_map u32, u32 => Vec; + DoubleMapVecWithDefault: double_map u32, u32 => Vec = vec![6, 9]; + OptionDoubleMapVec: double_map u32, u32 => Option>; LinkedMapVec: linked_map u32 => Vec; LinkedMapVecWithDefault: linked_map u32 => Vec = vec![6, 9]; diff --git a/frame/support/test/tests/final_keys.rs b/frame/support/test/tests/final_keys.rs index 71e13f7ced561..9f1b379e2544d 100644 --- a/frame/support/test/tests/final_keys.rs +++ b/frame/support/test/tests/final_keys.rs @@ -41,12 +41,12 @@ mod no_instance { pub LinkedMap: linked_map u32 => u32; pub LinkedMap2: linked_map hasher(twox_128) u32 => u32; - pub DoubleMap: double_map u32, blake2_256(u32) => u32; - pub DoubleMap2: double_map hasher(twox_128) u32, blake2_128(u32) => u32; + pub DoubleMap: double_map u32, u32 => u32; + pub DoubleMap2: double_map hasher(twox_128) u32, hasher(blake2_128) u32 => u32; pub TestGenericValue get(fn test_generic_value) config(): Option; pub TestGenericDoubleMap get(fn foo2) config(test_generic_double_map): - double_map u32, blake2_256(T::BlockNumber) => Option; + double_map u32, T::BlockNumber => Option; } } } @@ -71,12 +71,12 @@ mod instance { pub LinkedMap: linked_map u32 => u32; pub LinkedMap2: linked_map hasher(twox_128) u32 => u32; - pub DoubleMap: double_map u32, blake2_256(u32) => u32; - pub DoubleMap2: double_map hasher(twox_128) u32, blake2_128(u32) => u32; + pub DoubleMap: double_map u32, u32 => u32; + pub DoubleMap2: double_map hasher(twox_128) u32, hasher(blake2_128) u32 => u32; pub TestGenericValue get(fn test_generic_value) config(): Option; pub TestGenericDoubleMap get(fn foo2) config(test_generic_double_map): - double_map u32, blake2_256(T::BlockNumber) => Option; + double_map u32, T::BlockNumber => Option; } add_extra_genesis { // See `decl_storage` limitation. diff --git a/frame/support/test/tests/genesisconfig.rs b/frame/support/test/tests/genesisconfig.rs index 04525aa142d97..dee7aefe0aaa3 100644 --- a/frame/support/test/tests/genesisconfig.rs +++ b/frame/support/test/tests/genesisconfig.rs @@ -25,7 +25,7 @@ frame_support::decl_module! { frame_support::decl_storage! { trait Store for Module as Example { - pub AppendableDM config(t): double_map u32, blake2_256(T::BlockNumber) => Vec; + pub AppendableDM config(t): double_map u32, T::BlockNumber => Vec; } } diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index e4b707c1f170c..879ef4fa684d2 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -138,7 +138,7 @@ mod module2 { pub Value config(value): T::Amount; pub Map config(map): map u64 => u64; pub LinkedMap config(linked_map): linked_map u64 => Vec; - pub DoubleMap config(double_map): double_map u64, blake2_256(u64) => u64; + pub DoubleMap config(double_map): double_map u64, u64 => u64; } } diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 8103939a5c6a3..97c8f668a6e5c 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -127,7 +127,8 @@ pub struct Multisig { decl_storage! { trait Store for Module as Utility { /// The set of open multisig operations. - pub Multisigs: double_map hasher(twox_64_concat) T::AccountId, blake2_128_concat([u8; 32]) + pub Multisigs: double_map + hasher(twox_64_concat) T::AccountId, hasher(blake2_128_concat) [u8; 32] => Option, T::AccountId>>; } } diff --git a/utils/frame/rpc/support/src/lib.rs b/utils/frame/rpc/support/src/lib.rs index ba467abd924c8..1e29c4e91b495 100644 --- a/utils/frame/rpc/support/src/lib.rs +++ b/utils/frame/rpc/support/src/lib.rs @@ -67,7 +67,7 @@ use sc_rpc_api::state::StateClient; /// pub LastActionId: u64; /// pub Voxels: map Loc => Block; /// pub Actions: linked_map u64 => Loc; -/// pub Prefab: double_map u128, blake2_256((i8, i8, i8)) => Block; +/// pub Prefab: double_map u128, (i8, i8, i8) => Block; /// } /// } ///