Skip to content

Commit 375f8a2

Browse files
committed
signature flag
1 parent 93e47b2 commit 375f8a2

File tree

1 file changed

+60
-57
lines changed

1 file changed

+60
-57
lines changed

validator_manager/src/exit_validators.rs

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde_json;
99
use slot_clock::{SlotClock, SystemTimeSlotClock};
1010
use std::path::PathBuf;
1111
use std::time::Duration;
12-
use tokio::time::sleep;
12+
// use tokio::time::sleep;
1313
use types::{ChainSpec, EthSpec, PublicKeyBytes};
1414
// use validator_http_api::create_signed_voluntary_exit::get_current_epoch;
1515

@@ -71,8 +71,7 @@ pub fn cli_app() -> Command {
7171
.long(SIGNATURE_FLAG)
7272
.help("Display the signature of the voluntary exit.")
7373
.help_heading(FLAG_HEADER)
74-
.value_parser(["true", "false"])
75-
.action(ArgAction::Set)
74+
.action(ArgAction::SetTrue)
7675
.display_order(0),
7776
)
7877
}
@@ -84,7 +83,7 @@ pub struct ExitConfig {
8483
pub validators_to_exit: Vec<PublicKeyBytes>,
8584
pub beacon_url: Option<SensitiveUrl>,
8685
pub exit_epoch: Option<Epoch>,
87-
pub signature: Option<bool>,
86+
pub signature: bool,
8887
}
8988

9089
impl ExitConfig {
@@ -106,7 +105,7 @@ impl ExitConfig {
106105
validators_to_exit,
107106
beacon_url: clap_utils::parse_optional(matches, BEACON_URL_FLAG)?,
108107
exit_epoch: clap_utils::parse_optional(matches, EXIT_EPOCH_FLAG)?,
109-
signature: clap_utils::parse_optional(matches, SIGNATURE_FLAG)?,
108+
signature: matches.get_flag(SIGNATURE_FLAG),
110109
})
111110
}
112111
}
@@ -157,7 +156,7 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
157156
.await
158157
.map_err(|e| format!("Failed to generate voluntary exit message: {}", e))?;
159158

160-
if signature.is_some() {
159+
if signature {
161160
let exit_message_json = serde_json::to_string(&exit_message.data);
162161
match exit_message_json {
163162
Ok(json) => println!("{}", json),
@@ -177,6 +176,19 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
177176
return Err("Beacon URL is not provided".into());
178177
};
179178

179+
if beacon_node
180+
.get_node_syncing()
181+
.await
182+
.map_err(|e| format!("Failed to get beacon node sync status: {:?}", e))?
183+
.data
184+
.is_syncing
185+
{
186+
return Err(
187+
"Beacon node is syncing, submit the voluntary exit later when beacon node is synced"
188+
.to_string(),
189+
);
190+
}
191+
180192
// Get beacon node spec to be used later
181193
let genesis_data = beacon_node
182194
.get_beacon_genesis()
@@ -193,19 +205,6 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
193205
let spec = ChainSpec::from_config::<E>(config_and_preset.config())
194206
.ok_or_else(|| "Failed to create chain spec".to_string())?;
195207

196-
if beacon_node
197-
.get_node_syncing()
198-
.await
199-
.map_err(|e| format!("Failed to get beacon node sync status: {:?}", e))?
200-
.data
201-
.is_syncing
202-
{
203-
return Err(
204-
"Beacon node is syncing, submit the voluntary exit later when beacon node is synced"
205-
.to_string(),
206-
);
207-
}
208-
209208
let validator_data = beacon_node
210209
.get_beacon_states_validator_id(
211210
StateId::Head,
@@ -249,52 +248,56 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
249248
"Successfully validated and published voluntary exit for validator {}",
250249
validator_to_exit
251250
);
252-
}
253251

254-
sleep(Duration::from_secs(spec.seconds_per_slot)).await;
252+
// sleep(Duration::from_secs(spec.seconds_per_slot)).await;
255253

256-
// Check validator status after publishing voluntary exit
257-
match validator_data.status {
258-
ValidatorStatus::ActiveExiting => {
259-
let exit_epoch = validator_data.validator.exit_epoch;
260-
let withdrawal_epoch = validator_data.validator.withdrawable_epoch;
254+
// Check validator status after publishing voluntary exit
255+
match validator_data.status {
256+
ValidatorStatus::ActiveExiting => {
257+
let exit_epoch = validator_data.validator.exit_epoch;
258+
let withdrawal_epoch = validator_data.validator.withdrawable_epoch;
261259

262-
// let slot_clock = SystemTimeSlotClock::new(
263-
// spec.genesis_slot,
264-
// Duration::from_secs(genesis_data.genesis_time),
265-
// Duration::from_secs(spec.config().seconds_per_slot),
266-
// );
260+
// let slot_clock = SystemTimeSlotClock::new(
261+
// spec.genesis_slot,
262+
// Duration::from_secs(genesis_data.genesis_time),
263+
// Duration::from_secs(spec.config().seconds_per_slot),
264+
// );
267265

268-
// let current_epoch = get_current_epoch::<SystemTimeSlotClock, E>(slot_clock)
269-
// .ok_or_else(|| "Unable to determine current epoch".to_string())?;
266+
// let current_epoch = get_current_epoch::<SystemTimeSlotClock, E>(slot_clock)
267+
// .ok_or_else(|| "Unable to determine current epoch".to_string())?;
270268

271-
eprintln!("Voluntary exit has been accepted into the beacon chain, but not yet finalized. \
269+
eprintln!("Voluntary exit has been accepted into the beacon chain, but not yet finalized. \
272270
Finalization may take several minutes or longer. Before finalization there is a low \
273271
probability that the exit may be reverted.");
274-
eprintln!(
275-
"Current epoch: {}, Exit epoch: {}, Withdrawable epoch: {}",
276-
current_epoch, exit_epoch, withdrawal_epoch
277-
);
278-
eprintln!("Please keep your validator running till exit epoch");
279-
eprintln!(
280-
"Exit epoch in approximately {} secs",
281-
(exit_epoch - current_epoch) * spec.seconds_per_slot * E::slots_per_epoch()
282-
);
272+
eprintln!(
273+
"Current epoch: {}, Exit epoch: {}, Withdrawable epoch: {}",
274+
current_epoch, exit_epoch, withdrawal_epoch
275+
);
276+
eprintln!("Please keep your validator running till exit epoch");
277+
eprintln!(
278+
"Exit epoch in approximately {} secs",
279+
(exit_epoch - current_epoch)
280+
* spec.seconds_per_slot
281+
* E::slots_per_epoch()
282+
);
283+
}
284+
285+
_ => {
286+
eprintln!(
287+
"Waiting for voluntary exit to be accepted into the beacon chain..."
288+
)
289+
} // fn get_current_epoch<T: 'static + SlotClock + Clone, E: EthSpec>(
290+
// slot_clock: T,
291+
// ) -> Option<Epoch> {
292+
// slot_clock.now().map(|s| s.epoch(E::slots_per_epoch()))
293+
// }
294+
295+
// let spec = ChainSpec::mainnet();
296+
297+
// let current_epoch =
298+
// get_current_epoch::<E>(genesis_time, &spec).ok_or("Failed to get current epoch")?;
299+
//let current_epoch = get_current_epoch::<E>(genesis_data.genesis_time, spec);
283300
}
284-
285-
_ => {
286-
eprintln!("Waiting for voluntary exit to be accepted into the beacon chain...")
287-
} // fn get_current_epoch<T: 'static + SlotClock + Clone, E: EthSpec>(
288-
// slot_clock: T,
289-
// ) -> Option<Epoch> {
290-
// slot_clock.now().map(|s| s.epoch(E::slots_per_epoch()))
291-
// }
292-
293-
// let spec = ChainSpec::mainnet();
294-
295-
// let current_epoch =
296-
// get_current_epoch::<E>(genesis_time, &spec).ok_or("Failed to get current epoch")?;
297-
//let current_epoch = get_current_epoch::<E>(genesis_data.genesis_time, spec);
298301
}
299302
}
300303
}

0 commit comments

Comments
 (0)