mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-03 09:29:46 +00:00
Ensure TotalAllocatedStake is set for the first set
This commit is contained in:
parent
ba244e8090
commit
52bb918cc9
1 changed files with 15 additions and 6 deletions
|
@ -691,6 +691,15 @@ pub mod pallet {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_total_allocated_stake(network: NetworkId) {
|
||||
let participants = Participants::<T>::get(network)
|
||||
.expect("setting TotalAllocatedStake for a network without participants");
|
||||
let total_stake = participants.iter().fold(0, |acc, (addr, _)| {
|
||||
acc + Allocations::<T>::get((network, addr)).unwrap_or(Amount(0)).0
|
||||
});
|
||||
TotalAllocatedStake::<T>::set(network, Some(Amount(total_stake)));
|
||||
}
|
||||
|
||||
// TODO: This is called retire_set, yet just starts retiring the set
|
||||
// Update the nomenclature within this function
|
||||
pub fn retire_set(set: ValidatorSet) {
|
||||
|
@ -715,12 +724,7 @@ pub mod pallet {
|
|||
});
|
||||
|
||||
// Update the total allocated stake to be for the current set
|
||||
let participants =
|
||||
Participants::<T>::get(set.network).expect("set retired without a new set");
|
||||
let total_stake = participants.iter().fold(0, |acc, (addr, _)| {
|
||||
acc + Allocations::<T>::get((set.network, addr)).unwrap_or(Amount(0)).0
|
||||
});
|
||||
TotalAllocatedStake::<T>::set(set.network, Some(Amount(total_stake)));
|
||||
self.set_total_allocated_stake(set.network);
|
||||
}
|
||||
|
||||
/// Take the amount deallocatable.
|
||||
|
@ -907,6 +911,11 @@ pub mod pallet {
|
|||
|
||||
Keys::<T>::set(set, Some(key_pair.clone()));
|
||||
|
||||
// If this is the first ever set for this network, set TotalAllocatedStake now
|
||||
if session == Session(0) {
|
||||
self.set_total_allocated_stake(network);
|
||||
}
|
||||
|
||||
// This does not remove from TotalAllocatedStake or InSet in order to:
|
||||
// 1) Not decrease the stake present in this set. This means removed participants are
|
||||
// still liable for the economic security of the external network. This prevents
|
||||
|
|
Loading…
Reference in a new issue