Skip to content

Commit

Permalink
reth electra payload support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed May 14, 2024
1 parent 942f0cd commit a9ac358
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
23 changes: 14 additions & 9 deletions mev-build-rs/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::Error;
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
electra::{DepositReceipt, ExecutionLayerWithdrawalRequest},
primitives::{Bytes32, ExecutionAddress},
primitives::{BlsPublicKey, BlsSignature, Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256},
Fork,
};
Expand Down Expand Up @@ -89,26 +89,31 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
.collect::<Vec<_>>();
let mut deposit_receipts = vec![];
let mut withdrawal_requests = vec![];
for request in requests.as_ref().unwrap() {
let requests = requests.unwrap();
for request in requests {
match request {
Request::DepositRequest(deposit) => {
let deposit_receipt = DepositReceipt {
public_key: deposit.pubkey,
withdrawal_credentials: deposit.withdrawal_credentials,
public_key: BlsPublicKey::try_from(deposit.pubkey.as_ref()).unwrap(),
withdrawal_credentials: to_bytes32(deposit.withdrawal_credentials),
amount: deposit.amount,
signature: deposit.signature,
signature: BlsSignature::try_from(deposit.signature.as_ref()).unwrap(),
index: deposit.index,
};
deposit_receipts.push(deposit_receipt);
}
Request::WithdrawalRequest(withdrawal) => {
let withdrawal_request = ExecutionLayerWithdrawalRequest {
source_address: withdrawal.source_address,
validator_public_key: withdrawal.validator_public_key,
source_address: to_bytes20(withdrawal.source_address),
validator_public_key: BlsPublicKey::try_from(
withdrawal.validator_public_key.as_ref(),
)
.unwrap(),
amount: withdrawal.amount,
};
withdrawal_requests.push(withdrawal_request);
}
_ => unreachable!("struct is non-exhaustive, but all variants are matched"),
}
}
let payload = electra::ExecutionPayload {
Expand All @@ -129,8 +134,8 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
withdrawals: TryFrom::try_from(withdrawals).unwrap(),
blob_gas_used: header.blob_gas_used.unwrap(),
excess_blob_gas: header.excess_blob_gas.unwrap(),
deposit_receipts,
withdrawal_requests,
deposit_receipts: TryFrom::try_from(deposit_receipts).unwrap(),
withdrawal_requests: TryFrom::try_from(withdrawal_requests).unwrap(),
};
Ok(ExecutionPayload::Electra(payload))
}
Expand Down
3 changes: 2 additions & 1 deletion mev-build-rs/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth::{
primitives::ChainSpec,
rpc::types::{
engine::{
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3,
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4,
PayloadAttributes as EthPayloadAttributes,
},
ExecutionPayloadV1,
Expand Down Expand Up @@ -64,6 +64,7 @@ impl EngineTypes for BuilderEngineTypes {
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadV4 = ExecutionPayloadEnvelopeV4;

fn validate_version_specific_fields(
chain_spec: &ChainSpec,
Expand Down
4 changes: 2 additions & 2 deletions mev-build-rs/src/payload/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn append_payment<Client: StateProviderFactory>(
drop(evm);
db.commit(state);

let Block { mut header, mut body, ommers, withdrawals } = block.unseal();
let Block { mut header, mut body, ommers, withdrawals, requests } = block.unseal();

// Verify we reserved the correct amount of gas for the payment transaction
let gas_limit = header.gas_limit + result.gas_used();
Expand Down Expand Up @@ -181,7 +181,7 @@ fn append_payment<Client: StateProviderFactory>(
header.gas_used = cumulative_gas_used;
header.gas_limit = gas_limit;

let block = Block { header, body, ommers, withdrawals };
let block = Block { header, body, ommers, withdrawals, requests };

Ok(block.seal_slow())
}
Expand Down

0 comments on commit a9ac358

Please sign in to comment.