Skip to content

Commit 25853e1

Browse files
committed
Added drop impl to clean up after tests
Changed revert tests a bit fmt Add txpool test Fix DA config, set it via miner Extend tests Add op-alloy-flz dependency and update related configurations - Added `op-alloy-flz` as a dependency in `Cargo.toml` and `Cargo.lock`. - Configured `op-alloy-flz` to be part of the workspace in `op-rbuilder`'s `Cargo.toml`. - Updated the `payload_builder_vanilla.rs` to utilize `op-alloy-flz` for transaction size estimation. - Enhanced test framework to include new data availability tests ensuring block size limits are respected. Add max data availability transaction and block size configuration - Introduced `max_da_tx_size` and `max_da_block_size` fields in `TestHarnessBuilder` and `OpRbuilderConfig`. - Added builder methods `with_max_da_tx_size` and `with_max_da_block_size` for setting these values. - Implemented a new test to ensure transaction size limits are respected in data availability scenarios. - Updated test module to include the new data availability test. Add cumulative_da_bytes_used accur Add da config Use correct DA transaction compression
1 parent 3bc0aff commit 25853e1

File tree

15 files changed

+338
-54
lines changed

15 files changed

+338
-54
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ op-alloy-rpc-types-engine = { version = "0.16.0", default-features = false }
132132
op-alloy-rpc-jsonrpsee = { version = "0.16.0", default-features = false }
133133
op-alloy-network = { version = "0.16.0", default-features = false }
134134
op-alloy-consensus = { version = "0.16.0", default-features = false }
135+
op-alloy-flz = { version = "0.13.0", default-features = false }
135136

136137
async-trait = { version = "0.1.83" }
137138
clap = { version = "4.4.3", features = ["derive", "env"] }

crates/op-rbuilder/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ op-alloy-consensus.workspace = true
6464
op-alloy-rpc-types-engine.workspace = true
6565
op-alloy-rpc-types.workspace = true
6666
op-alloy-network.workspace = true
67+
op-alloy-flz.workspace = true
6768

6869
revm.workspace = true
6970
op-revm.workspace = true
@@ -110,6 +111,9 @@ tikv-jemallocator = { version = "0.6", optional = true }
110111
vergen = { workspace = true, features = ["build", "cargo", "emit_and_set"] }
111112
vergen-git2.workspace = true
112113

114+
[dev-dependencies]
115+
alloy-provider = {workspace = true, default-features = true, features = ["txpool-api"]}
116+
113117
[features]
114118
default = ["jemalloc"]
115119

crates/op-rbuilder/src/args/op.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
//! clap [Args](clap::Args) for optimism rollup configuration
66
use std::path::PathBuf;
77

8-
use reth_optimism_node::args::RollupArgs;
9-
108
use crate::tx_signer::Signer;
9+
use reth_optimism_node::args::RollupArgs;
1110

1211
/// Parameters for rollup configuration
1312
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]

crates/op-rbuilder/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use reth_optimism_node::{
55
node::{OpAddOnsBuilder, OpPoolBuilder},
66
OpNode,
77
};
8+
use reth_optimism_payload_builder::config::OpDAConfig;
89
use reth_transaction_pool::TransactionPool;
910

1011
/// CLI argument parsing.
@@ -56,6 +57,7 @@ fn main() {
5657
.run(|builder, builder_args| async move {
5758
let rollup_args = builder_args.rollup_args;
5859

60+
let da_config = OpDAConfig::default();
5961
let op_node = OpNode::new(rollup_args.clone());
6062
let handle = builder
6163
.with_types::<OpNode>()
@@ -78,6 +80,7 @@ fn main() {
7880
.payload(CustomOpPayloadBuilder::new(
7981
builder_args.builder_signer,
8082
std::time::Duration::from_secs(builder_args.extra_block_deadline_secs),
83+
da_config.clone(),
8184
builder_args.flashblocks_ws_url,
8285
builder_args.chain_block_time,
8386
builder_args.flashblock_block_time,
@@ -87,6 +90,7 @@ fn main() {
8790
OpAddOnsBuilder::default()
8891
.with_sequencer(rollup_args.sequencer.clone())
8992
.with_enable_tx_conditional(rollup_args.enable_tx_conditional)
93+
.with_da_config(da_config)
9094
.build(),
9195
)
9296
.extend_rpc_modules(move |ctx| {

crates/op-rbuilder/src/payload_builder.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
3838
use reth_optimism_forks::OpHardforks;
3939
use reth_optimism_node::OpEngineTypes;
4040
use reth_optimism_payload_builder::{
41+
config::OpDAConfig,
4142
error::OpPayloadBuilderError,
4243
payload::{OpBuiltPayload, OpPayloadBuilderAttributes},
4344
};
4445
use reth_optimism_primitives::{OpPrimitives, OpReceipt, OpTransactionSigned};
45-
use reth_optimism_txpool::OpPooledTx;
46+
use reth_optimism_txpool::{estimated_da_size::DataAvailabilitySized, OpPooledTx};
4647
use reth_payload_builder::PayloadBuilderService;
4748
use reth_payload_builder_primitives::PayloadBuilderError;
4849
use reth_payload_primitives::PayloadBuilderAttributes;
@@ -96,6 +97,7 @@ struct FlashblocksMetadata<N: NodePrimitives> {
9697
pub struct CustomOpPayloadBuilder {
9798
#[expect(dead_code)]
9899
builder_signer: Option<Signer>,
100+
da_config: OpDAConfig,
99101
flashblocks_ws_url: String,
100102
chain_block_time: u64,
101103
flashblock_block_time: u64,
@@ -106,12 +108,14 @@ impl CustomOpPayloadBuilder {
106108
pub fn new(
107109
builder_signer: Option<Signer>,
108110
extra_block_deadline: std::time::Duration,
111+
da_config: OpDAConfig,
109112
flashblocks_ws_url: String,
110113
chain_block_time: u64,
111114
flashblock_block_time: u64,
112115
) -> Self {
113116
Self {
114117
builder_signer,
118+
da_config,
115119
flashblocks_ws_url,
116120
chain_block_time,
117121
flashblock_block_time,
@@ -132,6 +136,7 @@ where
132136
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
133137
+ Unpin
134138
+ 'static,
139+
<Pool as TransactionPool>::Transaction: OpPooledTx,
135140
Evm: ConfigureEvm<
136141
Primitives = PrimitivesTy<Node::Types>,
137142
NextBlockEnvCtx = OpNextBlockEnvAttributes,
@@ -149,6 +154,7 @@ where
149154
OpEvmConfig::optimism(ctx.chain_spec()),
150155
pool,
151156
ctx.provider().clone(),
157+
self.da_config,
152158
self.flashblocks_ws_url.clone(),
153159
self.chain_block_time,
154160
self.flashblock_block_time,
@@ -241,6 +247,8 @@ pub struct OpPayloadBuilder<Pool, Client> {
241247
pub pool: Pool,
242248
/// Node client
243249
pub client: Client,
250+
/// DA settings.
251+
pub da_config: OpDAConfig,
244252
/// Channel sender for publishing messages
245253
pub tx: mpsc::UnboundedSender<String>,
246254
/// chain block time
@@ -259,6 +267,7 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
259267
evm_config: OpEvmConfig,
260268
pool: Pool,
261269
client: Client,
270+
da_config: OpDAConfig,
262271
flashblocks_ws_url: String,
263272
chain_block_time: u64,
264273
flashblock_block_time: u64,
@@ -276,6 +285,7 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
276285
evm_config,
277286
pool,
278287
client,
288+
da_config,
279289
tx,
280290
chain_block_time,
281291
flashblock_block_time,
@@ -337,7 +347,8 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
337347

338348
impl<Pool, Client> OpPayloadBuilder<Pool, Client>
339349
where
340-
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = OpTransactionSigned>>,
350+
Pool:
351+
TransactionPool<Transaction: PoolTransaction<Consensus = OpTransactionSigned> + OpPooledTx>,
341352
Client: StateProviderFactory + ChainSpecProvider<ChainSpec: EthChainSpec + OpHardforks>,
342353
{
343354
/// Send a message to be published
@@ -394,6 +405,7 @@ where
394405

395406
let ctx = OpPayloadBuilderCtx {
396407
evm_config: self.evm_config.clone(),
408+
da_config: self.da_config.clone(),
397409
chain_spec: self.client.chain_spec(),
398410
config,
399411
evm_env,
@@ -443,8 +455,17 @@ where
443455

444456
let gas_per_batch = ctx.block_gas_limit() / self.flashblocks_per_block;
445457

458+
// We initially set total_gas_per_batch equal to 1 flashblocks portion and then
459+
// add additional portions to the limit as we build more flashblocks
446460
let mut total_gas_per_batch = gas_per_batch;
447461

462+
let da_per_batch = if let Some(da_limit) = ctx.da_config.max_da_block_size() {
463+
Some(da_limit / self.flashblocks_per_block)
464+
} else {
465+
None
466+
};
467+
let mut total_da_per_batch = da_per_batch;
468+
448469
let mut flashblock_count = 0;
449470
// Create a channel to coordinate flashblock building
450471
let (build_tx, mut build_rx) = mpsc::channel(1);
@@ -513,9 +534,10 @@ where
513534
// Continue with flashblock building
514535
tracing::info!(
515536
target: "payload_builder",
516-
"Building flashblock {} {}",
537+
"Building flashblock idx={} target_gas={} taget_da={}",
517538
flashblock_count,
518539
total_gas_per_batch,
540+
total_da_per_batch.unwrap_or(0),
519541
);
520542

521543
let flashblock_build_start_time = Instant::now();
@@ -542,6 +564,7 @@ where
542564
&mut db,
543565
best_txs,
544566
total_gas_per_batch.min(ctx.block_gas_limit()),
567+
total_da_per_batch,
545568
)?;
546569
ctx.metrics
547570
.payload_tx_simulation_duration
@@ -596,6 +619,9 @@ where
596619
// Update bundle_state for next iteration
597620
bundle_state = new_bundle_state;
598621
total_gas_per_batch += gas_per_batch;
622+
if let Some(da_limit) = da_per_batch {
623+
total_da_per_batch.as_mut().map(|da| *da += da_limit);
624+
}
599625
flashblock_count += 1;
600626
tracing::info!(target: "payload_builder", "Flashblock {} built", flashblock_count);
601627
}
@@ -617,7 +643,8 @@ where
617643
impl<Pool, Client> PayloadBuilder for OpPayloadBuilder<Pool, Client>
618644
where
619645
Client: StateProviderFactory + ChainSpecProvider<ChainSpec: EthChainSpec + OpHardforks> + Clone,
620-
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = OpTransactionSigned>>,
646+
Pool:
647+
TransactionPool<Transaction: PoolTransaction<Consensus = OpTransactionSigned> + OpPooledTx>,
621648
{
622649
type Attributes = OpPayloadBuilderAttributes<OpTransactionSigned>;
623650
type BuiltPayload = OpBuiltPayload;
@@ -889,6 +916,8 @@ impl<T: PoolTransaction> OpPayloadTransactions<T> for () {
889916
pub struct OpPayloadBuilderCtx<ChainSpec> {
890917
/// The type that knows how to perform system calls and configure the evm.
891918
pub evm_config: OpEvmConfig,
919+
/// The DA config for the payload builder
920+
pub da_config: OpDAConfig,
892921
/// The chainspec
893922
pub chain_spec: Arc<ChainSpec>,
894923
/// How to build the payload.
@@ -1145,9 +1174,10 @@ where
11451174
info: &mut ExecutionInfo<OpPrimitives>,
11461175
db: &mut State<DB>,
11471176
mut best_txs: impl PayloadTransactions<
1148-
Transaction: PoolTransaction<Consensus = OpTransactionSigned>,
1177+
Transaction: PoolTransaction<Consensus = OpTransactionSigned> + OpPooledTx,
11491178
>,
11501179
batch_gas_limit: u64,
1180+
block_da_limit: Option<u64>,
11511181
) -> Result<Option<()>, PayloadBuilderError>
11521182
where
11531183
DB: Database<Error = ProviderError>,
@@ -1157,10 +1187,11 @@ where
11571187
let mut num_txs_simulated = 0;
11581188
let mut num_txs_simulated_success = 0;
11591189
let mut num_txs_simulated_fail = 0;
1160-
1190+
let tx_da_limit = self.da_config.max_da_tx_size();
11611191
let mut evm = self.evm_config.evm_with_env(&mut *db, self.evm_env.clone());
11621192

11631193
while let Some(tx) = best_txs.next(()) {
1194+
let tx_da_size = tx.estimated_da_size();
11641195
let tx = tx.into_consensus();
11651196
num_txs_considered += 1;
11661197

@@ -1170,7 +1201,13 @@ where
11701201
}
11711202

11721203
// ensure we still have capacity for this transaction
1173-
if info.is_tx_over_limits(tx.inner(), batch_gas_limit, None, None) {
1204+
if info.is_tx_over_limits(
1205+
tx_da_size,
1206+
batch_gas_limit,
1207+
tx_da_limit,
1208+
block_da_limit,
1209+
tx.gas_limit(),
1210+
) {
11741211
// we can't fit this transaction into the block, so we need to mark it as
11751212
// invalid which also removes all dependent transaction from
11761213
// the iterator before we can continue
@@ -1227,6 +1264,8 @@ where
12271264
// add gas used by the transaction to cumulative gas used, before creating the receipt
12281265
let gas_used = result.gas_used();
12291266
info.cumulative_gas_used += gas_used;
1267+
// record tx da size
1268+
info.cumulative_da_bytes_used += tx_da_size;
12301269

12311270
let ctx = ReceiptBuilderCtx {
12321271
tx: tx.inner(),

0 commit comments

Comments
 (0)