Skip to content

Commit

Permalink
finish mapping reth payload to execution payload for block submission
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed May 14, 2024
1 parent c32c4e1 commit 313d06a
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion mev-build-rs/src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::Error;
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
electra::{DepositReceipt, ExecutionLayerWithdrawalRequest},
primitives::{Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256},
Fork,
};
use mev_rs::types::{BlobsBundle, ExecutionPayload};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, SealedBlock, B256};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, Request, SealedBlock, B256};

#[cfg(not(feature = "minimal-preset"))]
use ethereum_consensus::{deneb::mainnet as deneb, electra::mainnet as electra};
Expand All @@ -30,6 +31,7 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
let header = &value.header;
let transactions = &value.body;
let withdrawals = &value.withdrawals;
let requests = &value.requests;
match fork {
Fork::Deneb => {
let transactions = transactions
Expand Down Expand Up @@ -85,6 +87,30 @@ pub fn to_execution_payload(value: &SealedBlock, fork: Fork) -> Result<Execution
amount: w.amount,
})
.collect::<Vec<_>>();
let mut deposit_receipts = vec![];
let mut withdrawal_requests = vec![];
for request in requests.as_ref().unwrap() {
match request {
Request::DepositRequest(deposit) => {
let deposit_receipt = DepositReceipt {
public_key: deposit.pubkey,
withdrawal_credentials: deposit.withdrawal_credentials,
amount: deposit.amount,
signature: deposit.signature,
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,
amount: withdrawal.amount,
};
withdrawal_requests.push(withdrawal_request);
}
}
}
let payload = electra::ExecutionPayload {
parent_hash: to_bytes32(header.parent_hash),
fee_recipient: to_bytes20(header.beneficiary),
Expand All @@ -103,6 +129,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,
};
Ok(ExecutionPayload::Electra(payload))
}
Expand Down

0 comments on commit 313d06a

Please sign in to comment.