-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Add new validator API for voluntary exit #4119
Closed
Closed
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8b39d21
Add validator exit endpoint to validator API
jimmygchen 9ad2519
Update exit validator endpoint to return SignedVoluntaryExit instead …
jimmygchen 53529a2
Add http test for validator voluntary exit api
jimmygchen 3a6fe18
Rename file and fix test
jimmygchen f053edd
Add VC voluntary exit endpoint to Lighthouse book.
jimmygchen b204dea
Revert back to submitting exit to Beacon API
jimmygchen ef64b7f
Update exit endpoint to latest proposed spec
jimmygchen 63898d3
Update VC exit endpoint: remove confirm param, make epoch mandatory a…
jimmygchen f05fa5b
Remove exit endpoint from LH book
jimmygchen e1cddc9
Rename file only
jimmygchen 37adc18
Renamed function and file
jimmygchen f621c3e
Make Epoch optional again, default to current if not set.
jimmygchen abf58bb
Return 404 when validator is not found
jimmygchen 709131e
Improve validator exit test
jimmygchen 6edcfe3
Add more detail for 404s
paulhauner 9e8a17d
Improve logs when signing voluntary exits
jimmygchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
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); | ||
let validator_index = validator_store | ||
.validator_index(&pubkey_bytes) | ||
.ok_or_else(|| { | ||
warp_utils::reject::custom_not_found(format!( | ||
"Unable to find validator with public key: {}", | ||
pubkey_bytes.as_hex_string() | ||
)) | ||
})?; | ||
|
||
let voluntary_exit = VoluntaryExit { | ||
epoch, | ||
validator_index, | ||
}; | ||
|
||
info!(log, "Signing voluntary exit"; "validator" => pubkey_bytes.as_hex_string()); | ||
jimmygchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using this endpoint on Goerli on a VC with 5,000 validators on it (a pretty unreasonable amount of validators, I know). It turns out that it takes some time to obtain all the validator indices for all pubkeys when the VCs starts (on a fresh boot the VC only knows pubkeys but doesn't know validator indices). I was hitting this 404 and it took me a bit to figure out what was going on.
Here's a suggestion you're free to cherry-pick which would clarify things:
b1a1cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @paulhauner, thanks for this, nice changes! 👍 I've cherry-picked your changes. I wasn't aware that the validator indices were fetched / available later - good to know!