Skip to content

Commit

Permalink
move some stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 4, 2023
1 parent ec97338 commit 2dcab8e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 40 deletions.
2 changes: 2 additions & 0 deletions crates/rpc/rpc-types/src/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use alloy_primitives::FixedBytes;
use constants::{BLS_PUBLIC_KEY_BYTES_LEN, BLS_SIGNATURE_BYTES_LEN};

pub mod constants;
/// Beacon API events support.
pub mod events;
pub mod payload;
pub mod withdrawals;

Expand Down
60 changes: 30 additions & 30 deletions crates/rpc/rpc-types/src/beacon/payload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(missing_docs, private_interfaces)]
#![allow(missing_docs)]
//! Payload support for the beacon API.
//!
//! Internal helper module to deserialize/serialize the payload attributes for the beacon API, which
Expand All @@ -9,10 +9,9 @@
//!
//! See also <https://github.com/ethereum/consensus-specs/blob/master/specs/deneb/beacon-chain.md#executionpayload>

pub use crate::Withdrawal;
use crate::{
beacon::withdrawals::BeaconWithdrawal, engine::ExecutionPayloadV3, ExecutionPayload,
ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV1, ExecutionPayloadV2, Withdrawal,
};
use alloy_primitives::{Address, Bloom, Bytes, B256, U256, U64};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand All @@ -35,8 +34,8 @@ struct BeaconPayloadAttributes {

/// A helper module for serializing and deserializing the payload attributes for the beacon API.
///
/// The beacon API encoded object has equivalent fields to the [PayloadAttributes] with two
/// differences:
/// The beacon API encoded object has equivalent fields to the
/// [PayloadAttributes](crate::engine::PayloadAttributes) with two differences:
/// 1) `snake_case` identifiers must be used rather than `camelCase`;
/// 2) integers must be encoded as quoted decimals rather than big-endian hex.
pub mod beacon_api_payload_attributes {
Expand Down Expand Up @@ -80,25 +79,26 @@ pub mod beacon_api_payload_attributes {

#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct BeaconExecutionPayloadV1<'a> {
pub(crate) parent_hash: Cow<'a, B256>,
pub(crate) fee_recipient: Cow<'a, Address>,
pub(crate) state_root: Cow<'a, B256>,
pub(crate) receipts_root: Cow<'a, B256>,
pub(crate) logs_bloom: Cow<'a, Bloom>,
pub(crate) prev_randao: Cow<'a, B256>,
struct BeaconExecutionPayloadV1<'a> {
parent_hash: Cow<'a, B256>,
fee_recipient: Cow<'a, Address>,
state_root: Cow<'a, B256>,
receipts_root: Cow<'a, B256>,
logs_bloom: Cow<'a, Bloom>,
prev_randao: Cow<'a, B256>,
#[serde_as(as = "DisplayFromStr")]
pub(crate) block_number: u64,
block_number: u64,
#[serde_as(as = "DisplayFromStr")]
pub(crate) gas_limit: u64,
gas_limit: u64,
#[serde_as(as = "DisplayFromStr")]
pub(crate) gas_used: u64,
gas_used: u64,
#[serde_as(as = "DisplayFromStr")]
pub(crate) timestamp: u64,
pub(crate) extra_data: Cow<'a, Bytes>,
pub(crate) base_fee_per_gas: Cow<'a, U256>,
pub(crate) block_hash: Cow<'a, B256>,
pub(crate) transactions: Cow<'a, Vec<Bytes>>,
timestamp: u64,
extra_data: Cow<'a, Bytes>,
#[serde_as(as = "DisplayFromStr")]
base_fee_per_gas: U256,
block_hash: Cow<'a, B256>,
transactions: Cow<'a, Vec<Bytes>>,
}

impl<'a> From<BeaconExecutionPayloadV1<'a>> for ExecutionPayloadV1 {
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<'a> From<BeaconExecutionPayloadV1<'a>> for ExecutionPayloadV1 {
gas_used: U64::from(gas_used),
timestamp: U64::from(timestamp),
extra_data: extra_data.into_owned(),
base_fee_per_gas: base_fee_per_gas.into_owned(),
base_fee_per_gas,
block_hash: block_hash.into_owned(),
transactions: transactions.into_owned(),
}
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'a> From<&'a ExecutionPayloadV1> for BeaconExecutionPayloadV1<'a> {
gas_used: gas_used.to(),
timestamp: timestamp.to(),
extra_data: Cow::Borrowed(extra_data),
base_fee_per_gas: Cow::Borrowed(base_fee_per_gas),
base_fee_per_gas: *base_fee_per_gas,
block_hash: Cow::Borrowed(block_hash),
transactions: Cow::Borrowed(transactions),
}
Expand Down Expand Up @@ -204,14 +204,14 @@ pub mod beacon_payload_v1 {

#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct BeaconExecutionPayloadV2<'a> {
struct BeaconExecutionPayloadV2<'a> {
/// Inner V1 payload
#[serde(flatten)]
pub(crate) payload_inner: BeaconExecutionPayloadV1<'a>,
payload_inner: BeaconExecutionPayloadV1<'a>,
/// Array of [`Withdrawal`] enabled with V2
/// See <https://github.com/ethereum/execution-apis/blob/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine/shanghai.md#executionpayloadv2>
#[serde_as(as = "Vec<BeaconWithdrawal>")]
pub(crate) withdrawals: Vec<Withdrawal>,
withdrawals: Vec<Withdrawal>,
}

impl<'a> From<BeaconExecutionPayloadV2<'a>> for ExecutionPayloadV2 {
Expand Down Expand Up @@ -259,18 +259,18 @@ pub mod beacon_payload_v2 {

#[serde_as]
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct BeaconExecutionPayloadV3<'a> {
struct BeaconExecutionPayloadV3<'a> {
/// Inner V1 payload
#[serde(flatten)]
pub(crate) payload_inner: BeaconExecutionPayloadV2<'a>,
payload_inner: BeaconExecutionPayloadV2<'a>,
/// Array of [`U64`] representing blob gas used, enabled with V3
/// See <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#ExecutionPayloadV3>
#[serde_as(as = "DisplayFromStr")]
pub(crate) blob_gas_used: u64,
blob_gas_used: u64,
/// Array of [`U64`] representing excess blob gas, enabled with V3
/// See <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#ExecutionPayloadV3>
#[serde_as(as = "DisplayFromStr")]
pub(crate) excess_blob_gas: u64,
excess_blob_gas: u64,
}

impl<'a> From<BeaconExecutionPayloadV3<'a>> for ExecutionPayloadV3 {
Expand Down Expand Up @@ -324,7 +324,7 @@ pub mod beacon_payload_v3 {
/// Represents all possible payload versions.
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum BeaconExecutionPayload<'a> {
enum BeaconExecutionPayload<'a> {
/// V1 payload
V1(BeaconExecutionPayloadV1<'a>),
/// V2 payload
Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc-types/src/eth/engine/beacon_api/mod.rs

This file was deleted.

6 changes: 1 addition & 5 deletions crates/rpc/rpc-types/src/eth/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
//! Engine API types: <https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md> and <https://eips.ethereum.org/EIPS/eip-3675> following the execution specs <https://github.com/ethereum/execution-apis/tree/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine>

#![allow(missing_docs)]
//! Engine API types: <https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md> and <https://eips.ethereum.org/EIPS/eip-3675> following the execution specs <https://github.com/ethereum/execution-apis/tree/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine>

mod cancun;
mod forkchoice;
pub mod payload;
mod transition;
pub use self::{cancun::*, forkchoice::*, payload::*, transition::*};

/// Beacon API types
pub mod beacon_api;

/// The list of all supported Engine capabilities available over the engine endpoint.
pub const CAPABILITIES: [&str; 12] = [
"engine_forkchoiceUpdatedV1",
Expand Down
7 changes: 5 additions & 2 deletions crates/rpc/rpc-types/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct BidTrace {
pub gas_limit: u64,
#[serde_as(as = "DisplayFromStr")]
pub gas_used: u64,
#[serde_as(as = "DisplayFromStr")]
pub value: U256,
}

Expand Down Expand Up @@ -89,8 +90,10 @@ mod tests {

#[test]
fn deneb_bid_submission() {
let s = r#"{"message":{"slot":"1","parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","builder_pubkey":"0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a", "proposer_pubkey": "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a","proposer_fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","gas_limit":"1","gas_used":"1","value":"1"},"execution_payload":{"parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","state_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","receipts_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_number":"1","gas_limit":"1","gas_used":"1","timestamp":"1","extra_data":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","base_fee_per_gas":"1","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","transactions":["0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86"],"withdrawals":[{"index":"1","validator_index":"1","address":"0xabcf8e0d4e9587369b2301d0790347320302cc09","amount":"32000000000"}]},"blobs_bundle":{"commitments":["0x8dab030c51e16e84be9caab84ee3d0b8bbec1db4a0e4de76439da8424d9b957370a10a78851f97e4b54d2ce1ab0d686f"],"proofs":["0xb4021b0de10f743893d4f71e1bf830c019e832958efd6795baf2f83b8699a9eccc5dc99015d8d4d8ec370d0cc333c06a"],"blobs":["0x24564723180fcb3d994104538d351c8dcbde12d541676bb736cf678018ca4739"]},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}"#;
let s = r#"{"message":{"slot":"1","parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","builder_pubkey":"0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a", "proposer_pubkey": "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a","proposer_fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","gas_limit":"1","gas_used":"1","value":"1"},"execution_payload":{"parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","state_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","receipts_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_number":"1","gas_limit":"1","gas_used":"1","timestamp":"1","extra_data":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","base_fee_per_gas":"1","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","transactions":["0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86"],"withdrawals":[{"index":"1","validator_index":"1","address":"0xabcf8e0d4e9587369b2301d0790347320302cc09","amount":"32000000000"}]},"blobs_bundle":{"commitments":[],"proofs":[],"blobs":[]},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}"#;

let _bid = serde_json::from_str::<SignedBidSubmission>(s).unwrap();
let bid = serde_json::from_str::<SignedBidSubmission>(s).unwrap();
let json: serde_json::Value = serde_json::from_str(s).unwrap();
assert_eq!(json, serde_json::to_value(bid).unwrap());
}
}
2 changes: 1 addition & 1 deletion examples/beacon-api-sse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use reth::{
ext::{RethCliExt, RethNodeCommandConfig},
Cli,
},
rpc::types::engine::beacon_api::events::PayloadAttributesEvent,
rpc::types::beacon::events::PayloadAttributesEvent,
tasks::TaskSpawner,
};
use std::net::{IpAddr, Ipv4Addr};
Expand Down

0 comments on commit 2dcab8e

Please sign in to comment.