Skip to content

Commit

Permalink
Add exit status
Browse files Browse the repository at this point in the history
  • Loading branch information
chong-he committed Dec 18, 2024
1 parent 871692a commit 872daed
Showing 1 changed file with 59 additions and 53 deletions.
112 changes: 59 additions & 53 deletions validator_manager/src/exit_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde_json;
use slot_clock::{SlotClock, SystemTimeSlotClock};
use std::path::PathBuf;
use std::time::Duration;
use tokio::time::sleep;
use types::{ChainSpec, EthSpec, PublicKeyBytes};

pub const CMD: &str = "exit";
Expand All @@ -19,6 +18,7 @@ pub const VC_TOKEN_FLAG: &str = "vc-token";
pub const VALIDATOR_FLAG: &str = "validators";
pub const EXIT_EPOCH_FLAG: &str = "exit-epoch";
pub const SIGNATURE_FLAG: &str = "signature";
pub const EXIT_STATUS_FLAG: &str = "status";

pub fn cli_app() -> Command {
Command::new(CMD)
Expand Down Expand Up @@ -70,7 +70,6 @@ pub fn cli_app() -> Command {
.value_name("EPOCH")
.help("Provide the minimum epoch for processing voluntary exit.")
.action(ArgAction::Set)
.requires(SIGNATURE_FLAG)
.display_order(0),
)
.arg(
Expand All @@ -81,6 +80,15 @@ pub fn cli_app() -> Command {
.action(ArgAction::SetTrue)
.display_order(0),
)
.arg(
Arg::new(EXIT_STATUS_FLAG)
.long(EXIT_STATUS_FLAG)
.help("Display the voluntary exit status.")
.help_heading(FLAG_HEADER)
.action(ArgAction::SetTrue)
.requires(BEACON_URL_FLAG)
.display_order(0),
)
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
Expand All @@ -91,6 +99,7 @@ pub struct ExitConfig {
pub beacon_url: Option<SensitiveUrl>,
pub exit_epoch: Option<Epoch>,
pub signature: bool,
pub exit_status: bool,
}

impl ExitConfig {
Expand All @@ -113,6 +122,7 @@ impl ExitConfig {
beacon_url: clap_utils::parse_optional(matches, BEACON_URL_FLAG)?,
exit_epoch: clap_utils::parse_optional(matches, EXIT_EPOCH_FLAG)?,
signature: matches.get_flag(SIGNATURE_FLAG),
exit_status: matches.get_flag(EXIT_STATUS_FLAG),
})
}
}
Expand All @@ -138,6 +148,7 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
beacon_url,
exit_epoch,
signature,
exit_status,
} = config;

let (http_client, validators) = vc_http_client(vc_url.clone(), &vc_token_path).await?;
Expand All @@ -147,8 +158,6 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
validators_to_exit = validators.iter().map(|v| v.validating_pubkey).collect();
}

let mut first_sleep = true;

for validator_to_exit in validators_to_exit {
// Check that the validators_to_exit is in the validator client
if !validators
Expand Down Expand Up @@ -255,62 +264,58 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
);
}

if first_sleep {
sleep(Duration::from_secs(spec.seconds_per_slot)).await;
first_sleep = false;
}

// Check validator status after publishing voluntary exit
let updated_validator_data = beacon_node
.get_beacon_states_validator_id(
StateId::Head,
&ValidatorId::PublicKey(validator_to_exit),
)
.await
.map_err(|e| format!("Failed to get updated validator details: {:?}", e))?
.ok_or_else(|| {
format!(
"Validator {} is not present in the beacon state",
validator_to_exit
if exit_status {
let updated_validator_data = beacon_node
.get_beacon_states_validator_id(
StateId::Head,
&ValidatorId::PublicKey(validator_to_exit),
)
})?
.data;

if validator_data.status == ValidatorStatus::ActiveOngoing
&& updated_validator_data.status == ValidatorStatus::ActiveOngoing
// The case where the beacon node has not yet published the voluntary exit
{
eprintln!("Waiting for voluntary exit to be accepted into the beacon chain...");
} else if updated_validator_data.status == ValidatorStatus::ActiveExiting {
let exit_epoch = updated_validator_data.validator.exit_epoch;
let withdrawal_epoch = updated_validator_data.validator.withdrawable_epoch;
.await
.map_err(|e| format!("Failed to get updated validator details: {:?}", e))?
.ok_or_else(|| {
format!(
"Validator {} is not present in the beacon state",
validator_to_exit
)
})?
.data;

if validator_data.status == ValidatorStatus::ActiveOngoing
&& updated_validator_data.status == ValidatorStatus::ActiveOngoing
{
eprintln!("Voluntary exit for Validator {} is waiting to be accepted into the beacon chain.", validator_to_exit);
} else if updated_validator_data.status == ValidatorStatus::ActiveExiting {
let exit_epoch = updated_validator_data.validator.exit_epoch;
let withdrawal_epoch = updated_validator_data.validator.withdrawable_epoch;

eprintln!("Voluntary exit has been accepted into the beacon chain, but not yet finalized. \
eprintln!("Voluntary exit for validator {} has been accepted into the beacon chain, but not yet finalized. \
Finalization may take several minutes or longer. Before finalization there is a low \
probability that the exit may be reverted.");
eprintln!(
"Current epoch: {}, Exit epoch: {}, Withdrawable epoch: {}",
current_epoch, exit_epoch, withdrawal_epoch
);
eprintln!("Please keep your validator running till exit epoch");
eprintln!(
"Exit epoch in approximately {} secs",
(exit_epoch - current_epoch) * spec.seconds_per_slot * E::slots_per_epoch()
);
} else if updated_validator_data.status == ValidatorStatus::ExitedSlashed
|| updated_validator_data.status == ValidatorStatus::ExitedUnslashed
{
{
probability that the exit may be reverted.", validator_to_exit);
eprintln!(
"Current epoch: {}, Exit epoch: {}, Withdrawable epoch: {}",
current_epoch, exit_epoch, withdrawal_epoch
);
eprintln!("Please keep your validator running till exit epoch");
eprintln!(
"Validator has exited on epoch: {}",
updated_validator_data.validator.exit_epoch
"Exit epoch in approximately {} secs",
(exit_epoch - current_epoch) * spec.seconds_per_slot * E::slots_per_epoch()
);
} else if updated_validator_data.status == ValidatorStatus::ExitedSlashed
|| updated_validator_data.status == ValidatorStatus::ExitedUnslashed
{
{
eprintln!(
"Validator {} has exited at epoch: {}",
validator_to_exit, updated_validator_data.validator.exit_epoch
);
}
} else {
eprintln!(
"Validator {} has not initiated voluntary exit. Validator status is: {}",
validator_to_exit, updated_validator_data.status
)
}
} else {
eprintln!(
"Validator has not initiated voluntary exit. Validator status is: {}",
updated_validator_data.status
)
}
}
}
Expand Down Expand Up @@ -487,6 +492,7 @@ mod test {
beacon_url: Some(beacon_url),
exit_epoch: None,
signature: false,
exit_status: false,
});

self.validators = local_validators.clone();
Expand Down

0 comments on commit 872daed

Please sign in to comment.