Add Deneb builder test & update mock builder (#4607)

* Update mock builder, mev-rs dependencies, eth2 lib to support deneb builder flow

* Replace `sharingForkTime` with `cancunTime`

* Patch `ethereum-consensus` to include some deneb-devnet-8 changes

* Add deneb builder test and fix block contents deserialization

* Fix builder bid encoding issue and passing deneb builder test \o/

* Fix test compilation

* Revert `cancunTime` change in genesis to pass doppelganger tests
This commit is contained in:
Jimmy Chen
2023-08-19 10:12:09 +10:00
committed by GitHub
parent f031a570ce
commit 4898430330
18 changed files with 440 additions and 130 deletions

View File

@@ -9,9 +9,22 @@ use superstruct::superstruct;
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;
pub type KzgCommitments<T> =
pub type KzgCommitments<T> = VariableList<KzgCommitment, <T as EthSpec>::MaxBlobsPerBlock>;
pub type BlockBodyKzgCommitments<T> =
VariableList<KzgCommitment, <T as EthSpec>::MaxBlobCommitmentsPerBlock>;
pub fn to_block_kzg_commitments<E: EthSpec>(
commitments: KzgCommitments<E>,
) -> BlockBodyKzgCommitments<E> {
commitments.to_vec().into()
}
pub fn from_block_kzg_commitments<E: EthSpec>(
commitments: &BlockBodyKzgCommitments<E>,
) -> KzgCommitments<E> {
commitments.to_vec().into()
}
/// The body of a `BeaconChain` block, containing operations.
///
/// This *superstruct* abstracts over the hard-fork.
@@ -72,7 +85,7 @@ pub struct BeaconBlockBody<T: EthSpec, Payload: AbstractExecPayload<T> = FullPay
pub bls_to_execution_changes:
VariableList<SignedBlsToExecutionChange, T::MaxBlsToExecutionChanges>,
#[superstruct(only(Deneb))]
pub blob_kzg_commitments: KzgCommitments<T>,
pub blob_kzg_commitments: BlockBodyKzgCommitments<T>,
#[superstruct(only(Base, Altair))]
#[ssz(skip_serializing, skip_deserializing)]
#[tree_hash(skip_hashing)]

View File

@@ -84,11 +84,14 @@ impl<T: EthSpec> BlobItems<T> for BlobRootsList<T> {
Ok(roots)
}
fn try_from_blobs(_blobs: BlobsList<T>) -> Result<Self, String> {
// It is possible to convert from blobs to blob roots, however this should be done using
// `From` or `Into` instead of this generic implementation; this function implementation
// should be unreachable, and attempt to use this indicates a bug somewhere.
Err("Unexpected conversion from blob to blob roots".to_string())
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String> {
VariableList::new(
blobs
.into_iter()
.map(|blob| blob.tree_hash_root())
.collect(),
)
.map_err(|e| format!("{e:?}"))
}
fn len(&self) -> usize {
@@ -216,6 +219,21 @@ impl<E: EthSpec> From<Arc<BlobSidecar<E>>> for BlindedBlobSidecar {
}
}
impl<E: EthSpec> From<BlobSidecar<E>> for BlindedBlobSidecar {
fn from(blob_sidecar: BlobSidecar<E>) -> Self {
BlindedBlobSidecar {
block_root: blob_sidecar.block_root,
index: blob_sidecar.index,
slot: blob_sidecar.slot,
block_parent_root: blob_sidecar.block_parent_root,
proposer_index: blob_sidecar.proposer_index,
blob_root: blob_sidecar.blob.tree_hash_root(),
kzg_commitment: blob_sidecar.kzg_commitment,
kzg_proof: blob_sidecar.kzg_proof,
}
}
}
impl<T: EthSpec> PartialOrd for BlobSidecar<T> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.index.partial_cmp(&other.index)

View File

@@ -1,17 +1,19 @@
use crate::beacon_block_body::KzgCommitments;
use crate::{
BlobRootsList, ChainSpec, EthSpec, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb,
ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, ForkName, ForkVersionDeserialize,
KzgProofs, SignedRoot, Uint256,
BlobRootsList, BlobsBundle, ChainSpec, EthSpec, ExecutionPayloadHeaderCapella,
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, ForkName,
ForkVersionDeserialize, KzgProofs, SignedRoot, Uint256,
};
use bls::PublicKeyBytes;
use bls::Signature;
use serde::Deserializer;
use serde_derive::{Deserialize, Serialize};
use ssz_derive::Encode;
use superstruct::superstruct;
use tree_hash::TreeHash;
use tree_hash_derive::TreeHash;
#[derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone)]
#[derive(PartialEq, Debug, Default, Serialize, Deserialize, TreeHash, Clone, Encode)]
#[serde(bound = "E: EthSpec")]
pub struct BlindedBlobsBundle<E: EthSpec> {
pub commitments: KzgCommitments<E>,
@@ -19,6 +21,21 @@ pub struct BlindedBlobsBundle<E: EthSpec> {
pub blob_roots: BlobRootsList<E>,
}
impl<E: EthSpec> From<BlobsBundle<E>> for BlindedBlobsBundle<E> {
fn from(blobs_bundle: BlobsBundle<E>) -> Self {
BlindedBlobsBundle {
commitments: blobs_bundle.commitments,
proofs: blobs_bundle.proofs,
blob_roots: blobs_bundle
.blobs
.into_iter()
.map(|blob| blob.tree_hash_root())
.collect::<Vec<_>>()
.into(),
}
}
}
#[superstruct(
variants(Merge, Capella, Deneb),
variant_attributes(

View File

@@ -972,9 +972,10 @@ impl<T: EthSpec> From<BlindedPayload<T>> for ExecutionPayloadHeader<T> {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Encode)]
#[serde(untagged)]
#[serde(bound = "E: EthSpec")]
#[ssz(enum_behaviour = "transparent")]
pub enum FullPayloadContents<E: EthSpec> {
Payload(ExecutionPayload<E>),
PayloadAndBlobs(ExecutionPayloadAndBlobs<E>),
@@ -1037,14 +1038,14 @@ impl<E: EthSpec> ForkVersionDeserialize for FullPayloadContents<E> {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Encode)]
#[serde(bound = "E: EthSpec")]
pub struct ExecutionPayloadAndBlobs<E: EthSpec> {
pub execution_payload: ExecutionPayload<E>,
pub blobs_bundle: BlobsBundle<E>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Encode)]
#[serde(bound = "E: EthSpec")]
pub struct BlobsBundle<E: EthSpec> {
pub commitments: KzgCommitments<E>,

View File

@@ -59,13 +59,6 @@ impl<T: EthSpec> SignedSidecar<T, BlindedBlobSidecar> {
}
}
/// List of Signed Sidecars that implements `Sidecar`.
pub type SignedSidecarList<T, Sidecar> =
VariableList<SignedSidecar<T, Sidecar>, <T as EthSpec>::MaxBlobsPerBlock>;
pub type SignedBlobSidecarList<T> = SignedSidecarList<T, BlobSidecar<T>>;
pub type SignedBlobSidecar<T> = SignedSidecar<T, BlobSidecar<T>>;
impl<T: EthSpec> SignedBlobSidecar<T> {
/// Verify `self.signature`.
///
@@ -99,3 +92,21 @@ impl<T: EthSpec> SignedBlobSidecar<T> {
self.signature.verify(pubkey, message)
}
}
impl<T: EthSpec> From<SignedBlobSidecar<T>> for SignedBlindedBlobSidecar<T> {
fn from(signed: SignedBlobSidecar<T>) -> Self {
SignedBlindedBlobSidecar {
message: Arc::new(signed.message.into()),
signature: signed.signature,
_phantom: PhantomData,
}
}
}
pub type SignedBlobSidecar<T> = SignedSidecar<T, BlobSidecar<T>>;
pub type SignedBlindedBlobSidecar<T> = SignedSidecar<T, BlindedBlobSidecar>;
/// List of Signed Sidecars that implements `Sidecar`.
pub type SignedSidecarList<T, Sidecar> =
VariableList<SignedSidecar<T, Sidecar>, <T as EthSpec>::MaxBlobsPerBlock>;
pub type SignedBlobSidecarList<T> = SignedSidecarList<T, BlobSidecar<T>>;