From bff19dee6f472640da6a73682c98b2b392f8f90d Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Sun, 3 Mar 2024 11:35:48 -0500 Subject: [PATCH] stake: clean-up `add_validator_inner` --- .../validator_handler/validator_manager.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/core/component/stake/src/component/validator_handler/validator_manager.rs b/crates/core/component/stake/src/component/validator_handler/validator_manager.rs index a31fda13dc..becb04af9b 100644 --- a/crates/core/component/stake/src/component/validator_handler/validator_manager.rs +++ b/crates/core/component/stake/src/component/validator_handler/validator_manager.rs @@ -298,7 +298,6 @@ pub trait ValidatorManager: StateWrite { #[instrument(skip(self))] /// Try to perform a state transition in/out of the `Defined` precursor state. /// If successful, returns the new state, otherwise returns `None`. - /// async fn try_precursor_transition( &mut self, validator_id: &IdentityKey, @@ -356,8 +355,8 @@ pub trait ValidatorManager: StateWrite { Some(new_state) } - /// Add a new genesis validator which will start in the [`Active`] state with its - /// genesis allocation bonded. + /// Add a new genesis validator starting in the [`Active`] state with its + /// genesis allocation entirely bonded. #[instrument(skip(self, genesis_allocations))] async fn add_genesis_validator( &mut self, @@ -394,9 +393,12 @@ pub trait ValidatorManager: StateWrite { ) .await?; - // We also need to start tracking uptime of new validators, because they - // start in the active state, so we need to bundle in the effects of the - // Inactive -> Active state transition. + // Here, we are in the special case of genesis validators. Since they start in + // the active state we need to bundle the effects of the `Inactive -> Active` + // state transition: + // - add them to the consensus set index + // - track their uptime + self.add_consensus_set_index(&validator.identity_key); self.set_validator_uptime( &validator.identity_key, Uptime::new(0, self.signed_blocks_window_len().await? as usize), @@ -469,11 +471,6 @@ pub trait ValidatorManager: StateWrite { self.set_validator_power(&validator_identity, initial_voting_power)?; self.set_validator_bonding_state(&validator_identity, initial_bonding_state); - // For genesis validators, we also need to add them to the consensus set index. - if initial_state == validator::State::Active { - self.add_consensus_set_index(&validator_identity); - } - // Finally, update metrics for the new validator. match initial_state { validator::State::Active => {