diff --git a/substrate/staking/pallet/src/lib.rs b/substrate/staking/pallet/src/lib.rs index 34c2cb34e..b4bd9ed1e 100644 --- a/substrate/staking/pallet/src/lib.rs +++ b/substrate/staking/pallet/src/lib.rs @@ -155,7 +155,7 @@ pub mod pallet { ) -> DispatchResult { let account = ensure_signed(origin)?; - // remove participant if we necessary + // remove the participant if necessary. // we can't directly deallocate here, since the leaving validator // will be removed after the next session. We only deallocate then // on `end_session` for the right index. @@ -187,6 +187,7 @@ pub mod pallet { fn end_session(end_index: u32) { // do the deallocation of those validator funds + // who will not be in the set next session. let key = ValidatorSet { session: Session(end_index + 1), network: NetworkId::Serai }; let deallocating_validators = VsPallet::::deallocating_validators(key); for (account, amount, _) in deallocating_validators { diff --git a/substrate/validator-sets/pallet/src/lib.rs b/substrate/validator-sets/pallet/src/lib.rs index 2823cd899..22960ccc7 100644 --- a/substrate/validator-sets/pallet/src/lib.rs +++ b/substrate/validator-sets/pallet/src/lib.rs @@ -99,6 +99,22 @@ pub mod pallet { KeyGen { set: ValidatorSet, key_pair: KeyPair }, } + #[pallet::error] + pub enum Error { + /// Validator Set doesn't exist. + NonExistentValidatorSet, + /// Validator Set already generated keys. + AlreadyGeneratedKeys, + /// An invalid MuSig signature was provided. + BadSignature, + /// Not enough bond to participate in a set. + InSufficientBond, + /// Validator wasn't registered or active. + NonExistentValidator, + /// Trying to deallocate more than allocated. + InSufficientAllocation, + } + #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { @@ -133,22 +149,6 @@ pub mod pallet { } } - #[pallet::error] - pub enum Error { - /// Validator Set doesn't exist. - NonExistentValidatorSet, - /// Validator Set already generated keys. - AlreadyGeneratedKeys, - /// An invalid MuSig signature was provided. - BadSignature, - /// Not enough bond to participate in a set. - InSufficientBond, - /// Validator wasn't registered or active. - NonExistentValidator, - /// Trying to deallocate more than allocated. - InSufficientAllocation, - } - #[pallet::hooks] impl Hooks> for Pallet { /// Called when a block is initialized. @@ -210,7 +210,8 @@ pub mod pallet { *existing = Some(vec![(account, amount)]); } Ok::<_, Error>(()) - })?; + }) + .unwrap(); Ok(()) } @@ -264,12 +265,13 @@ pub mod pallet { } pub fn genesis_validator_set(network: NetworkId) -> Vec { - let mut current = Vec::new(); let key = ValidatorSet { session: Session(0), network }; - for p in Self::validator_set(key).unwrap().participants { - current.push(p.0); - } - current + Self::validator_set(key) + .unwrap() + .participants + .into_iter() + .map(|(id, _)| id) + .collect::>() } pub fn next_validator_set(new_index: u32, network: NetworkId) -> Vec { @@ -397,6 +399,8 @@ pub mod pallet { } // delete old keys + // we don't delete the end_index itself since we still need it + // to start the next session. let key = ValidatorSet { session: Session(end_index - 1), network }; JoiningValidators::::remove(key); DeallocatingValidators::::remove(key);