@@ -9,7 +9,7 @@ use serde_json;
9
9
use slot_clock:: { SlotClock , SystemTimeSlotClock } ;
10
10
use std:: path:: PathBuf ;
11
11
use std:: time:: Duration ;
12
- use tokio:: time:: sleep;
12
+ // use tokio::time::sleep;
13
13
use types:: { ChainSpec , EthSpec , PublicKeyBytes } ;
14
14
// use validator_http_api::create_signed_voluntary_exit::get_current_epoch;
15
15
@@ -71,8 +71,7 @@ pub fn cli_app() -> Command {
71
71
. long ( SIGNATURE_FLAG )
72
72
. help ( "Display the signature of the voluntary exit." )
73
73
. help_heading ( FLAG_HEADER )
74
- . value_parser ( [ "true" , "false" ] )
75
- . action ( ArgAction :: Set )
74
+ . action ( ArgAction :: SetTrue )
76
75
. display_order ( 0 ) ,
77
76
)
78
77
}
@@ -84,7 +83,7 @@ pub struct ExitConfig {
84
83
pub validators_to_exit : Vec < PublicKeyBytes > ,
85
84
pub beacon_url : Option < SensitiveUrl > ,
86
85
pub exit_epoch : Option < Epoch > ,
87
- pub signature : Option < bool > ,
86
+ pub signature : bool ,
88
87
}
89
88
90
89
impl ExitConfig {
@@ -106,7 +105,7 @@ impl ExitConfig {
106
105
validators_to_exit,
107
106
beacon_url : clap_utils:: parse_optional ( matches, BEACON_URL_FLAG ) ?,
108
107
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 ) ,
110
109
} )
111
110
}
112
111
}
@@ -157,7 +156,7 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
157
156
. await
158
157
. map_err ( |e| format ! ( "Failed to generate voluntary exit message: {}" , e) ) ?;
159
158
160
- if signature. is_some ( ) {
159
+ if signature {
161
160
let exit_message_json = serde_json:: to_string ( & exit_message. data ) ;
162
161
match exit_message_json {
163
162
Ok ( json) => println ! ( "{}" , json) ,
@@ -177,6 +176,19 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
177
176
return Err ( "Beacon URL is not provided" . into ( ) ) ;
178
177
} ;
179
178
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
+
180
192
// Get beacon node spec to be used later
181
193
let genesis_data = beacon_node
182
194
. get_beacon_genesis ( )
@@ -193,19 +205,6 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
193
205
let spec = ChainSpec :: from_config :: < E > ( config_and_preset. config ( ) )
194
206
. ok_or_else ( || "Failed to create chain spec" . to_string ( ) ) ?;
195
207
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
-
209
208
let validator_data = beacon_node
210
209
. get_beacon_states_validator_id (
211
210
StateId :: Head ,
@@ -249,52 +248,56 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
249
248
"Successfully validated and published voluntary exit for validator {}" ,
250
249
validator_to_exit
251
250
) ;
252
- }
253
251
254
- sleep ( Duration :: from_secs ( spec. seconds_per_slot ) ) . await ;
252
+ // sleep(Duration::from_secs(spec.seconds_per_slot)).await;
255
253
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 ;
261
259
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
+ // );
267
265
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())?;
270
268
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. \
272
270
Finalization may take several minutes or longer. Before finalization there is a low \
273
271
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);
283
300
}
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);
298
301
}
299
302
}
300
303
}
0 commit comments