Skip to content

Commit

Permalink
chore: flatten eip-7685 requests into a single list
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Sep 26, 2024
1 parent bb7c040 commit 882bb2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 57 deletions.
1 change: 1 addition & 0 deletions crates/rpc-types-beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ workspace = true

[dependencies]
# ethereum
alloy-consensus = { workspace = true, features = ["serde"] }
alloy-eips = { workspace = true, features = ["serde"] }
alloy-rpc-types-engine = { workspace = true, features = ["serde"] }
alloy-primitives.workspace = true
Expand Down
33 changes: 6 additions & 27 deletions crates/rpc-types-beacon/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! See also <https://github.com/ethereum/consensus-specs/blob/master/specs/deneb/beacon-chain.md#executionpayload>

use crate::{withdrawals::BeaconWithdrawal, BlsPublicKey};
use alloy_consensus::Requests;
use alloy_eips::{
eip4895::Withdrawal, eip6110::DepositRequest, eip7002::WithdrawalRequest,
eip7251::ConsolidationRequest,
Expand Down Expand Up @@ -412,42 +413,20 @@ struct BeaconExecutionPayloadV4<'a> {
/// Inner V1 payload
#[serde(flatten)]
payload_inner: BeaconExecutionPayloadV3<'a>,
deposit_requests: Vec<DepositRequest>,
withdrawal_requests: Vec<WithdrawalRequest>,
consolidation_requests: Vec<ConsolidationRequest>,
requests: Requests,
}

impl<'a> From<BeaconExecutionPayloadV4<'a>> for ExecutionPayloadV4 {
fn from(payload: BeaconExecutionPayloadV4<'a>) -> Self {
let BeaconExecutionPayloadV4 {
payload_inner,
deposit_requests,
withdrawal_requests,
consolidation_requests,
} = payload;
Self {
payload_inner: payload_inner.into(),
deposit_requests,
withdrawal_requests,
consolidation_requests,
}
let BeaconExecutionPayloadV4 { payload_inner, requests } = payload;
Self { payload_inner: payload_inner.into(), requests }
}
}

impl<'a> From<&'a ExecutionPayloadV4> for BeaconExecutionPayloadV4<'a> {
fn from(value: &'a ExecutionPayloadV4) -> Self {
let ExecutionPayloadV4 {
payload_inner,
deposit_requests,
withdrawal_requests,
consolidation_requests,
} = value;
BeaconExecutionPayloadV4 {
payload_inner: payload_inner.into(),
deposit_requests: deposit_requests.clone(),
withdrawal_requests: withdrawal_requests.clone(),
consolidation_requests: consolidation_requests.clone(),
}
let ExecutionPayloadV4 { payload_inner, requests } = value;
BeaconExecutionPayloadV4 { payload_inner: payload_inner.into(), requests: requests.clone() }
}
}

Expand Down
40 changes: 10 additions & 30 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::{
string::{String, ToString},
vec::Vec,
};
use alloy_consensus::{Blob, Bytes48};
use alloy_consensus::{Blob, Bytes48, Requests};
use alloy_eips::{
eip4844::BlobTransactionSidecar, eip4895::Withdrawal, eip6110::DepositRequest,
eip7002::WithdrawalRequest, eip7251::ConsolidationRequest, BlockNumHash,
Expand Down Expand Up @@ -460,15 +460,8 @@ pub struct ExecutionPayloadV4 {
/// Array of deposit requests.
///
/// This maps directly to the deposit requests defined in [EIP-6110](https://eips.ethereum.org/EIPS/eip-6110).
pub deposit_requests: Vec<DepositRequest>,
/// Array of execution layer triggerable withdrawal requests.
///
/// See [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002).
pub withdrawal_requests: Vec<WithdrawalRequest>,
/// Array of consolidation requests.
///
/// See [EIP-7251](https://eips.ethereum.org/EIPS/eip-7251).
pub consolidation_requests: Vec<ConsolidationRequest>,
// todo
pub requests: Requests,
}

impl ExecutionPayloadV4 {
Expand Down Expand Up @@ -539,9 +532,7 @@ impl ssz::Decode for ExecutionPayloadV4 {
blob_gas_used: decoder.decode_next()?,
excess_blob_gas: decoder.decode_next()?,
},
deposit_requests: decoder.decode_next()?,
withdrawal_requests: decoder.decode_next()?,
consolidation_requests: decoder.decode_next()?,
requests: decoder.decode_next()?,
})
}
}
Expand Down Expand Up @@ -579,19 +570,15 @@ impl ssz::Encode for ExecutionPayloadV4 {
encoder.append(&self.payload_inner.payload_inner.withdrawals);
encoder.append(&self.payload_inner.blob_gas_used);
encoder.append(&self.payload_inner.excess_blob_gas);
encoder.append(&self.deposit_requests);
encoder.append(&self.withdrawal_requests);
encoder.append(&self.consolidation_requests);
encoder.append(&self.requests);

encoder.finalize();
}

fn ssz_bytes_len(&self) -> usize {
<ExecutionPayloadV3 as ssz::Encode>::ssz_bytes_len(&self.payload_inner)
+ ssz::BYTES_PER_LENGTH_OFFSET * 3
+ self.deposit_requests.ssz_bytes_len()
+ self.withdrawal_requests.ssz_bytes_len()
+ self.consolidation_requests.ssz_bytes_len()
+ self.requests.ssz_bytes_len()
}
}

Expand Down Expand Up @@ -1020,8 +1007,8 @@ pub struct ExecutionPayloadBodyV1 {
pub withdrawals: Option<Vec<Withdrawal>>,
}

/// This structure has the syntax of [`ExecutionPayloadBodyV1`] and appends the new fields:
/// depositRequests and withdrawalRequests.
// todo update
/// This structure has the syntax of [`ExecutionPayloadBodyV1`] and appends the new fields: requests.
///
/// See also: <https://github.com/ethereum/execution-apis/blob/3ae3d29fc9900e5c48924c238dff7643fdc3680e/src/engine/prague.md#executionpayloadbodyv2>
#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -1034,18 +1021,11 @@ pub struct ExecutionPayloadBodyV2 {
///
/// Will always be `None` if pre shanghai.
pub withdrawals: Option<Vec<Withdrawal>>,
// todo update
/// Array of deposits requests.
///
/// Will always be `None` if pre prague.
pub deposit_requests: Option<Vec<DepositRequest>>,
/// Array of withdrawal requests.
///
/// Will always be `None` if pre prague.
pub withdrawal_requests: Option<Vec<WithdrawalRequest>>,
/// Array of consolidation requests.
///
/// Will always be `None` if pre prague.
pub consolidation_requests: Option<Vec<ConsolidationRequest>>,
pub requests: Option<Requests>,
}

/// This structure contains the attributes required to initiate a payload build process in the
Expand Down

0 comments on commit 882bb2f

Please sign in to comment.