Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove all reth types #752

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions bolt-sidecar/src/builder/compat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy::{
consensus::BlockHeader,
consensus::{transaction::PooledTransaction, BlockHeader},
eips::{eip2718::Encodable2718, eip4895::Withdrawal},
primitives::{Address, Bloom, B256, U256},
rpc::types::Withdrawals,
Expand All @@ -19,14 +19,14 @@ use ethereum_consensus::{
ssz::prelude::{ssz_rs, ByteList, ByteVector, HashTreeRoot, List},
types::mainnet::ExecutionPayload as ConsensusExecutionPayload,
};
use reth_primitives::{SealedBlock, TransactionSigned};
use reth_primitives_traits::BlockBody;

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: &SealedBlock,
transactions: Vec<TransactionSigned>,
sealed_block: &SealedAlloyBlock,
transactions: Vec<PooledTransaction>,
) -> ConsensusExecutionPayloadHeader {
// Transactions and withdrawals are treated as opaque byte arrays in consensus types
let transactions_bytes = transactions.iter().map(|t| t.encoded_2718()).collect::<Vec<_>>();
Expand Down Expand Up @@ -75,36 +75,30 @@ 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: &SealedBlock,
block: &SealedAlloyBlock,
block_hash: B256,
) -> ExecutionPayloadV3 {
let alloy_withdrawals = block
let alloy_withdrawals =
block.body().withdrawals.clone().map(|w| w.into_inner()).unwrap_or_default();

let transactions = block
.body()
.withdrawals
.as_ref()
.map(|withdrawals| {
withdrawals
.iter()
.map(|w| Withdrawal {
index: w.index,
validator_index: w.validator_index,
address: w.address,
amount: w.amount,
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
.transactions
.iter()
.map(|tx| tx.encoded_2718())
.map(Into::into)
.collect::<Vec<_>>();

ExecutionPayloadV3 {
blob_gas_used: block.blob_gas_used().unwrap_or_default(),
excess_blob_gas: block.excess_blob_gas.unwrap_or_default(),
payload_inner: ExecutionPayloadV2 {
payload_inner: ExecutionPayloadV1 {
base_fee_per_gas: U256::from(block.base_fee_per_gas.unwrap_or_default()),
block_hash,
transactions,
base_fee_per_gas: U256::from(block.base_fee_per_gas.unwrap_or_default()),
block_number: block.number,
extra_data: block.extra_data.clone(),
transactions: block.body().encoded_2718_transactions(),
fee_recipient: block.header().beneficiary,
gas_limit: block.gas_limit,
gas_used: block.gas_used,
Expand All @@ -121,7 +115,9 @@ 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: &SealedBlock) -> ConsensusExecutionPayload {
pub(crate) fn to_consensus_execution_payload(
value: &SealedAlloyBlock,
) -> ConsensusExecutionPayload {
let hash = value.hash();
let header = value.header();
let transactions = &value.body().transactions;
Expand Down
14 changes: 7 additions & 7 deletions bolt-sidecar/src/builder/fallback/engine_hinter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::ops::Deref;

use alloy::{
consensus::{Header, EMPTY_OMMER_ROOT_HASH},
consensus::{transaction::PooledTransaction, Header, EMPTY_OMMER_ROOT_HASH},
primitives::{Address, Bloom, Bytes, B256, B64, U256},
rpc::types::{Block, 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, TransactionSigned};
use reth_primitives::{BlockBody, SealedBlock, SealedHeader};
use tracing::{debug, error};

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

Expand Down Expand Up @@ -52,7 +52,7 @@ impl EngineHinter {
pub async fn fetch_payload_from_hints(
&self,
mut ctx: EngineHinterContext,
) -> Result<SealedBlock, BuilderError> {
) -> Result<SealedAlloyBlock, 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 Down Expand Up @@ -206,7 +206,7 @@ pub struct EngineHinterContext {
pub parent_beacon_block_root: B256,
pub blob_versioned_hashes: Vec<B256>,
pub block_timestamp: u64,
pub transactions: Vec<TransactionSigned>,
pub transactions: Vec<PooledTransaction>,
pub withdrawals: Vec<Withdrawal>,
pub head_block: Block,
pub hints: Hints,
Expand All @@ -215,8 +215,8 @@ pub struct EngineHinterContext {

impl EngineHinterContext {
/// Build a block body using the transactions and withdrawals from the context.
pub fn build_block_body(&self) -> BlockBody {
BlockBody {
pub fn build_block_body(&self) -> BlockBody<PooledTransaction> {
BlockBody::<PooledTransaction> {
ommers: Vec::new(),
transactions: self.transactions.clone(),
withdrawals: Some(Withdrawals::new(self.withdrawals.clone())),
Expand Down
14 changes: 6 additions & 8 deletions bolt-sidecar/src/builder/fallback/payload_builder.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use alloy::{
consensus::{proofs, Transaction},
consensus::{proofs, transaction::PooledTransaction, Transaction},
eips::{calc_excess_blob_gas, calc_next_block_base_fee, eip1559::BaseFeeParams},
primitives::{Address, Bytes},
};
use reth_primitives::{SealedBlock, TransactionSigned};
use tracing::debug;

use super::{
engine_hinter::{EngineHinter, EngineHinterContext},
DEFAULT_EXTRA_DATA,
};
use crate::{
builder::BuilderError,
builder::{BuilderError, SealedAlloyBlock},
client::{BeaconClient, ExecutionClient},
config::Opts,
};
Expand Down Expand Up @@ -62,8 +61,8 @@ impl FallbackPayloadBuilder {
pub async fn build_fallback_payload(
&self,
target_slot: u64,
transactions: &[TransactionSigned],
) -> Result<SealedBlock, BuilderError> {
transactions: &[PooledTransaction],
) -> Result<SealedAlloyBlock, 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 @@ -145,15 +144,14 @@ mod tests {
use std::time::{SystemTime, UNIX_EPOCH};

use alloy::{
consensus::{constants, proofs},
consensus::{constants, proofs, transaction::PooledTransaction},
eips::eip2718::{Decodable2718, Encodable2718},
network::{EthereumWallet, TransactionBuilder},
primitives::{hex, Address},
providers::{Provider, ProviderBuilder},
signers::{k256::ecdsa::SigningKey, local::PrivateKeySigner},
};
use beacon_api_client::mainnet::Client as BeaconClient;
use reth_primitives::TransactionSigned;
use tracing::warn;

use crate::{
Expand Down Expand Up @@ -192,7 +190,7 @@ mod tests {
let tx = default_test_transaction(addy, Some(nonce)).with_chain_id(17000);
let tx_signed = tx.build(&wallet).await?;
let raw_encoded = tx_signed.encoded_2718();
let tx_signed_reth = TransactionSigned::decode_2718(&mut raw_encoded.as_slice())?;
let tx_signed_reth = PooledTransaction::decode_2718(&mut raw_encoded.as_slice())?;

let slot = genesis_time +
(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() / cfg.chain.slot_time()) +
Expand Down
9 changes: 8 additions & 1 deletion bolt-sidecar/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use alloy::primitives::U256;
use alloy::{
consensus::{transaction::PooledTransaction, BlockBody, Header},
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 @@ -40,6 +44,9 @@ 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
7 changes: 3 additions & 4 deletions bolt-sidecar/src/builder/template.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use alloy::{
consensus::Transaction,
consensus::{transaction::PooledTransaction, Transaction},
primitives::{Address, TxHash, U256},
};
use ethereum_consensus::{
crypto::{KzgCommitment, KzgProof},
deneb::mainnet::{Blob, BlobsBundle},
};
use reth_primitives::TransactionSigned;
use std::collections::HashMap;
use tracing::warn;

Expand Down Expand Up @@ -47,10 +46,10 @@ impl BlockTemplate {
/// Converts the list of signed constraints into a list of signed transactions. Use this when
/// building a local execution payload.
#[inline]
pub fn as_signed_transactions(&self) -> Vec<TransactionSigned> {
pub fn as_signed_transactions(&self) -> Vec<PooledTransaction> {
self.signed_constraints_list
.iter()
.flat_map(|sc| sc.message.transactions.iter().map(|c| c.clone().into_signed()))
.flat_map(|sc| sc.message.transactions.iter().map(|c| c.clone().into_inner()))
.collect()
}

Expand Down
23 changes: 3 additions & 20 deletions bolt-sidecar/src/primitives/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::{borrow::Cow, fmt};

use alloy::{
consensus::{
transaction::PooledTransaction, BlobTransactionSidecar, Signed, Transaction, TxType,
Typed2718,
transaction::PooledTransaction, BlobTransactionSidecar, Transaction, TxType, Typed2718,
},
eips::eip2718::{Decodable2718, Encodable2718},
hex,
primitives::{Address, U256},
};
use reth_primitives::TransactionSigned;
use serde::{de, ser::SerializeSeq};
use std::{borrow::Cow, fmt};

/// Trait that exposes additional information on transaction types that don't already do it
/// by themselves (e.g. [`PooledTransaction`]).
Expand Down Expand Up @@ -139,22 +138,6 @@ impl FullTransaction {
self.tx
}

/// Returns the signed transaction.
pub fn into_signed(self) -> TransactionSigned {
match self.tx {
PooledTransaction::Legacy(tx) => tx.into(),
PooledTransaction::Eip1559(tx) => tx.into(),
PooledTransaction::Eip2930(tx) => tx.into(),
PooledTransaction::Eip4844(tx) => {
let sig = *tx.signature();
let hash = *tx.hash();
let inner_tx = tx.into_parts().0.into_parts().0;
Signed::new_unchecked(inner_tx, sig, hash).into()
}
PooledTransaction::Eip7702(tx) => tx.into(),
}
}

/// Returns the sender of the transaction, if recovered.
pub fn sender(&self) -> Option<&Address> {
self.sender.as_ref()
Expand Down