Remove hashbrown from validator-sets pallet

This commit is contained in:
Luke Parker 2023-10-16 01:47:15 -04:00
parent 1f5b1bb514
commit e4d59eeeca
No known key found for this signature in database
3 changed files with 6 additions and 14 deletions

2
Cargo.lock generated
View file

@ -8559,7 +8559,6 @@ version = "0.1.0"
dependencies = [
"frame-support",
"frame-system",
"hashbrown 0.14.1",
"pallet-session",
"parity-scale-codec",
"scale-info",
@ -8568,7 +8567,6 @@ dependencies = [
"sp-application-crypto",
"sp-core",
"sp-io",
"sp-runtime",
"sp-std",
]

View file

@ -12,8 +12,6 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
hashbrown = { version = "0.14", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }

View file

@ -145,7 +145,8 @@ pub mod pallet {
fn recover_key_from_sorted_allocation_key(key: &[u8]) -> Public {
Public(key[(key.len() - 32) ..].try_into().unwrap())
}
fn set_allocation(network: NetworkId, key: Public, amount: Amount) {
// Returns if this validator already had an allocation set.
fn set_allocation(network: NetworkId, key: Public, amount: Amount) -> bool {
let prior = Allocations::<T>::take((network, key));
if let Some(amount) = prior {
SortedAllocations::<T>::remove(Self::sorted_allocation_key(network, key, amount));
@ -154,6 +155,7 @@ pub mod pallet {
Allocations::<T>::set((network, key), Some(amount));
SortedAllocations::<T>::set(Self::sorted_allocation_key(network, key, amount), Some(()));
}
prior.is_some()
}
}
@ -319,18 +321,12 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
{
let hash_set =
self.participants.iter().map(|key| key.0).collect::<hashbrown::HashSet<[u8; 32]>>();
if hash_set.len() != self.participants.len() {
panic!("participants contained duplicates");
}
}
for (id, stake) in self.networks.clone() {
AllocationPerKeyShare::<T>::set(id, Some(stake));
for participant in self.participants.clone() {
Pallet::<T>::set_allocation(id, participant, stake);
if Pallet::<T>::set_allocation(id, participant, stake) {
panic!("participants contained duplicates");
}
}
Pallet::<T>::new_set(id);
}