Builder Specs v0.2.0 (#3134)

## Issue Addressed

https://github.com/sigp/lighthouse/issues/3091

Extends https://github.com/sigp/lighthouse/pull/3062, adding pre-bellatrix block support on blinded endpoints and allowing the normal proposal flow (local payload construction) on blinded endpoints. This resulted in better fallback logic because the VC will not have to switch endpoints on failure in the BN <> Builder API, the BN can just fallback immediately and without repeating block processing that it shouldn't need to. We can also keep VC fallback from the VC<>BN API's blinded endpoint to full endpoint.

## Proposed Changes

- Pre-bellatrix blocks on blinded endpoints
- Add a new `PayloadCache` to the execution layer
- Better fallback-from-builder logic

## Todos

- [x] Remove VC transition logic
- [x] Add logic to only enable builder flow after Merge transition finalization
- [x] Tests
- [x] Fix metrics
- [x] Rustdocs


Co-authored-by: Mac L <mjladson@pm.me>
Co-authored-by: realbigsean <sean@sigmaprime.io>
This commit is contained in:
realbigsean
2022-07-30 00:22:37 +00:00
parent 25f0e261cb
commit 6c2d8b2262
61 changed files with 3522 additions and 687 deletions

View File

@@ -1,13 +1,14 @@
use crate::{EthSpec, ExecPayload, ExecutionPayloadHeader, Uint256};
use bls::blst_implementations::PublicKeyBytes;
use crate::{ChainSpec, EthSpec, ExecPayload, ExecutionPayloadHeader, SignedRoot, Uint256};
use bls::PublicKeyBytes;
use bls::Signature;
use serde::{Deserialize as De, Deserializer, Serialize as Ser, Serializer};
use serde_derive::{Deserialize, Serialize};
use serde_with::{serde_as, DeserializeAs, SerializeAs};
use std::marker::PhantomData;
use tree_hash_derive::TreeHash;
#[serde_as]
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone)]
#[serde(bound = "E: EthSpec, Payload: ExecPayload<E>")]
pub struct BuilderBid<E: EthSpec, Payload: ExecPayload<E>> {
#[serde_as(as = "BlindedPayloadAsHeader<E>")]
@@ -16,9 +17,12 @@ pub struct BuilderBid<E: EthSpec, Payload: ExecPayload<E>> {
pub value: Uint256,
pub pubkey: PublicKeyBytes,
#[serde(skip)]
#[tree_hash(skip_hashing)]
_phantom_data: PhantomData<E>,
}
impl<E: EthSpec, Payload: ExecPayload<E>> SignedRoot for BuilderBid<E, Payload> {}
/// Validator registration, for use in interacting with servers implementing the builder API.
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[serde(bound = "E: EthSpec, Payload: ExecPayload<E>")]
@@ -50,3 +54,17 @@ impl<'de, E: EthSpec, Payload: ExecPayload<E>> DeserializeAs<'de, Payload>
.map_err(|_| serde::de::Error::custom("unable to convert payload header to payload"))
}
}
impl<E: EthSpec, Payload: ExecPayload<E>> SignedBuilderBid<E, Payload> {
pub fn verify_signature(&self, spec: &ChainSpec) -> bool {
self.message
.pubkey
.decompress()
.map(|pubkey| {
let domain = spec.get_builder_domain();
let message = self.message.signing_root(domain);
self.signature.verify(&pubkey, message)
})
.unwrap_or(false)
}
}

View File

@@ -1355,4 +1355,12 @@ mod yaml_tests {
)
);
}
#[test]
fn test_domain_builder() {
assert_eq!(
int_to_bytes4(ApplicationDomain::Builder.get_domain_constant()),
[0, 0, 0, 1]
);
}
}

View File

@@ -1,12 +1,14 @@
use crate::test_utils::TestRandom;
use crate::Hash256;
use derivative::Derivative;
use rand::RngCore;
use serde_derive::{Deserialize, Serialize};
use ssz::{Decode, DecodeError, Encode};
use std::fmt;
#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))]
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[derive(Default, Clone, Copy, Serialize, Deserialize, Eq, PartialEq, Hash, Derivative)]
#[derivative(Debug = "transparent")]
#[serde(transparent)]
pub struct ExecutionBlockHash(Hash256);

View File

@@ -9,6 +9,7 @@ use std::hash::Hash;
use test_random_derive::TestRandom;
use tree_hash::TreeHash;
#[derive(Debug)]
pub enum BlockType {
Blinded,
Full,
@@ -18,6 +19,7 @@ pub trait ExecPayload<T: EthSpec>:
Debug
+ Clone
+ Encode
+ Debug
+ Decode
+ TestRandom
+ TreeHash
@@ -45,6 +47,7 @@ pub trait ExecPayload<T: EthSpec>:
fn timestamp(&self) -> u64;
fn block_hash(&self) -> ExecutionBlockHash;
fn fee_recipient(&self) -> Address;
fn gas_limit(&self) -> u64;
}
impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
@@ -79,6 +82,10 @@ impl<T: EthSpec> ExecPayload<T> for FullPayload<T> {
fn fee_recipient(&self) -> Address {
self.execution_payload.fee_recipient
}
fn gas_limit(&self) -> u64 {
self.execution_payload.gas_limit
}
}
impl<T: EthSpec> ExecPayload<T> for BlindedPayload<T> {
@@ -113,6 +120,10 @@ impl<T: EthSpec> ExecPayload<T> for BlindedPayload<T> {
fn fee_recipient(&self) -> Address {
self.execution_payload_header.fee_recipient
}
fn gas_limit(&self) -> u64 {
self.execution_payload_header.gas_limit
}
}
#[derive(Debug, Clone, TestRandom, Serialize, Deserialize, Derivative)]