diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 0bec78fe1f..962f3c9c73 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -84,7 +84,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 162, + spec_version: 163, impl_version: 163, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/srml/support/procedural/src/storage/impls.rs b/substrate/srml/support/procedural/src/storage/impls.rs index a5b91eda78..ee6fa9a164 100644 --- a/substrate/srml/support/procedural/src/storage/impls.rs +++ b/substrate/srml/support/procedural/src/storage/impls.rs @@ -257,14 +257,14 @@ impl<'a, I: Iterator> Impls<'a, I> { }; // make sure to use different prefix for head and elements. - let final_head_key = if let Some(instance) = instance { + let head_key = if let Some(instance) = instance { let const_name = Ident::new( &format!("{}{}", HEAD_KEY_FOR, name.to_string()), proc_macro2::Span::call_site() ); quote!{ #instance::#const_name.as_bytes() } } else { - let final_head_key = format!("head of {}", prefix); - quote!{ #final_head_key.as_bytes() } + let head_key = format!("head of {}", prefix); + quote!{ #head_key.as_bytes() } }; let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos; @@ -308,8 +308,8 @@ impl<'a, I: Iterator> Impls<'a, I> { #final_prefix } - fn final_head_key() -> &'static [u8] { - #final_head_key + fn head_key() -> &'static [u8] { + #head_key } fn from_optional_value_to_query(v: Option<#typ>) -> Self::Query { diff --git a/substrate/srml/support/src/storage/generator/linked_map.rs b/substrate/srml/support/src/storage/generator/linked_map.rs index e1786d2120..2c69df4364 100644 --- a/substrate/srml/support/src/storage/generator/linked_map.rs +++ b/substrate/srml/support/src/storage/generator/linked_map.rs @@ -36,7 +36,7 @@ pub trait StorageLinkedMap { fn prefix() -> &'static [u8]; /// Key used to store linked map head. - fn final_head_key() -> &'static [u8]; + fn head_key() -> &'static [u8]; /// Convert an optionnal value retrieved from storage to the type queried. fn from_optional_value_to_query(v: Option) -> Self::Query; @@ -53,6 +53,11 @@ pub trait StorageLinkedMap { key.borrow().encode_to(&mut final_key); Self::Hasher::hash(&final_key) } + + /// Generate the hashed key for head + fn storage_linked_map_final_head_key() -> ::Output { + Self::Hasher::hash(Self::head_key()) + } } /// Linkage data of an element (it's successor and predecessor) @@ -181,7 +186,7 @@ where V: Codec, G: StorageLinkedMap { - unhashed::get(G::final_head_key()) + unhashed::get(G::storage_linked_map_final_head_key().as_ref()) } /// Overwrite current head pointer. @@ -194,8 +199,8 @@ where G: StorageLinkedMap { match head { - Some(head) => unhashed::put(G::final_head_key(), head), - None => unhashed::kill(G::final_head_key()), + Some(head) => unhashed::put(G::storage_linked_map_final_head_key().as_ref(), head), + None => unhashed::kill(G::storage_linked_map_final_head_key().as_ref()), } } diff --git a/substrate/srml/support/src/storage/storage_items.rs b/substrate/srml/support/src/storage/storage_items.rs index ac120c31e7..3abb390ab5 100644 --- a/substrate/srml/support/src/storage/storage_items.rs +++ b/substrate/srml/support/src/storage/storage_items.rs @@ -758,7 +758,7 @@ mod test3 { #[cfg(test)] #[allow(dead_code)] mod test_append_and_len { - use crate::storage::{StorageMap, StorageValue, StorageLinkedMap}; + use crate::storage::{StorageMap, StorageValue}; use runtime_io::{with_externalities, TestExternalities}; use codec::{Encode, Decode}; diff --git a/substrate/srml/support/test/tests/final_keys.rs b/substrate/srml/support/test/tests/final_keys.rs index 8c26ad1843..d53e0aa139 100644 --- a/substrate/srml/support/test/tests/final_keys.rs +++ b/substrate/srml/support/test/tests/final_keys.rs @@ -72,10 +72,14 @@ fn final_keys() { k.extend(1u32.encode()); assert_eq!(unhashed::get::(&runtime_io::twox_128(&k)), Some(2u32)); + let head = b"head of FinalKeys LinkedMap".to_vec(); + assert_eq!(unhashed::get::(&runtime_io::blake2_256(&head)), None); + LinkedMap::insert(1, 2); let mut k = b"FinalKeys LinkedMap".to_vec(); k.extend(1u32.encode()); assert_eq!(unhashed::get::(&runtime_io::blake2_256(&k)), Some(2u32)); + assert_eq!(unhashed::get::(&runtime_io::blake2_256(&head)), Some(1u32)); LinkedMap2::insert(1, 2); let mut k = b"FinalKeys LinkedMap2".to_vec();