Skip to content

Commit

Permalink
feat: remove all reth types
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Jan 29, 2025
1 parent c8e04c3 commit ab429ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
28 changes: 13 additions & 15 deletions bolt-sidecar/src/builder/compat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy::{
consensus::{transaction::PooledTransaction, BlockHeader},
consensus::{transaction::PooledTransaction, Block, BlockHeader},
eips::{eip2718::Encodable2718, eip4895::Withdrawal},
primitives::{Address, Bloom, B256, U256},
rpc::types::Withdrawals,
Expand All @@ -20,12 +20,10 @@ use ethereum_consensus::{
types::mainnet::ExecutionPayload as ConsensusExecutionPayload,
};

use super::SealedAlloyBlock;

/// Compatibility: convert a sealed header into an ethereum-consensus execution payload header.
/// This requires recalculating the withdrals and transactions roots as SSZ instead of MPT roots.
pub(crate) fn to_execution_payload_header(
sealed_block: &SealedAlloyBlock,
sealed_block: &Block<PooledTransaction>,
transactions: Vec<PooledTransaction>,
) -> ConsensusExecutionPayloadHeader {
// Transactions and withdrawals are treated as opaque byte arrays in consensus types
Expand All @@ -42,15 +40,15 @@ pub(crate) fn to_execution_payload_header(
let mut withdrawals_ssz: List<ConsensusWithdrawal, MAX_WITHDRAWALS_PER_PAYLOAD> =
List::default();

if let Some(withdrawals) = sealed_block.body().withdrawals.as_ref() {
if let Some(withdrawals) = sealed_block.body.withdrawals.as_ref() {
for w in withdrawals {
withdrawals_ssz.push(to_consensus_withdrawal(w));
}
}

let withdrawals_root = withdrawals_ssz.hash_tree_root().expect("valid withdrawals root");

let header = sealed_block.header();
let header = &sealed_block.header;

ConsensusExecutionPayloadHeader {
parent_hash: to_bytes32(header.parent_hash),
Expand All @@ -75,14 +73,14 @@ pub(crate) fn to_execution_payload_header(

/// Compatibility: convert a sealed block into an Alloy execution payload
pub(crate) fn to_alloy_execution_payload(
block: &SealedAlloyBlock,
block: &Block<PooledTransaction>,
block_hash: B256,
) -> ExecutionPayloadV3 {
let alloy_withdrawals =
block.body().withdrawals.clone().map(|w| w.into_inner()).unwrap_or_default();
block.body.withdrawals.clone().map(|w| w.into_inner()).unwrap_or_default();

let transactions = block
.body()
.body
.transactions
.iter()
.map(|tx| tx.encoded_2718())
Expand All @@ -99,7 +97,7 @@ pub(crate) fn to_alloy_execution_payload(
base_fee_per_gas: U256::from(block.base_fee_per_gas.unwrap_or_default()),
block_number: block.number,
extra_data: block.extra_data.clone(),
fee_recipient: block.header().beneficiary,
fee_recipient: block.header.beneficiary,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
logs_bloom: block.logs_bloom,
Expand All @@ -116,12 +114,12 @@ pub(crate) fn to_alloy_execution_payload(

/// Compatibility: convert a sealed block into an ethereum-consensus execution payload
pub(crate) fn to_consensus_execution_payload(
value: &SealedAlloyBlock,
value: &Block<PooledTransaction>,
) -> ConsensusExecutionPayload {
let hash = value.hash();
let header = value.header();
let transactions = &value.body().transactions;
let withdrawals = &value.body().withdrawals;
let hash = value.hash_slow();
let header = &value.header;
let transactions = &value.body.transactions;
let withdrawals = &value.body.withdrawals;
let transactions = transactions
.iter()
.map(|t| spec::Transaction::try_from(t.encoded_2718().as_ref()).unwrap())
Expand Down
21 changes: 9 additions & 12 deletions bolt-sidecar/src/builder/fallback/engine_hinter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::ops::Deref;

use alloy::{
consensus::{transaction::PooledTransaction, Header, EMPTY_OMMER_ROOT_HASH},
consensus::{transaction::PooledTransaction, Block, BlockBody, Header, EMPTY_OMMER_ROOT_HASH},
primitives::{Address, Bloom, Bytes, B256, B64, U256},
rpc::types::{Block, Withdrawal, Withdrawals},
rpc::types::{Block as RpcBlock, Withdrawal, Withdrawals},
};
use alloy_provider::ext::EngineApi;
use alloy_rpc_types_engine::{ClientCode, ExecutionPayloadV3, JwtSecret, PayloadStatusEnum};
use reqwest::Url;
use reth_primitives::{BlockBody, SealedBlock, SealedHeader};
use tracing::{debug, error};

use crate::{
builder::{compat::to_alloy_execution_payload, BuilderError, SealedAlloyBlock},
builder::{compat::to_alloy_execution_payload, BuilderError},
client::EngineClient,
};

Expand Down Expand Up @@ -52,7 +51,7 @@ impl EngineHinter {
pub async fn fetch_payload_from_hints(
&self,
mut ctx: EngineHinterContext,
) -> Result<SealedAlloyBlock, BuilderError> {
) -> Result<Block<PooledTransaction>, BuilderError> {
// The block body can be the same for all iterations, since it only contains
// the transactions and withdrawals from the context.
let body = ctx.build_block_body();
Expand All @@ -66,20 +65,18 @@ impl EngineHinter {
// Build a new block header using the hints from the context
let header = ctx.build_block_header_with_hints();

let sealed_hash = header.hash_slow();
let sealed_header = SealedHeader::new(header, sealed_hash);
let sealed_block = SealedBlock::new(sealed_header, body.clone());
let block_hash = ctx.hints.block_hash.unwrap_or(sealed_block.hash());
let block = Block { header, body: body.clone() };
let block_hash = ctx.hints.block_hash.unwrap_or(block.hash_slow());

// build the new execution payload from the block header
let exec_payload = to_alloy_execution_payload(&sealed_block, block_hash);
let exec_payload = to_alloy_execution_payload(&block, block_hash);

// attempt to fetch the next hint from the engine API payload response
let hint = self.next_hint(exec_payload, &ctx).await?;
debug!(?hint, "Received hint from engine API");

if matches!(hint, EngineApiHint::ValidPayload) {
return Ok(sealed_block);
return Ok(block);
}

// Populate the new hint in the context and continue the loop
Expand Down Expand Up @@ -208,7 +205,7 @@ pub struct EngineHinterContext {
pub block_timestamp: u64,
pub transactions: Vec<PooledTransaction>,
pub withdrawals: Vec<Withdrawal>,
pub head_block: Block,
pub head_block: RpcBlock,
pub hints: Hints,
pub el_client_code: ClientCode,
}
Expand Down
8 changes: 4 additions & 4 deletions bolt-sidecar/src/builder/fallback/payload_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy::{
consensus::{proofs, transaction::PooledTransaction, Transaction},
consensus::{proofs, transaction::PooledTransaction, Block, Transaction},
eips::{calc_excess_blob_gas, calc_next_block_base_fee, eip1559::BaseFeeParams},
primitives::{Address, Bytes},
};
Expand All @@ -10,7 +10,7 @@ use super::{
DEFAULT_EXTRA_DATA,
};
use crate::{
builder::{BuilderError, SealedAlloyBlock},
builder::BuilderError,
client::{BeaconClient, ExecutionClient},
config::Opts,
};
Expand Down Expand Up @@ -62,7 +62,7 @@ impl FallbackPayloadBuilder {
&self,
target_slot: u64,
transactions: &[PooledTransaction],
) -> Result<SealedAlloyBlock, BuilderError> {
) -> Result<Block<PooledTransaction>, BuilderError> {
// Fetch the latest block to get the necessary parent values for the new block.
// For the timestamp, we must use the one expected by the beacon chain instead, to
// prevent edge cases where the proposer before us has missed their slot and therefore
Expand Down Expand Up @@ -198,7 +198,7 @@ mod tests {

let block = builder.build_fallback_payload(slot, &[tx_signed_reth]).await?;

assert_eq!(block.body().transactions.len(), 1);
assert_eq!(block.body.transactions.len(), 1);

Ok(())
}
Expand Down
9 changes: 1 addition & 8 deletions bolt-sidecar/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use alloy::{
consensus::{transaction::PooledTransaction, BlockBody, Header},
primitives::U256,
};
use alloy::primitives::U256;
use alloy_rpc_types_engine::{ClientCode, PayloadStatusEnum};
use ethereum_consensus::{
crypto::{KzgCommitment, PublicKey},
deneb::mainnet::ExecutionPayloadHeader,
ssz::prelude::{List, MerkleizationError},
};
use reth_primitives::SealedBlock;

use crate::{
common::secrets::BlsSecretKeyWrapper,
Expand Down Expand Up @@ -44,9 +40,6 @@ pub use payload_fetcher::{LocalPayloadFetcher, PayloadFetcher};
#[doc(hidden)]
mod compat;

/// Type alias for the sealed block.
type SealedAlloyBlock = SealedBlock<Header, BlockBody<PooledTransaction>>;

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
#[allow(missing_docs)]
Expand Down

0 comments on commit ab429ce

Please sign in to comment.