Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0b6f313
System.BlockHash
gavofyork Mar 11, 2020
051967a
Fix hash
gavofyork Mar 11, 2020
5fb1aeb
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 11, 2020
3921666
Introduce K/V iteration in all _concat maps
gavofyork Mar 11, 2020
a926a45
Build fixes
gavofyork Mar 11, 2020
e73f349
Ensure migration happens in correct order
gavofyork Mar 11, 2020
1e8230d
Staking.*
gavofyork Mar 12, 2020
855f20e
Vesting.* Offences.*
gavofyork Mar 12, 2020
d195330
Democracy.*
gavofyork Mar 12, 2020
cc6a4d0
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 12, 2020
c82856e
Babe.* Collective.*
gavofyork Mar 12, 2020
13ad20c
Grandpa.*
gavofyork Mar 12, 2020
bdde997
Assets.* Benchmark.* Contracts.* Elections.* Asset.* Nicks.*
gavofyork Mar 12, 2020
2cbc09e
ImOnline.*
gavofyork Mar 12, 2020
182ec5a
Treasury.*
gavofyork Mar 12, 2020
c573e56
Recovery.*
gavofyork Mar 12, 2020
cf69961
Final bits.
gavofyork Mar 12, 2020
c03a485
Docs
gavofyork Mar 12, 2020
0e3d187
Fix one test
gavofyork Mar 12, 2020
990e972
Fix test
gavofyork Mar 12, 2020
4e2acc9
All passing except the UI tests
gavofyork Mar 12, 2020
1c73a1f
Remove linked_map part 1
gavofyork Mar 12, 2020
5108dc9
Remove linked_map
gavofyork Mar 12, 2020
11a8b94
Some iterator utils for double maps.
gavofyork Mar 12, 2020
d14ba60
Remove old migrations
gavofyork Mar 12, 2020
becb495
Introduce tombstone for LinkedMap type
gavofyork Mar 13, 2020
fb97b30
Migration for genesis hash
gavofyork Mar 13, 2020
7ee5cee
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 15, 2020
0d95a1e
Fix build
gavofyork Mar 15, 2020
1e52937
Fix hash
gavofyork Mar 15, 2020
869b18f
Rename Map is_linked -> unused, keeping backwards compat (#5256)
jacogr Mar 16, 2020
9eb0ea3
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
f4e3c00
Update frame/balances/src/lib.rs
gavofyork Mar 16, 2020
43f3fb0
Update frame/elections/src/lib.rs
gavofyork Mar 16, 2020
3e50210
Remove old migration code.
gavofyork Mar 16, 2020
c90efd0
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
fbbcf01
Update frame/system/src/lib.rs
gavofyork Mar 16, 2020
84af903
Update bin/node/runtime/src/lib.rs
gavofyork Mar 16, 2020
9bcf544
Merge branch 'gav-refactor-hashing' of github.com:paritytech/substrat…
gavofyork Mar 16, 2020
12382d8
Fix hash
gavofyork Mar 16, 2020
07e3361
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
e971241
Merge remote-tracking branch 'origin/master' into gav-refactor-hashing
gavofyork Mar 16, 2020
a2ca4ea
fix session migration
rphmeier Mar 16, 2020
c34e064
Fix watning
gavofyork Mar 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove linked_map part 1
  • Loading branch information
gavofyork committed Mar 12, 2020
commit 1c73a1f1f09ebe22fb307d52a2063f82e224247c
2 changes: 1 addition & 1 deletion frame/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ decl_storage! {
Dummy get(fn dummy) config(): Option<T::Balance>;

// A map that has enumerable entries.
Bar get(fn bar) config(): linked_map hasher(blake2_128_concat) T::AccountId => T::Balance;
Bar get(fn bar) config(): map hasher(blake2_128_concat) T::AccountId => T::Balance;

// this one uses the default, we'll demonstrate the usage of 'mutate' API.
Foo get(fn foo) config(): T::Balance;
Expand Down
32 changes: 1 addition & 31 deletions frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use proc_macro::TokenStream;
/// trait Store for Module<T: Trait> as Example {
/// Foo get(fn foo) config(): u32=12;
/// Bar: map hasher(identity) u32 => u32;
/// pub Zed build(|config| vec![(0, 0)]): linked_map hasher(identity) u32 => u32;
/// pub Zed build(|config| vec![(0, 0)]): map hasher(identity) u32 => u32;
/// }
/// }
/// ```
Expand Down Expand Up @@ -105,36 +105,6 @@ use proc_macro::TokenStream;
/// twox128(module_prefix) ++ twox128(storage_prefix) ++ hasher(encode(key))
/// ```
///
/// * Linked map: `Foo: linked_map hasher($hash) type => type`: Implements the
/// [`StorageLinkedMap`](../frame_support/storage/trait.StorageLinkedMap.html) trait using the
/// [`StorageLinkedMap generator`](../frame_support/storage/generator/trait.StorageLinkedMap.html).
/// And [`StoragePrefixedMap`](../frame_support/storage/trait.StoragePrefixedMap.html).
///
/// `$hash` representing a choice of hashing algorithms available in the
/// [`Hashable`](../frame_support/trait.Hashable.html) trait.
///
/// `blake2_256` and `blake2_128_concat` are strong hasher. One should use another hasher
/// with care, see generator documentation.
///
/// All key formatting logic can be accessed in a type-agnostic format via the
/// `KeyFormat` trait, which
/// is implemented for the storage linked map type as well.
///
/// The generator key format is implemented with:
/// * `module_prefix`: $module_prefix
/// * `storage_prefix`: storage_name
/// * `head_prefix`: `"HeadOf" ++ storage_name`
/// * `Hasher`: $hash
///
/// Thus the keys are stored at:
/// ```nocompile
/// Twox128(module_prefix) ++ Twox128(storage_prefix) ++ Hasher(encode(key))
/// ```
/// and head is stored at:
/// ```nocompile
/// Twox128(module_prefix) ++ Twox128(head_prefix)
/// ```
///
/// * 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).
Expand Down
73 changes: 36 additions & 37 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ mod tests {
decl_storage! {
trait Store for Module<T: Trait> as Example {
pub Data get(fn data) build(|_| vec![(15u32, 42u64)]):
linked_map hasher(twox_64_concat) u32 => u64;
pub OptionLinkedMap: linked_map hasher(blake2_128_concat) u32 => Option<u32>;
map hasher(twox_64_concat) u32 => u64;
pub OptionLinkedMap: map hasher(blake2_128_concat) u32 => Option<u32>;
pub GenericData get(fn generic_data):
linked_map hasher(identity) T::BlockNumber => T::BlockNumber;
map hasher(identity) T::BlockNumber => T::BlockNumber;
pub GenericData2 get(fn generic_data2):
linked_map hasher(blake2_128_concat) T::BlockNumber => Option<T::BlockNumber>;
map hasher(blake2_128_concat) T::BlockNumber => Option<T::BlockNumber>;
pub GetterNoFnKeyword get(no_fn): Option<u32>;

pub DataDM config(test_config) build(|_| vec![(15u32, 16u32, 42u64)]):
Expand Down Expand Up @@ -287,8 +287,16 @@ mod tests {

type Map = Data;

trait Sorted { fn sorted(self) -> Self; }
impl<T: Ord> Sorted for Vec<T> {
fn sorted(mut self) -> Self {
self.sort();
self
}
}

#[test]
fn linked_map_issue_3318() {
fn map_issue_3318() {
new_test_ext().execute_with(|| {
OptionLinkedMap::insert(1, 1);
assert_eq!(OptionLinkedMap::get(1), Some(1));
Expand All @@ -298,31 +306,31 @@ mod tests {
}

#[test]
fn linked_map_swap_works() {
fn map_swap_works() {
new_test_ext().execute_with(|| {
OptionLinkedMap::insert(0, 0);
OptionLinkedMap::insert(1, 1);
OptionLinkedMap::insert(2, 2);
OptionLinkedMap::insert(3, 3);

let collect = || OptionLinkedMap::enumerate().collect::<Vec<_>>();
assert_eq!(collect(), vec![(3, 3), (2, 2), (1, 1), (0, 0)]);
let collect = || OptionLinkedMap::iter().collect::<Vec<_>>().sorted();
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);

// Two existing
OptionLinkedMap::swap(1, 2);
assert_eq!(collect(), vec![(3, 3), (2, 1), (1, 2), (0, 0)]);
assert_eq!(collect(), vec![(0, 0), (1, 2), (2, 1), (3, 3)]);

// Back to normal
OptionLinkedMap::swap(2, 1);
assert_eq!(collect(), vec![(3, 3), (2, 2), (1, 1), (0, 0)]);
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);

// Left existing
OptionLinkedMap::swap(2, 5);
assert_eq!(collect(), vec![(5, 2), (3, 3), (1, 1), (0, 0)]);
assert_eq!(collect(), vec![(0, 0), (1, 1), (3, 3), (5, 2)]);

// Right existing
OptionLinkedMap::swap(5, 2);
assert_eq!(collect(), vec![(2, 2), (3, 3), (1, 1), (0, 0)]);
assert_eq!(collect(), vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
});
}

Expand Down Expand Up @@ -357,7 +365,7 @@ mod tests {
}

#[test]
fn linked_map_basic_insert_remove_should_work() {
fn map_basic_insert_remove_should_work() {
new_test_ext().execute_with(|| {
// initialized during genesis
assert_eq!(Map::get(&15u32), 42u64);
Expand All @@ -383,54 +391,45 @@ mod tests {
}

#[test]
fn linked_map_enumeration_and_head_should_work() {
fn map_iteration_should_work() {
new_test_ext().execute_with(|| {
assert_eq!(Map::head(), Some(15));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(15, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42)]);
// insert / remove
let key = 17u32;
Map::insert(key, 4u64);
assert_eq!(Map::head(), Some(key));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key, 4), (15, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(15, 42), (key, 4)]);
assert_eq!(Map::take(&15), 42u64);
assert_eq!(Map::take(&key), 4u64);
assert_eq!(Map::head(), None);
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);

// Add couple of more elements
Map::insert(key, 42u64);
assert_eq!(Map::head(), Some(key));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42)]);
Map::insert(key + 1, 43u64);
assert_eq!(Map::head(), Some(key + 1));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key + 1, 43), (key, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key, 42), (key + 1, 43)]);

// mutate
let key = key + 2;
Map::mutate(&key, |val| {
*val = 15;
});
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key, 15), (key - 1, 43), (key - 2, 42)]);
assert_eq!(Map::head(), Some(key));
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43), (key, 15)]);
Map::mutate(&key, |val| {
*val = 17;
});
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key, 17), (key - 1, 43), (key - 2, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43), (key, 17)]);

// remove first
Map::remove(&key);
assert_eq!(Map::head(), Some(key - 1));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key - 1, 43), (key - 2, 42)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 2, 42), (key - 1, 43)]);

// remove last from the list
Map::remove(&(key - 2));
assert_eq!(Map::head(), Some(key - 1));
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![(key - 1, 43)]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![(key - 1, 43)]);

// remove the last element
Map::remove(&(key - 1));
assert_eq!(Map::head(), None);
assert_eq!(Map::enumerate().collect::<Vec<_>>(), vec![]);
assert_eq!(Map::iter().collect::<Vec<_>>().sorted(), vec![]);
});
}

Expand Down Expand Up @@ -499,7 +498,7 @@ mod tests {
hasher: StorageHasher::Twox64Concat,
key: DecodeDifferent::Encode("u32"),
value: DecodeDifferent::Encode("u64"),
is_linked: true,
is_linked: false,
},
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructData(PhantomData::<Test>))
Expand All @@ -513,7 +512,7 @@ mod tests {
hasher: StorageHasher::Blake2_128Concat,
key: DecodeDifferent::Encode("u32"),
value: DecodeDifferent::Encode("u32"),
is_linked: true,
is_linked: false,
},
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructOptionLinkedMap(PhantomData::<Test>))
Expand All @@ -527,7 +526,7 @@ mod tests {
hasher: StorageHasher::Identity,
key: DecodeDifferent::Encode("T::BlockNumber"),
value: DecodeDifferent::Encode("T::BlockNumber"),
is_linked: true
is_linked: false
},
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructGenericData(PhantomData::<Test>))
Expand All @@ -541,7 +540,7 @@ mod tests {
hasher: StorageHasher::Blake2_128Concat,
key: DecodeDifferent::Encode("T::BlockNumber"),
value: DecodeDifferent::Encode("T::BlockNumber"),
is_linked: true
is_linked: false
},
default: DecodeDifferent::Encode(
DefaultByteGetter(&__GetByteStructGenericData2(PhantomData::<Test>))
Expand Down