forked from sigp/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new validator API for voluntary exit (sigp#4119)
## Issue Addressed Addresses sigp#4117 ## Proposed Changes See ethereum/keymanager-APIs#58 for proposed API specification. ## TODO - [x] ~~Add submission to BN~~ - removed, see discussion in [keymanager API](ethereum/keymanager-APIs#58) - [x] ~~Add flag to allow voluntary exit via the API~~ - no longer needed now the VC doesn't submit exit directly - [x] ~~Additional verification / checks, e.g. if validator on same network as BN~~ - to be done on client side - [x] ~~Potentially wait for the message to propagate and return some exit information in the response~~ - not required - [x] Update http tests - [x] ~~Update lighthouse book~~ - not required if this endpoint makes it to the standard keymanager API Co-authored-by: Paul Hauner <[email protected]> Co-authored-by: Jimmy Chen <[email protected]>
- Loading branch information
1 parent
bb1916e
commit 3f8dbb1
Showing
10 changed files
with
256 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
validator_client/src/http_api/create_signed_voluntary_exit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::validator_store::ValidatorStore; | ||
use bls::{PublicKey, PublicKeyBytes}; | ||
use slog::{info, Logger}; | ||
use slot_clock::SlotClock; | ||
use std::sync::Arc; | ||
use types::{Epoch, EthSpec, SignedVoluntaryExit, VoluntaryExit}; | ||
|
||
pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: EthSpec>( | ||
pubkey: PublicKey, | ||
maybe_epoch: Option<Epoch>, | ||
validator_store: Arc<ValidatorStore<T, E>>, | ||
slot_clock: T, | ||
log: Logger, | ||
) -> Result<SignedVoluntaryExit, warp::Rejection> { | ||
let epoch = match maybe_epoch { | ||
Some(epoch) => epoch, | ||
None => get_current_epoch::<T, E>(slot_clock).ok_or_else(|| { | ||
warp_utils::reject::custom_server_error("Unable to determine current epoch".to_string()) | ||
})?, | ||
}; | ||
|
||
let pubkey_bytes = PublicKeyBytes::from(pubkey); | ||
if !validator_store.has_validator(&pubkey_bytes) { | ||
return Err(warp_utils::reject::custom_not_found(format!( | ||
"{} is disabled or not managed by this validator client", | ||
pubkey_bytes.as_hex_string() | ||
))); | ||
} | ||
|
||
let validator_index = validator_store | ||
.validator_index(&pubkey_bytes) | ||
.ok_or_else(|| { | ||
warp_utils::reject::custom_not_found(format!( | ||
"The validator index for {} is not known. The validator client \ | ||
may still be initializing or the validator has not yet had a \ | ||
deposit processed.", | ||
pubkey_bytes.as_hex_string() | ||
)) | ||
})?; | ||
|
||
let voluntary_exit = VoluntaryExit { | ||
epoch, | ||
validator_index, | ||
}; | ||
|
||
info!( | ||
log, | ||
"Signing voluntary exit"; | ||
"validator" => pubkey_bytes.as_hex_string(), | ||
"epoch" => epoch | ||
); | ||
|
||
let signed_voluntary_exit = validator_store | ||
.sign_voluntary_exit(pubkey_bytes, voluntary_exit) | ||
.await | ||
.map_err(|e| { | ||
warp_utils::reject::custom_server_error(format!( | ||
"Failed to sign voluntary exit: {:?}", | ||
e | ||
)) | ||
})?; | ||
|
||
Ok(signed_voluntary_exit) | ||
} | ||
|
||
/// Calculates the current epoch from the genesis time and current time. | ||
fn get_current_epoch<T: 'static + SlotClock + Clone, E: EthSpec>(slot_clock: T) -> Option<Epoch> { | ||
slot_clock.now().map(|s| s.epoch(E::slots_per_epoch())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.