Skip to content

Commit

Permalink
feat: pectra (#183)
Browse files Browse the repository at this point in the history
## 📝 Summary

Support for the upcoming Pectra hardfork. Depends on
alloy-rs/alloy#1303
  • Loading branch information
rkrasiuk authored Sep 30, 2024
1 parent 66756ad commit c886cf1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
19 changes: 9 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ alloy-rpc-types-engine = { version = "0.3.0", features = [
"ssz",
] }
alloy-rpc-types-eth = { version = "0.3.0" }
alloy-signer-local = { version = "0.3.0" }
alloy-signer-local = { version = "0.3.0" }
34 changes: 28 additions & 6 deletions crates/rbuilder/src/building/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ use reth_basic_payload_builder::{commit_withdrawals, WithdrawalsOutcome};
use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_errors::ProviderError;
use reth_evm::system_calls::{
post_block_withdrawal_requests_contract_call, pre_block_beacon_root_contract_call,
post_block_consolidation_requests_contract_call, post_block_withdrawal_requests_contract_call,
pre_block_beacon_root_contract_call, pre_block_blockhashes_contract_call,
};
use reth_evm_ethereum::{eip6110::parse_deposits_from_receipts, revm_spec, EthEvmConfig};
use reth_node_api::PayloadBuilderAttributes;
Expand Down Expand Up @@ -581,18 +582,30 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
.chain_spec
.is_prague_active_at_timestamp(ctx.attributes.timestamp())
{
let deposit_requests =
parse_deposits_from_receipts(&ctx.chain_spec, self.receipts.iter())?;
let evm_config = EthEvmConfig::default();
let mut db = state.new_db_ref();

let deposit_requests =
parse_deposits_from_receipts(&ctx.chain_spec, self.receipts.iter())?;
let withdrawal_requests = post_block_withdrawal_requests_contract_call(
&EthEvmConfig::default(),
&evm_config,
db.as_mut(),
&ctx.initialized_cfg,
&ctx.block_env,
)?;
let consolidation_requests = post_block_consolidation_requests_contract_call(
&evm_config,
db.as_mut(),
&ctx.initialized_cfg,
&ctx.block_env,
)?;

let requests = [deposit_requests, withdrawal_requests].concat();
let requests = [
deposit_requests,
withdrawal_requests,
consolidation_requests,
]
.concat();
let requests_root = calculate_requests_root(&requests);
(Some(requests.into()), Some(requests_root))
} else {
Expand Down Expand Up @@ -706,15 +719,24 @@ impl<Tracer: SimulationTracer> PartialBlock<Tracer> {
ctx: &BlockBuildingContext,
state: &mut BlockState,
) -> eyre::Result<()> {
let evm_config = EthEvmConfig::default();
let mut db = state.new_db_ref();
pre_block_beacon_root_contract_call(
db.as_mut(),
&EthEvmConfig::default(),
&evm_config,
&ctx.chain_spec,
&ctx.initialized_cfg,
&ctx.block_env,
ctx.attributes.parent_beacon_block_root(),
)?;
pre_block_blockhashes_contract_call(
db.as_mut(),
&evm_config,
&ctx.chain_spec,
&ctx.initialized_cfg,
&ctx.block_env,
ctx.attributes.parent,
)?;
db.as_mut().merge_transitions(BundleRetention::Reverts);
Ok(())
}
Expand Down
10 changes: 9 additions & 1 deletion crates/rbuilder/src/mev_boost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pub mod sign_payload;
use super::utils::u256decimal_serde_helper;

use alloy_primitives::{Address, BlockHash, Bytes, U256};
use alloy_rpc_types_beacon::relay::{BidTrace, SignedBidSubmissionV2, SignedBidSubmissionV3};
use alloy_rpc_types_beacon::relay::{
BidTrace, SignedBidSubmissionV2, SignedBidSubmissionV3, SignedBidSubmissionV4,
};
use flate2::{write::GzEncoder, Compression};
use primitive_types::H384;
use reqwest::{
Expand Down Expand Up @@ -455,6 +457,7 @@ impl RelayClient {
match data {
SubmitBlockRequest::Capella(data) => data.0.as_ssz_bytes(),
SubmitBlockRequest::Deneb(data) => data.0.as_ssz_bytes(),
SubmitBlockRequest::Electra(data) => data.0.as_ssz_bytes(),
},
SSZ_CONTENT_TYPE,
)
Expand Down Expand Up @@ -582,6 +585,9 @@ impl RelayClient {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ElectraSubmitBlockRequest(SignedBidSubmissionV4);

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DenebSubmitBlockRequest(SignedBidSubmissionV3);

Expand All @@ -599,13 +605,15 @@ pub struct CapellaSubmitBlockRequest(SignedBidSubmissionV2);
pub enum SubmitBlockRequest {
Capella(CapellaSubmitBlockRequest),
Deneb(DenebSubmitBlockRequest),
Electra(ElectraSubmitBlockRequest),
}

impl SubmitBlockRequest {
pub fn bid_trace(&self) -> BidTrace {
match self {
SubmitBlockRequest::Capella(req) => req.0.message.clone(),
SubmitBlockRequest::Deneb(req) => req.0.message.clone(),
SubmitBlockRequest::Electra(req) => req.0.message.clone(),
}
}
}
Expand Down
54 changes: 45 additions & 9 deletions crates/rbuilder/src/mev_boost/sign_payload.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use super::{CapellaSubmitBlockRequest, DenebSubmitBlockRequest, SubmitBlockRequest};
use super::{
CapellaSubmitBlockRequest, DenebSubmitBlockRequest, ElectraSubmitBlockRequest,
SubmitBlockRequest,
};
use crate::utils::u256decimal_serde_helper;
use alloy_primitives::{Address, BlockHash, FixedBytes, B256, U256};
use alloy_rpc_types_beacon::{
relay::{BidTrace, SignedBidSubmissionV2, SignedBidSubmissionV3},
relay::{BidTrace, SignedBidSubmissionV2, SignedBidSubmissionV3, SignedBidSubmissionV4},
BlsPublicKey,
};
use alloy_rpc_types_engine::{
BlobsBundleV1, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
BlobsBundleV1, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, ExecutionPayloadV4,
};
use alloy_rpc_types_eth::Withdrawal;
use ethereum_consensus::{
Expand Down Expand Up @@ -178,12 +181,45 @@ pub fn sign_block_for_relay(

let blobs_bundle = marshal_txs_blobs_sidecars(blobs_bundle);

SubmitBlockRequest::Deneb(DenebSubmitBlockRequest(SignedBidSubmissionV3 {
message,
execution_payload,
blobs_bundle: blobs_bundle.clone(),
signature,
}))
if chain_spec.is_prague_active_at_timestamp(sealed_block.timestamp) {
let mut deposit_requests = Vec::new();
let mut withdrawal_requests = Vec::new();
let mut consolidation_requests = Vec::new();
for request in sealed_block.requests.iter().flat_map(|r| &r.0) {
match request {
alloy_consensus::Request::DepositRequest(r) => {
deposit_requests.push(*r);
}
alloy_consensus::Request::WithdrawalRequest(r) => {
withdrawal_requests.push(*r);
}
alloy_consensus::Request::ConsolidationRequest(r) => {
consolidation_requests.push(*r);
}
_ => {}
};
}

let execution_payload = ExecutionPayloadV4 {
payload_inner: execution_payload,
deposit_requests,
withdrawal_requests,
consolidation_requests,
};
SubmitBlockRequest::Electra(ElectraSubmitBlockRequest(SignedBidSubmissionV4 {
message,
execution_payload,
blobs_bundle,
signature,
}))
} else {
SubmitBlockRequest::Deneb(DenebSubmitBlockRequest(SignedBidSubmissionV3 {
message,
execution_payload,
blobs_bundle,
signature,
}))
}
} else {
let execution_payload = capella_payload;
SubmitBlockRequest::Capella(CapellaSubmitBlockRequest(SignedBidSubmissionV2 {
Expand Down
1 change: 1 addition & 0 deletions crates/rbuilder/src/validation_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl ValidationAPIClient {
let method = match req {
SubmitBlockRequest::Capella(_) => "flashbots_validateBuilderSubmissionV2",
SubmitBlockRequest::Deneb(_) => "flashbots_validateBuilderSubmissionV3",
SubmitBlockRequest::Electra(_) => "flashbots_validateBuilderSubmissionV4",
};
let request = ValidRequest {
req: req.clone(),
Expand Down

0 comments on commit c886cf1

Please sign in to comment.