Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions crates/op-rbuilder/src/builders/builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ impl From<BuilderTransactionError> for PayloadBuilderError {
}
}

impl BuilderTransactionError {
pub fn other<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
BuilderTransactionError::Other(Box::new(error))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to be fancy we could impl From< T > for BuilderTransactionError where T: core::error::Error + Send + Sync + 'static

}
}

pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
fn simulate_builder_txs<Extra: Debug + Default>(
&self,
Expand Down
44 changes: 27 additions & 17 deletions crates/op-rbuilder/src/builders/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy_consensus::{Eip658Value, Transaction, conditional::BlockConditionalAtt
use alloy_eips::Typed2718;
use alloy_evm::Database;
use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
use alloy_primitives::{Bytes, U256};
use alloy_primitives::{BlockHash, Bytes, U256};
use alloy_rpc_types_eth::Withdrawals;
use core::fmt::Debug;
use op_alloy_consensus::OpDepositReceipt;
Expand Down Expand Up @@ -75,41 +75,51 @@ pub struct OpPayloadBuilderCtx<ExtraCtx: Debug + Default = ()> {

impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
/// Returns the parent block the payload will be build on.
pub(super) fn parent(&self) -> &SealedHeader {
pub fn parent(&self) -> &SealedHeader {
&self.config.parent_header
}

/// Returns the parent hash
pub fn parent_hash(&self) -> BlockHash {
self.parent().hash()
}

/// Returns the timestamp
pub fn timestamp(&self) -> u64 {
self.attributes().timestamp()
}

/// Returns the builder attributes.
pub(super) const fn attributes(&self) -> &OpPayloadBuilderAttributes<OpTransactionSigned> {
&self.config.attributes
}

/// Returns the withdrawals if shanghai is active.
pub(super) fn withdrawals(&self) -> Option<&Withdrawals> {
pub fn withdrawals(&self) -> Option<&Withdrawals> {
self.chain_spec
.is_shanghai_active_at_timestamp(self.attributes().timestamp())
.then(|| &self.attributes().payload_attributes.withdrawals)
}

/// Returns the block gas limit to target.
pub(super) fn block_gas_limit(&self) -> u64 {
pub fn block_gas_limit(&self) -> u64 {
self.attributes()
.gas_limit
.unwrap_or(self.evm_env.block_env.gas_limit)
}

/// Returns the block number for the block.
pub(super) fn block_number(&self) -> u64 {
pub fn block_number(&self) -> u64 {
as_u64_saturated!(self.evm_env.block_env.number)
}

/// Returns the current base fee
pub(super) fn base_fee(&self) -> u64 {
pub fn base_fee(&self) -> u64 {
self.evm_env.block_env.basefee
}

/// Returns the current blob gas price.
pub(super) fn get_blob_gasprice(&self) -> Option<u64> {
pub fn get_blob_gasprice(&self) -> Option<u64> {
self.evm_env
.block_env
.blob_gasprice()
Expand All @@ -119,7 +129,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
/// Returns the blob fields for the header.
///
/// This will always return `Some(0)` after ecotone.
pub(super) fn blob_fields(&self) -> (Option<u64>, Option<u64>) {
pub fn blob_fields(&self) -> (Option<u64>, Option<u64>) {
// OP doesn't support blobs/EIP-4844.
// https://specs.optimism.io/protocol/exec-engine.html#ecotone-disable-blob-transactions
// Need [Some] or [None] based on hardfork to match block hash.
Expand All @@ -133,7 +143,7 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
/// Returns the extra data for the block.
///
/// After holocene this extracts the extradata from the paylpad
pub(super) fn extra_data(&self) -> Result<Bytes, PayloadBuilderError> {
pub fn extra_data(&self) -> Result<Bytes, PayloadBuilderError> {
if self.is_holocene_active() {
self.attributes()
.get_holocene_extra_data(
Expand All @@ -148,47 +158,47 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
}

/// Returns the current fee settings for transactions from the mempool
pub(super) fn best_transaction_attributes(&self) -> BestTransactionsAttributes {
pub fn best_transaction_attributes(&self) -> BestTransactionsAttributes {
BestTransactionsAttributes::new(self.base_fee(), self.get_blob_gasprice())
}

/// Returns the unique id for this payload job.
pub(super) fn payload_id(&self) -> PayloadId {
pub fn payload_id(&self) -> PayloadId {
self.attributes().payload_id()
}

/// Returns true if regolith is active for the payload.
pub(super) fn is_regolith_active(&self) -> bool {
pub fn is_regolith_active(&self) -> bool {
self.chain_spec
.is_regolith_active_at_timestamp(self.attributes().timestamp())
}

/// Returns true if ecotone is active for the payload.
pub(super) fn is_ecotone_active(&self) -> bool {
pub fn is_ecotone_active(&self) -> bool {
self.chain_spec
.is_ecotone_active_at_timestamp(self.attributes().timestamp())
}

/// Returns true if canyon is active for the payload.
pub(super) fn is_canyon_active(&self) -> bool {
pub fn is_canyon_active(&self) -> bool {
self.chain_spec
.is_canyon_active_at_timestamp(self.attributes().timestamp())
}

/// Returns true if holocene is active for the payload.
pub(super) fn is_holocene_active(&self) -> bool {
pub fn is_holocene_active(&self) -> bool {
self.chain_spec
.is_holocene_active_at_timestamp(self.attributes().timestamp())
}

/// Returns true if isthmus is active for the payload.
pub(super) fn is_isthmus_active(&self) -> bool {
pub fn is_isthmus_active(&self) -> bool {
self.chain_spec
.is_isthmus_active_at_timestamp(self.attributes().timestamp())
}

/// Returns the chain id
pub(super) fn chain_id(&self) -> u64 {
pub fn chain_id(&self) -> u64 {
self.chain_spec.chain_id()
}
}
Expand Down
22 changes: 10 additions & 12 deletions crates/op-rbuilder/src/builders/flashblocks/builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
context::OpPayloadBuilderCtx,
flashblocks::payload::FlashblocksExtraCtx,
},
flashtestations::service::FlashtestationsBuilderTx,
flashtestations::builder_tx::FlashtestationsBuilderTx,
primitives::reth::ExecutionInfo,
tx_signer::Signer,
};
Expand Down Expand Up @@ -172,23 +172,21 @@ impl FlashblocksNumberBuilderTx {
) {
Ok(gas_used)
} else {
Err(BuilderTransactionError::Other(Box::new(
Err(BuilderTransactionError::other(
FlashblockNumberError::LogMismatch(
IFlashblockNumber::FlashblockIncremented::SIGNATURE_HASH,
),
)))
))
}
}
ExecutionResult::Revert { output, .. } => {
Err(BuilderTransactionError::Other(Box::new(
IFlashblockNumber::IFlashblockNumberErrors::abi_decode(&output)
.map(FlashblockNumberError::Revert)
.unwrap_or_else(|e| FlashblockNumberError::Unknown(hex::encode(output), e)),
)))
}
ExecutionResult::Halt { reason, .. } => Err(BuilderTransactionError::Other(Box::new(
ExecutionResult::Revert { output, .. } => Err(BuilderTransactionError::other(
IFlashblockNumber::IFlashblockNumberErrors::abi_decode(&output)
.map(FlashblockNumberError::Revert)
.unwrap_or_else(|e| FlashblockNumberError::Unknown(hex::encode(output), e)),
)),
ExecutionResult::Halt { reason, .. } => Err(BuilderTransactionError::other(
FlashblockNumberError::Halt(reason),
))),
)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/op-rbuilder/src/builders/standard/builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
BuilderTransactionCtx, BuilderTransactionError, BuilderTransactions,
builder_tx::BuilderTxBase, context::OpPayloadBuilderCtx,
},
flashtestations::service::FlashtestationsBuilderTx,
flashtestations::builder_tx::FlashtestationsBuilderTx,
primitives::reth::ExecutionInfo,
tx_signer::Signer,
};
Expand Down
Loading
Loading