diff --git a/Cargo.lock b/Cargo.lock index b0805491..54d2b3b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/substrate/validator-sets/pallet/Cargo.toml b/substrate/validator-sets/pallet/Cargo.toml index e8f119b3..c5b69c5e 100644 --- a/substrate/validator-sets/pallet/Cargo.toml +++ b/substrate/validator-sets/pallet/Cargo.toml @@ -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"] } diff --git a/substrate/validator-sets/pallet/src/lib.rs b/substrate/validator-sets/pallet/src/lib.rs index 139850aa..9e69442f 100644 --- a/substrate/validator-sets/pallet/src/lib.rs +++ b/substrate/validator-sets/pallet/src/lib.rs @@ -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::::take((network, key)); if let Some(amount) = prior { SortedAllocations::::remove(Self::sorted_allocation_key(network, key, amount)); @@ -154,6 +155,7 @@ pub mod pallet { Allocations::::set((network, key), Some(amount)); SortedAllocations::::set(Self::sorted_allocation_key(network, key, amount), Some(())); } + prior.is_some() } } @@ -319,18 +321,12 @@ pub mod pallet { #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { - { - let hash_set = - self.participants.iter().map(|key| key.0).collect::>(); - if hash_set.len() != self.participants.len() { - panic!("participants contained duplicates"); - } - } - for (id, stake) in self.networks.clone() { AllocationPerKeyShare::::set(id, Some(stake)); for participant in self.participants.clone() { - Pallet::::set_allocation(id, participant, stake); + if Pallet::::set_allocation(id, participant, stake) { + panic!("participants contained duplicates"); + } } Pallet::::new_set(id); }