Society v2 (#11324)

* New Society

* More logic drafting

* More work

* Building

* Some tests

* Fixes

* Improvements to the voting process

* More tests

* Test number 20

* Tests

* 30 tests

* Another test]

* All tests enabled

* Minor stuff

* generate_storage_alias: Rewrite as proc macro attribute

This rewrites the `generate_storage_alias!` declarative macro as proc-macro attribute. While doing
this the name is changed to `storage_alias`. The prefix can now also be the name of a pallet. This
makes storage aliases work in migrations for all kind of chains and not just for the ones that use
predefined prefixes.

* Maintenance operations don't pay fee

* Fix compilation and FMT

* Moare fixes

* Migrations

* Fix tests and add migration testing

* Introduce lazy-cleanup and avoid unbounded prefix removal

* Fixes

* Fixes

* [WIP][Society] Adding benchmarking to the v2. (#11776)

* [Society] Adding benchmarking to the v2.

* [Society] Code review.

* [Society] Better code.

* Using clear() + clear_prefix() and adding more tests.

* Benchmarking again...

* Fix Cargo

* Fixes

* Fixes

* Spelling

* Fix benchmarks

* Another fix

* Remove println

---------

Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: Artur Gontijo <arturgontijo@users.noreply.github.com>
This commit is contained in:
Gavin Wood
2023-06-18 18:22:17 +02:00
committed by GitHub
parent 116b6e65dc
commit 33a6536299
25 changed files with 3416 additions and 1444 deletions
@@ -202,6 +202,18 @@ pub trait StorageMap<K: FullEncode, V: FullCodec> {
f: F,
) -> Result<R, E>;
/// Mutate the value under a key if the value already exists. Do nothing and return the default
/// value if not.
fn mutate_extant<KeyArg: EncodeLike<K>, R: Default, F: FnOnce(&mut V) -> R>(
key: KeyArg,
f: F,
) -> R {
Self::mutate_exists(key, |maybe_v| match maybe_v {
Some(ref mut value) => f(value),
None => R::default(),
})
}
/// Mutate the value under a key.
///
/// Deletes the item if mutated to a `None`.
@@ -186,6 +186,14 @@ where
<Self as crate::storage::StorageMap<Key, Value>>::try_mutate(key, f)
}
/// Mutate the value under a key iff it exists. Do nothing and return the default value if not.
pub fn mutate_extant<KeyArg: EncodeLike<Key>, R: Default, F: FnOnce(&mut Value) -> R>(
key: KeyArg,
f: F,
) -> R {
<Self as crate::storage::StorageMap<Key, Value>>::mutate_extant(key, f)
}
/// Mutate the value under a key. Deletes the item if mutated to a `None`.
pub fn mutate_exists<KeyArg: EncodeLike<Key>, R, F: FnOnce(&mut Option<Value>) -> R>(
key: KeyArg,
@@ -366,6 +374,16 @@ where
<Self as crate::storage::IterableStorageMap<Key, Value>>::iter_from(starting_raw_key)
}
/// Enumerate all elements in the map after a specified `starting_key` in no
/// particular order.
///
/// If you alter the map while doing this, you'll get undefined results.
pub fn iter_from_key(
starting_key: impl EncodeLike<Key>,
) -> crate::storage::PrefixIterator<(Key, Value)> {
Self::iter_from(Self::hashed_key_for(starting_key))
}
/// Enumerate all keys in the map in no particular order.
///
/// If you alter the map while doing this, you'll get undefined results.
@@ -381,6 +399,16 @@ where
<Self as crate::storage::IterableStorageMap<Key, Value>>::iter_keys_from(starting_raw_key)
}
/// Enumerate all keys in the map after a specified `starting_key` in no particular
/// order.
///
/// If you alter the map while doing this, you'll get undefined results.
pub fn iter_keys_from_key(
starting_key: impl EncodeLike<Key>,
) -> crate::storage::KeyPrefixIterator<Key> {
Self::iter_keys_from(Self::hashed_key_for(starting_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.