mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Remove hashbrown from validator-sets pallet
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -8559,7 +8559,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"frame-support",
|
"frame-support",
|
||||||
"frame-system",
|
"frame-system",
|
||||||
"hashbrown 0.14.1",
|
|
||||||
"pallet-session",
|
"pallet-session",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"scale-info",
|
"scale-info",
|
||||||
@@ -8568,7 +8567,6 @@ dependencies = [
|
|||||||
"sp-application-crypto",
|
"sp-application-crypto",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-io",
|
"sp-io",
|
||||||
"sp-runtime",
|
|
||||||
"sp-std",
|
"sp-std",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ all-features = true
|
|||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hashbrown = { version = "0.14", default-features = false }
|
|
||||||
|
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,8 @@ pub mod pallet {
|
|||||||
fn recover_key_from_sorted_allocation_key(key: &[u8]) -> Public {
|
fn recover_key_from_sorted_allocation_key(key: &[u8]) -> Public {
|
||||||
Public(key[(key.len() - 32) ..].try_into().unwrap())
|
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));
|
let prior = Allocations::<T>::take((network, key));
|
||||||
if let Some(amount) = prior {
|
if let Some(amount) = prior {
|
||||||
SortedAllocations::<T>::remove(Self::sorted_allocation_key(network, key, amount));
|
SortedAllocations::<T>::remove(Self::sorted_allocation_key(network, key, amount));
|
||||||
@@ -154,6 +155,7 @@ pub mod pallet {
|
|||||||
Allocations::<T>::set((network, key), Some(amount));
|
Allocations::<T>::set((network, key), Some(amount));
|
||||||
SortedAllocations::<T>::set(Self::sorted_allocation_key(network, key, amount), Some(()));
|
SortedAllocations::<T>::set(Self::sorted_allocation_key(network, key, amount), Some(()));
|
||||||
}
|
}
|
||||||
|
prior.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,18 +321,12 @@ pub mod pallet {
|
|||||||
#[pallet::genesis_build]
|
#[pallet::genesis_build]
|
||||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||||
fn build(&self) {
|
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() {
|
for (id, stake) in self.networks.clone() {
|
||||||
AllocationPerKeyShare::<T>::set(id, Some(stake));
|
AllocationPerKeyShare::<T>::set(id, Some(stake));
|
||||||
for participant in self.participants.clone() {
|
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);
|
Pallet::<T>::new_set(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user