mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Implement skip_randao_verification and blinded block rewards API (#3540)
## Issue Addressed https://github.com/ethereum/beacon-APIs/pull/222 ## Proposed Changes Update Lighthouse's randao verification API to match the `beacon-APIs` spec. We implemented the API before spec stabilisation, and it changed slightly in the course of review. Rather than a flag `verify_randao` taking a boolean value, the new API uses a `skip_randao_verification` flag which takes no argument. The new spec also requires the randao reveal to be present and equal to the point-at-infinity when `skip_randao_verification` is set. I've also updated the `POST /lighthouse/analysis/block_rewards` API to take blinded blocks as input, as the execution payload is irrelevant and we may want to assess blocks produced by builders. ## Additional Info This is technically a breaking change, but seeing as I suspect I'm the only one using these parameters/APIs, I think we're OK to include this in a patch release.
This commit is contained in:
@@ -1233,17 +1233,17 @@ impl BeaconNodeHttpClient {
|
||||
randao_reveal: &SignatureBytes,
|
||||
graffiti: Option<&Graffiti>,
|
||||
) -> Result<ForkVersionedResponse<BeaconBlock<T, Payload>>, Error> {
|
||||
self.get_validator_blocks_with_verify_randao(slot, Some(randao_reveal), graffiti, None)
|
||||
self.get_validator_blocks_modular(slot, randao_reveal, graffiti, SkipRandaoVerification::No)
|
||||
.await
|
||||
}
|
||||
|
||||
/// `GET v2/validator/blocks/{slot}`
|
||||
pub async fn get_validator_blocks_with_verify_randao<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
pub async fn get_validator_blocks_modular<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
&self,
|
||||
slot: Slot,
|
||||
randao_reveal: Option<&SignatureBytes>,
|
||||
randao_reveal: &SignatureBytes,
|
||||
graffiti: Option<&Graffiti>,
|
||||
verify_randao: Option<bool>,
|
||||
skip_randao_verification: SkipRandaoVerification,
|
||||
) -> Result<ForkVersionedResponse<BeaconBlock<T, Payload>>, Error> {
|
||||
let mut path = self.eth_path(V2)?;
|
||||
|
||||
@@ -1253,19 +1253,17 @@ impl BeaconNodeHttpClient {
|
||||
.push("blocks")
|
||||
.push(&slot.to_string());
|
||||
|
||||
if let Some(randao_reveal) = randao_reveal {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("randao_reveal", &randao_reveal.to_string());
|
||||
}
|
||||
path.query_pairs_mut()
|
||||
.append_pair("randao_reveal", &randao_reveal.to_string());
|
||||
|
||||
if let Some(graffiti) = graffiti {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("graffiti", &graffiti.to_string());
|
||||
}
|
||||
|
||||
if let Some(verify_randao) = verify_randao {
|
||||
if skip_randao_verification == SkipRandaoVerification::Yes {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("verify_randao", &verify_randao.to_string());
|
||||
.append_pair("skip_randao_verification", "");
|
||||
}
|
||||
|
||||
self.get(path).await
|
||||
@@ -1278,25 +1276,22 @@ impl BeaconNodeHttpClient {
|
||||
randao_reveal: &SignatureBytes,
|
||||
graffiti: Option<&Graffiti>,
|
||||
) -> Result<ForkVersionedResponse<BeaconBlock<T, Payload>>, Error> {
|
||||
self.get_validator_blinded_blocks_with_verify_randao(
|
||||
self.get_validator_blinded_blocks_modular(
|
||||
slot,
|
||||
Some(randao_reveal),
|
||||
randao_reveal,
|
||||
graffiti,
|
||||
None,
|
||||
SkipRandaoVerification::No,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// `GET v1/validator/blinded_blocks/{slot}`
|
||||
pub async fn get_validator_blinded_blocks_with_verify_randao<
|
||||
T: EthSpec,
|
||||
Payload: ExecPayload<T>,
|
||||
>(
|
||||
pub async fn get_validator_blinded_blocks_modular<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
&self,
|
||||
slot: Slot,
|
||||
randao_reveal: Option<&SignatureBytes>,
|
||||
randao_reveal: &SignatureBytes,
|
||||
graffiti: Option<&Graffiti>,
|
||||
verify_randao: Option<bool>,
|
||||
skip_randao_verification: SkipRandaoVerification,
|
||||
) -> Result<ForkVersionedResponse<BeaconBlock<T, Payload>>, Error> {
|
||||
let mut path = self.eth_path(V1)?;
|
||||
|
||||
@@ -1306,19 +1301,17 @@ impl BeaconNodeHttpClient {
|
||||
.push("blinded_blocks")
|
||||
.push(&slot.to_string());
|
||||
|
||||
if let Some(randao_reveal) = randao_reveal {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("randao_reveal", &randao_reveal.to_string());
|
||||
}
|
||||
path.query_pairs_mut()
|
||||
.append_pair("randao_reveal", &randao_reveal.to_string());
|
||||
|
||||
if let Some(graffiti) = graffiti {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("graffiti", &graffiti.to_string());
|
||||
}
|
||||
|
||||
if let Some(verify_randao) = verify_randao {
|
||||
if skip_randao_verification == SkipRandaoVerification::Yes {
|
||||
path.query_pairs_mut()
|
||||
.append_pair("verify_randao", &verify_randao.to_string());
|
||||
.append_key_only("skip_randao_verification");
|
||||
}
|
||||
|
||||
self.get(path).await
|
||||
|
||||
@@ -658,16 +658,34 @@ pub struct ProposerData {
|
||||
pub slot: Slot,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct ValidatorBlocksQuery {
|
||||
pub randao_reveal: Option<SignatureBytes>,
|
||||
pub randao_reveal: SignatureBytes,
|
||||
pub graffiti: Option<Graffiti>,
|
||||
#[serde(default = "default_verify_randao")]
|
||||
pub verify_randao: bool,
|
||||
pub skip_randao_verification: SkipRandaoVerification,
|
||||
}
|
||||
|
||||
fn default_verify_randao() -> bool {
|
||||
true
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize)]
|
||||
#[serde(try_from = "Option<String>")]
|
||||
pub enum SkipRandaoVerification {
|
||||
Yes,
|
||||
#[default]
|
||||
No,
|
||||
}
|
||||
|
||||
/// Parse a `skip_randao_verification` query parameter.
|
||||
impl TryFrom<Option<String>> for SkipRandaoVerification {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(opt: Option<String>) -> Result<Self, String> {
|
||||
match opt.as_deref() {
|
||||
None => Ok(SkipRandaoVerification::No),
|
||||
Some("") => Ok(SkipRandaoVerification::Yes),
|
||||
Some(s) => Err(format!(
|
||||
"skip_randao_verification does not take a value, got: {s}"
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user