Skip to content

Commit 01573b2

Browse files
committed
Add flashtestation builder tx and registration in block
1 parent 0b9b3a3 commit 01573b2

File tree

7 files changed

+669
-57
lines changed

7 files changed

+669
-57
lines changed

crates/op-rbuilder/src/builders/builder_tx.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ impl From<BuilderTransactionError> for PayloadBuilderError {
8989
}
9090
}
9191

92+
impl BuilderTransactionError {
93+
pub fn other<E>(error: E) -> Self
94+
where
95+
E: core::error::Error + Send + Sync + 'static,
96+
{
97+
BuilderTransactionError::Other(Box::new(error))
98+
}
99+
}
100+
92101
pub trait BuilderTransactions<ExtraCtx: Debug + Default = ()>: Debug {
93102
fn simulate_builder_txs<Extra: Debug + Default>(
94103
&self,

crates/op-rbuilder/src/builders/context.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloy_consensus::{Eip658Value, Transaction, conditional::BlockConditionalAtt
22
use alloy_eips::Typed2718;
33
use alloy_evm::Database;
44
use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
5-
use alloy_primitives::{Bytes, U256};
5+
use alloy_primitives::{BlockHash, Bytes, U256};
66
use alloy_rpc_types_eth::Withdrawals;
77
use core::fmt::Debug;
88
use op_alloy_consensus::OpDepositReceipt;
@@ -75,41 +75,51 @@ pub struct OpPayloadBuilderCtx<ExtraCtx: Debug + Default = ()> {
7575

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

82+
/// Returns the parent hash
83+
pub fn parent_hash(&self) -> BlockHash {
84+
self.parent().hash()
85+
}
86+
87+
/// Returns the timestamp
88+
pub fn timestamp(&self) -> u64 {
89+
self.attributes().timestamp()
90+
}
91+
8292
/// Returns the builder attributes.
8393
pub(super) const fn attributes(&self) -> &OpPayloadBuilderAttributes<OpTransactionSigned> {
8494
&self.config.attributes
8595
}
8696

8797
/// Returns the withdrawals if shanghai is active.
88-
pub(super) fn withdrawals(&self) -> Option<&Withdrawals> {
98+
pub fn withdrawals(&self) -> Option<&Withdrawals> {
8999
self.chain_spec
90100
.is_shanghai_active_at_timestamp(self.attributes().timestamp())
91101
.then(|| &self.attributes().payload_attributes.withdrawals)
92102
}
93103

94104
/// Returns the block gas limit to target.
95-
pub(super) fn block_gas_limit(&self) -> u64 {
105+
pub fn block_gas_limit(&self) -> u64 {
96106
self.attributes()
97107
.gas_limit
98108
.unwrap_or(self.evm_env.block_env.gas_limit)
99109
}
100110

101111
/// Returns the block number for the block.
102-
pub(super) fn block_number(&self) -> u64 {
112+
pub fn block_number(&self) -> u64 {
103113
as_u64_saturated!(self.evm_env.block_env.number)
104114
}
105115

106116
/// Returns the current base fee
107-
pub(super) fn base_fee(&self) -> u64 {
117+
pub fn base_fee(&self) -> u64 {
108118
self.evm_env.block_env.basefee
109119
}
110120

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

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

155165
/// Returns the unique id for this payload job.
156-
pub(super) fn payload_id(&self) -> PayloadId {
166+
pub fn payload_id(&self) -> PayloadId {
157167
self.attributes().payload_id()
158168
}
159169

160170
/// Returns true if regolith is active for the payload.
161-
pub(super) fn is_regolith_active(&self) -> bool {
171+
pub fn is_regolith_active(&self) -> bool {
162172
self.chain_spec
163173
.is_regolith_active_at_timestamp(self.attributes().timestamp())
164174
}
165175

166176
/// Returns true if ecotone is active for the payload.
167-
pub(super) fn is_ecotone_active(&self) -> bool {
177+
pub fn is_ecotone_active(&self) -> bool {
168178
self.chain_spec
169179
.is_ecotone_active_at_timestamp(self.attributes().timestamp())
170180
}
171181

172182
/// Returns true if canyon is active for the payload.
173-
pub(super) fn is_canyon_active(&self) -> bool {
183+
pub fn is_canyon_active(&self) -> bool {
174184
self.chain_spec
175185
.is_canyon_active_at_timestamp(self.attributes().timestamp())
176186
}
177187

178188
/// Returns true if holocene is active for the payload.
179-
pub(super) fn is_holocene_active(&self) -> bool {
189+
pub fn is_holocene_active(&self) -> bool {
180190
self.chain_spec
181191
.is_holocene_active_at_timestamp(self.attributes().timestamp())
182192
}
183193

184194
/// Returns true if isthmus is active for the payload.
185-
pub(super) fn is_isthmus_active(&self) -> bool {
195+
pub fn is_isthmus_active(&self) -> bool {
186196
self.chain_spec
187197
.is_isthmus_active_at_timestamp(self.attributes().timestamp())
188198
}
189199

190200
/// Returns the chain id
191-
pub(super) fn chain_id(&self) -> u64 {
201+
pub fn chain_id(&self) -> u64 {
192202
self.chain_spec.chain_id()
193203
}
194204
}

crates/op-rbuilder/src/builders/flashblocks/builder_tx.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
context::OpPayloadBuilderCtx,
2626
flashblocks::payload::FlashblocksExtraCtx,
2727
},
28-
flashtestations::service::FlashtestationsBuilderTx,
28+
flashtestations::builder_tx::FlashtestationsBuilderTx,
2929
primitives::reth::ExecutionInfo,
3030
tx_signer::Signer,
3131
};
@@ -172,23 +172,21 @@ impl FlashblocksNumberBuilderTx {
172172
) {
173173
Ok(gas_used)
174174
} else {
175-
Err(BuilderTransactionError::Other(Box::new(
175+
Err(BuilderTransactionError::other(
176176
FlashblockNumberError::LogMismatch(
177177
IFlashblockNumber::FlashblockIncremented::SIGNATURE_HASH,
178178
),
179-
)))
179+
))
180180
}
181181
}
182-
ExecutionResult::Revert { output, .. } => {
183-
Err(BuilderTransactionError::Other(Box::new(
184-
IFlashblockNumber::IFlashblockNumberErrors::abi_decode(&output)
185-
.map(FlashblockNumberError::Revert)
186-
.unwrap_or_else(|e| FlashblockNumberError::Unknown(hex::encode(output), e)),
187-
)))
188-
}
189-
ExecutionResult::Halt { reason, .. } => Err(BuilderTransactionError::Other(Box::new(
182+
ExecutionResult::Revert { output, .. } => Err(BuilderTransactionError::other(
183+
IFlashblockNumber::IFlashblockNumberErrors::abi_decode(&output)
184+
.map(FlashblockNumberError::Revert)
185+
.unwrap_or_else(|e| FlashblockNumberError::Unknown(hex::encode(output), e)),
186+
)),
187+
ExecutionResult::Halt { reason, .. } => Err(BuilderTransactionError::other(
190188
FlashblockNumberError::Halt(reason),
191-
))),
189+
)),
192190
}
193191
}
194192

crates/op-rbuilder/src/builders/standard/builder_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
BuilderTransactionCtx, BuilderTransactionError, BuilderTransactions,
99
builder_tx::BuilderTxBase, context::OpPayloadBuilderCtx,
1010
},
11-
flashtestations::service::FlashtestationsBuilderTx,
11+
flashtestations::builder_tx::FlashtestationsBuilderTx,
1212
primitives::reth::ExecutionInfo,
1313
tx_signer::Signer,
1414
};

0 commit comments

Comments
 (0)