Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 9 additions & 70 deletions crates/common/src/pbs/types/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};

use super::{
blinded_block_body::{BlindedBeaconBlockBodyDeneb, BlindedBeaconBlockBodyElectra},
blobs_bundle::BlobsBundle,
execution_payload::ExecutionPayload,
spec::{DenebSpec, ElectraSpec},
utils::VersionedResponse,
blinded_block_body::BlindedBeaconBlockBodyElectra, blobs_bundle::BlobsBundle,
execution_payload::ExecutionPayload, spec::ElectraSpec, utils::VersionedResponse,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
Expand All @@ -21,28 +18,24 @@ impl SignedBlindedBeaconBlock {
pub fn block_hash(&self) -> B256 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.body.execution_payload_header.block_hash,
BlindedBeaconBlock::Deneb(b) => b.body.execution_payload_header.block_hash,
}
}

pub fn block_number(&self) -> u64 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.body.execution_payload_header.block_number,
BlindedBeaconBlock::Deneb(b) => b.body.execution_payload_header.block_number,
}
}

pub fn parent_hash(&self) -> B256 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.body.execution_payload_header.parent_hash,
BlindedBeaconBlock::Deneb(b) => b.body.execution_payload_header.parent_hash,
}
}

pub fn slot(&self) -> u64 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.slot,
BlindedBeaconBlock::Deneb(b) => b.slot,
}
}
}
Expand All @@ -51,27 +44,15 @@ impl SignedBlindedBeaconBlock {
#[serde(untagged)]
#[ssz(enum_behaviour = "transparent")]
pub enum BlindedBeaconBlock {
Deneb(BlindedBeaconBlockDeneb),
Electra(BlindedBeaconBlockElectra),
}

impl Default for BlindedBeaconBlock {
fn default() -> Self {
Self::Deneb(BlindedBeaconBlockDeneb::default())
Self::Electra(BlindedBeaconBlockElectra::default())
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct BlindedBeaconBlockDeneb {
#[serde(with = "serde_utils::quoted_u64")]
pub slot: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub proposer_index: u64,
pub parent_root: B256,
pub state_root: B256,
pub body: BlindedBeaconBlockBodyDeneb<DenebSpec>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct BlindedBeaconBlockElectra {
#[serde(with = "serde_utils::quoted_u64")]
Expand All @@ -84,30 +65,16 @@ pub struct BlindedBeaconBlockElectra {
}

/// Returned by relay in submit_block
pub type SubmitBlindedBlockResponse =
VersionedResponse<PayloadAndBlobsDeneb, PayloadAndBlobsElectra>;
pub type SubmitBlindedBlockResponse = VersionedResponse<PayloadAndBlobsElectra>;

impl SubmitBlindedBlockResponse {
pub fn block_hash(&self) -> B256 {
match self {
VersionedResponse::Deneb(d) => d.block_hash(),
VersionedResponse::Electra(d) => d.block_hash(),
}
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct PayloadAndBlobsDeneb {
pub execution_payload: ExecutionPayload<DenebSpec>,
pub blobs_bundle: BlobsBundle<DenebSpec>,
}

impl PayloadAndBlobsDeneb {
pub fn block_hash(&self) -> B256 {
self.execution_payload.block_hash
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct PayloadAndBlobsElectra {
pub execution_payload: ExecutionPayload<ElectraSpec>,
Expand All @@ -128,23 +95,6 @@ mod tests {
use super::*;
use crate::utils::{test_encode_decode, test_encode_decode_ssz};

#[test]
// this is from the builder api spec, but with sync_committee_bits fixed to
// deserialize correctly
fn test_signed_blinded_block_deneb() {
let data = include_str!("testdata/signed-blinded-beacon-block-deneb-2.json");
let block = test_encode_decode::<SignedBlindedBeaconBlock>(&data);
assert!(matches!(block.message, BlindedBeaconBlock::Deneb(_)));
}

#[test]
// this is from mev-boost test data
fn test_signed_blinded_block_fb_deneb() {
let data = include_str!("testdata/signed-blinded-beacon-block-deneb.json");
let block = test_encode_decode::<SignedBlindedBeaconBlock>(&data);
assert!(matches!(block.message, BlindedBeaconBlock::Deneb(_)));
}

#[test]
// this is from mev-boost test data
fn test_signed_blinded_block_fb_electra() {
Expand All @@ -156,11 +106,11 @@ mod tests {
#[test]
// this is from the builder api spec, but with blobs fixed to deserialize
// correctly
fn test_submit_blinded_block_response_deneb() {
fn test_submit_blinded_block_response_electra() {
let blob = alloy::primitives::hex::encode_prefixed([1; 131072]);

let data = json!({
"version": "deneb",
"version": "electra",
"data": {
"execution_payload": {
"parent_hash":
Expand Down Expand Up @@ -209,7 +159,7 @@ mod tests {
}).to_string();

let block = test_encode_decode::<SubmitBlindedBlockResponse>(&data);
assert!(matches!(block, SubmitBlindedBlockResponse::Deneb(_)));
assert!(matches!(block, SubmitBlindedBlockResponse::Electra(_)));
}

#[test]
Expand All @@ -230,21 +180,10 @@ mod tests {
#[test]
// this is dummy data generated with https://github.com/attestantio/go-builder-client
fn test_execution_payload_block_ssz() {
let data_json = include_str!("testdata/execution-payload-deneb.json");
let block_json = test_encode_decode::<PayloadAndBlobsDeneb>(&data_json);

let data_ssz = include_bytes!("testdata/execution-payload-deneb.ssz");
let data_ssz = alloy::primitives::hex::decode(data_ssz).unwrap();
test_encode_decode_ssz::<PayloadAndBlobsDeneb>(&data_ssz);

assert_eq!(block_json.as_ssz_bytes(), data_ssz);

// electra and deneb have the same execution payload

let data_json = include_str!("testdata/execution-payload-deneb.json");
let data_json = include_str!("testdata/execution-payload-electra.json");
let block_json = test_encode_decode::<PayloadAndBlobsElectra>(&data_json);

let data_ssz = include_bytes!("testdata/execution-payload-deneb.ssz");
let data_ssz = include_bytes!("testdata/execution-payload-electra.ssz");
let data_ssz = alloy::primitives::hex::decode(data_ssz).unwrap();
test_encode_decode_ssz::<PayloadAndBlobsElectra>(&data_ssz);

Expand Down
42 changes: 0 additions & 42 deletions crates/common/src/pbs/types/blinded_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ use super::{
kzg::KzgCommitments, spec::EthSpec, utils::*,
};

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(deny_unknown_fields)]
pub struct BlindedBeaconBlockBodyDeneb<T: EthSpec> {
pub randao_reveal: BlsSignature,
pub eth1_data: Eth1Data,
pub graffiti: B256,
pub proposer_slashings: VariableList<ProposerSlashing, T::MaxProposerSlashings>,
pub attester_slashings: VariableList<AttesterSlashingDeneb<T>, T::MaxAttesterSlashings>,
pub attestations: VariableList<AttestationDeneb<T>, T::MaxAttestations>,
pub deposits: VariableList<Deposit, T::MaxDeposits>,
pub voluntary_exits: VariableList<SignedVoluntaryExit, T::MaxVoluntaryExits>,
pub sync_aggregate: SyncAggregate<T>,
pub execution_payload_header: ExecutionPayloadHeader<T>,
pub bls_to_execution_changes:
VariableList<SignedBlsToExecutionChange, T::MaxBlsToExecutionChanges>,
pub blob_kzg_commitments: KzgCommitments<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(deny_unknown_fields)]
pub struct BlindedBeaconBlockBodyElectra<T: EthSpec> {
Expand Down Expand Up @@ -93,28 +75,12 @@ pub struct ProposerSlashing {
pub signed_header_2: SignedBeaconBlockHeader,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct AttesterSlashingDeneb<T: EthSpec> {
pub attestation_1: IndexedAttestationDeneb<T>,
pub attestation_2: IndexedAttestationDeneb<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
pub struct AttesterSlashingElectra<T: EthSpec> {
pub attestation_1: IndexedAttestationElectra<T>,
pub attestation_2: IndexedAttestationElectra<T>,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct IndexedAttestationDeneb<T: EthSpec> {
/// Lists validator registry indices, not committee indices.
#[serde(with = "quoted_variable_list_u64")]
pub attesting_indices: VariableList<u64, T::MaxValidatorsPerCommittee>,
pub data: AttestationData,
pub signature: BlsSignature,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct IndexedAttestationElectra<T: EthSpec> {
Expand Down Expand Up @@ -145,14 +111,6 @@ pub struct Checkpoint {
pub root: B256,
}

#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct AttestationDeneb<T: EthSpec> {
pub aggregation_bits: BitList<T::MaxValidatorsPerCommittee>,
pub data: AttestationData,
pub signature: BlsSignature,
}

#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
#[serde(bound = "T: EthSpec")]
pub struct AttestationElectra<T: EthSpec> {
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/pbs/types/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ mod tests {

use super::*;
use crate::{
pbs::types::{execution_payload::Transactions, spec::DenebSpec},
pbs::{types::execution_payload::Transactions, ElectraSpec},
utils::test_encode_decode,
};

#[test]
fn test_empty_tx_root_hash() {
let txs: Transactions<DenebSpec> = VariableList::empty();
let txs: Transactions<ElectraSpec> = VariableList::empty();
let txs_root = txs.tree_hash_root();

assert_eq!(txs_root, EMPTY_TX_ROOT_HASH);
Expand Down Expand Up @@ -129,7 +129,7 @@ mod tests {
"excess_blob_gas": "95158272"
}"#;

let parsed = test_encode_decode::<ExecutionPayloadHeader<DenebSpec>>(&data);
let parsed = test_encode_decode::<ExecutionPayloadHeader<ElectraSpec>>(&data);

assert_eq!(
parsed.parent_hash,
Expand Down
Loading
Loading