Skip to content

Commit 99c69f4

Browse files
authored
Use correct DA transaction compression (#61)
* 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 * conflict changes
1 parent 92b8f6a commit 99c69f4

File tree

16 files changed

+292
-36
lines changed

16 files changed

+292
-36
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/builders/context.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloy_consensus::{Eip658Value, Transaction, TxEip1559};
2-
use alloy_eips::Typed2718;
2+
use alloy_eips::{Encodable2718, Typed2718};
33
use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
4-
use alloy_primitives::{private::alloy_rlp::Encodable, Address, Bytes, TxKind, U256};
4+
use alloy_primitives::{Address, Bytes, TxKind, U256};
55
use alloy_rpc_types_eth::Withdrawals;
66
use core::fmt::Debug;
77
use op_alloy_consensus::{OpDepositReceipt, OpTypedTransaction};
@@ -19,6 +19,7 @@ use reth_optimism_forks::OpHardforks;
1919
use reth_optimism_node::OpPayloadBuilderAttributes;
2020
use reth_optimism_payload_builder::{config::OpDAConfig, error::OpPayloadBuilderError};
2121
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
22+
use reth_optimism_txpool::estimated_da_size::DataAvailabilitySized;
2223
use reth_payload_builder::PayloadId;
2324
use reth_primitives::{Recovered, SealedHeader};
2425
use reth_primitives_traits::{InMemorySize, SignedTransaction};
@@ -329,11 +330,18 @@ impl OpPayloadBuilderCtx {
329330

330331
while let Some(tx) = best_txs.next(()) {
331332
let exclude_reverting_txs = tx.exclude_reverting_txs();
333+
let tx_da_size = tx.estimated_da_size();
332334

333335
let tx = tx.into_consensus();
334336
num_txs_considered += 1;
335337
// ensure we still have capacity for this transaction
336-
if info.is_tx_over_limits(tx.inner(), block_gas_limit, tx_da_limit, block_da_limit) {
338+
if info.is_tx_over_limits(
339+
tx_da_size,
340+
block_gas_limit,
341+
tx_da_limit,
342+
block_da_limit,
343+
tx.gas_limit(),
344+
) {
337345
// we can't fit this transaction into the block, so we need to mark it as
338346
// invalid which also removes all dependent transaction from
339347
// the iterator before we can continue
@@ -394,6 +402,8 @@ impl OpPayloadBuilderCtx {
394402
// receipt
395403
let gas_used = result.gas_used();
396404
info.cumulative_gas_used += gas_used;
405+
// record tx da size
406+
info.cumulative_da_bytes_used += tx_da_size;
397407

398408
// Push transaction changeset and calculate header bloom filter for receipt.
399409
let ctx = ReceiptBuilderCtx {
@@ -498,7 +508,7 @@ impl OpPayloadBuilderCtx {
498508
db: &mut State<DB>,
499509
builder_tx_gas: u64,
500510
message: Vec<u8>,
501-
) -> Option<usize>
511+
) -> Option<u64>
502512
where
503513
DB: Database<Error = ProviderError>,
504514
{
@@ -509,7 +519,9 @@ impl OpPayloadBuilderCtx {
509519
// Create and sign the transaction
510520
let builder_tx =
511521
signed_builder_tx(db, builder_tx_gas, message, signer, base_fee, chain_id)?;
512-
Ok(builder_tx.length())
522+
Ok(op_alloy_flz::tx_estimated_size_fjord(
523+
builder_tx.encoded_2718().as_slice(),
524+
))
513525
})
514526
.transpose()
515527
.unwrap_or_else(|err: PayloadBuilderError| {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ where
222222

223223
let gas_per_batch = ctx.block_gas_limit() / self.config.flashblocks_per_block();
224224
let mut total_gas_per_batch = gas_per_batch;
225-
let total_da_bytes_per_batch = ctx
225+
let da_per_batch = ctx
226226
.da_config
227227
.max_da_block_size()
228-
.map(|limit| limit / self.config.flashblocks_per_block());
228+
.map(|da_limit| da_limit / self.config.flashblocks_per_block());
229+
let mut total_da_per_batch = da_per_batch;
229230

230231
let mut flashblock_count = 0;
231232
// Create a channel to coordinate flashblock building
@@ -295,11 +296,11 @@ where
295296
// Continue with flashblock building
296297
tracing::info!(
297298
target: "payload_builder",
298-
"Building flashblock {} {}",
299+
"Building flashblock idx={} target_gas={} taget_da={}",
299300
flashblock_count,
300301
total_gas_per_batch,
302+
total_da_per_batch.unwrap_or(0),
301303
);
302-
303304
let flashblock_build_start_time = Instant::now();
304305
let state = StateProviderDatabase::new(&state_provider);
305306

@@ -324,7 +325,7 @@ where
324325
&mut db,
325326
best_txs,
326327
total_gas_per_batch.min(ctx.block_gas_limit()),
327-
total_da_bytes_per_batch,
328+
total_da_per_batch,
328329
)?;
329330
ctx.metrics
330331
.payload_tx_simulation_duration
@@ -377,6 +378,13 @@ where
377378
// Update bundle_state for next iteration
378379
bundle_state = new_bundle_state;
379380
total_gas_per_batch += gas_per_batch;
381+
if let Some(da_limit) = da_per_batch {
382+
if let Some(da) = total_da_per_batch.as_mut() {
383+
*da += da_limit;
384+
} else {
385+
error!("Builder end up in faulty invariant, if da_per_batch is set then total_da_per_batch must be set");
386+
}
387+
}
380388
flashblock_count += 1;
381389
tracing::info!(target: "payload_builder", "Flashblock {} built", flashblock_count);
382390
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,7 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
355355
let block_da_limit = ctx
356356
.da_config
357357
.max_da_block_size()
358-
.map(|da_size| da_size - builder_tx_da_size as u64);
359-
// Check that it's possible to create builder tx, considering max_da_tx_size, otherwise panic
360-
if let Some(tx_da_limit) = ctx.da_config.max_da_tx_size() {
361-
// Panic indicate max_da_tx_size misconfiguration
362-
assert!(
363-
tx_da_limit >= builder_tx_da_size as u64,
364-
"The configured da_config.max_da_tx_size is too small to accommodate builder tx."
365-
);
366-
}
358+
.map(|da_size| da_size.saturating_sub(builder_tx_da_size));
367359

368360
if !ctx.attributes().no_tx_pool {
369361
let best_txs_start_time = Instant::now();

crates/op-rbuilder/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
cli.run(|builder, builder_args| async move {
6969
let builder_config = BuilderConfig::<B::Config>::try_from(builder_args.clone())
7070
.expect("Failed to convert rollup args to builder config");
71-
71+
let da_config = builder_config.da_config.clone();
7272
let rollup_args = builder_args.rollup_args;
7373
let op_node = OpNode::new(rollup_args.clone());
7474
let handle = builder
@@ -95,6 +95,7 @@ where
9595
OpAddOnsBuilder::default()
9696
.with_sequencer(rollup_args.sequencer.clone())
9797
.with_enable_tx_conditional(rollup_args.enable_tx_conditional)
98+
.with_da_config(da_config)
9899
.build(),
99100
)
100101
.extend_rpc_modules(move |ctx| {

crates/op-rbuilder/src/primitives/reth/execution.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Heavily influenced by [reth](https://github.com/paradigmxyz/reth/blob/1e965caf5fa176f244a31c0d2662ba1b590938db/crates/optimism/payload/src/builder.rs#L570)
2-
use alloy_consensus::Transaction;
3-
use alloy_primitives::{private::alloy_rlp::Encodable, Address, U256};
2+
use alloy_primitives::{Address, U256};
43
use core::fmt::Debug;
54
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
65

@@ -44,21 +43,22 @@ impl<T: Debug + Default> ExecutionInfo<T> {
4443
/// maximum allowed DA limit per block.
4544
pub fn is_tx_over_limits(
4645
&self,
47-
tx: &OpTransactionSigned,
46+
tx_da_size: u64,
4847
block_gas_limit: u64,
4948
tx_data_limit: Option<u64>,
5049
block_data_limit: Option<u64>,
50+
tx_gas_limit: u64,
5151
) -> bool {
52-
if tx_data_limit.is_some_and(|da_limit| tx.length() as u64 > da_limit) {
52+
if tx_data_limit.is_some_and(|da_limit| tx_da_size > da_limit) {
5353
return true;
5454
}
5555

5656
if block_data_limit
57-
.is_some_and(|da_limit| self.cumulative_da_bytes_used + (tx.length() as u64) > da_limit)
57+
.is_some_and(|da_limit| self.cumulative_da_bytes_used + tx_da_size > da_limit)
5858
{
5959
return true;
6060
}
6161

62-
self.cumulative_gas_used + tx.gas_limit() > block_gas_limit
62+
self.cumulative_gas_used + tx_gas_limit > block_gas_limit
6363
}
6464
}

crates/op-rbuilder/src/tests/framework/blocks.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,12 @@ impl BlockGenerated {
372372
pub fn includes(&self, tx_hash: B256) -> bool {
373373
self.block.transactions.hashes().any(|hash| hash == tx_hash)
374374
}
375+
376+
pub fn includes_vec(&self, tx_hashes: Vec<B256>) -> bool {
377+
tx_hashes.iter().all(|hash| self.includes(*hash))
378+
}
379+
380+
pub fn not_includes_vec(&self, tx_hashes: Vec<B256>) -> bool {
381+
tx_hashes.iter().all(|hash| self.not_includes(*hash))
382+
}
375383
}

crates/op-rbuilder/src/tests/framework/harness.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct TestHarnessBuilder {
2525
flashblocks_ws_url: Option<String>,
2626
chain_block_time: Option<u64>,
2727
flashbots_block_time: Option<u64>,
28+
namespaces: Option<String>,
29+
extra_params: Option<String>,
2830
}
2931

3032
impl TestHarnessBuilder {
@@ -35,6 +37,8 @@ impl TestHarnessBuilder {
3537
flashblocks_ws_url: None,
3638
chain_block_time: None,
3739
flashbots_block_time: None,
40+
namespaces: None,
41+
extra_params: None,
3842
}
3943
}
4044

@@ -58,6 +62,16 @@ impl TestHarnessBuilder {
5862
self
5963
}
6064

65+
pub fn with_namespaces(mut self, namespaces: &str) -> Self {
66+
self.namespaces = Some(namespaces.to_string());
67+
self
68+
}
69+
70+
pub fn with_extra_params(mut self, extra_params: &str) -> Self {
71+
self.extra_params = Some(extra_params.to_string());
72+
self
73+
}
74+
6175
pub async fn build(self) -> eyre::Result<TestHarness> {
6276
let mut framework = IntegrationFramework::new(&self.name).unwrap();
6377

@@ -69,7 +83,7 @@ impl TestHarnessBuilder {
6983
std::fs::write(&genesis_path, genesis)?;
7084

7185
// create the builder
72-
let builder_data_dir = std::env::temp_dir().join(Uuid::new_v4().to_string());
86+
let builder_data_dir: PathBuf = std::env::temp_dir().join(Uuid::new_v4().to_string());
7387
let builder_auth_rpc_port = get_available_port();
7488
let builder_http_port = get_available_port();
7589
let mut op_rbuilder_config = OpRbuilderConfig::new()
@@ -79,8 +93,9 @@ impl TestHarnessBuilder {
7993
.network_port(get_available_port())
8094
.http_port(builder_http_port)
8195
.with_builder_private_key(BUILDER_PRIVATE_KEY)
82-
.with_revert_protection(self.use_revert_protection);
83-
96+
.with_revert_protection(self.use_revert_protection)
97+
.with_namespaces(self.namespaces)
98+
.with_extra_params(self.extra_params);
8499
if let Some(flashblocks_ws_url) = self.flashblocks_ws_url {
85100
op_rbuilder_config = op_rbuilder_config.with_flashblocks_ws_url(&flashblocks_ws_url);
86101
}
@@ -113,7 +128,7 @@ impl TestHarnessBuilder {
113128
let builder_log_path = builder.log_path.clone();
114129

115130
Ok(TestHarness {
116-
_framework: framework,
131+
framework: framework,
117132
builder_auth_rpc_port,
118133
builder_http_port,
119134
validator_auth_rpc_port,
@@ -123,7 +138,7 @@ impl TestHarnessBuilder {
123138
}
124139

125140
pub struct TestHarness {
126-
_framework: IntegrationFramework,
141+
framework: IntegrationFramework,
127142
builder_auth_rpc_port: u16,
128143
builder_http_port: u16,
129144
validator_auth_rpc_port: u16,
@@ -237,6 +252,16 @@ impl TestHarness {
237252
}
238253
}
239254

255+
impl Drop for TestHarness {
256+
fn drop(&mut self) {
257+
for service in &mut self.framework.services {
258+
let res = service.stop();
259+
if let Err(e) = res {
260+
println!("Failed to stop service: {}", e);
261+
}
262+
}
263+
}
264+
}
240265
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
241266
pub enum TransactionStatus {
242267
NotFound,

crates/op-rbuilder/src/tests/framework/op.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub struct OpRbuilderConfig {
2727
chain_block_time: Option<u64>,
2828
flashbots_block_time: Option<u64>,
2929
with_revert_protection: Option<bool>,
30+
namespaces: Option<String>,
31+
extra_params: Option<String>,
3032
}
3133

3234
impl OpRbuilderConfig {
@@ -83,6 +85,16 @@ impl OpRbuilderConfig {
8385
self.flashbots_block_time = Some(time);
8486
self
8587
}
88+
89+
pub fn with_namespaces(mut self, namespaces: Option<String>) -> Self {
90+
self.namespaces = namespaces;
91+
self
92+
}
93+
94+
pub fn with_extra_params(mut self, extra_params: Option<String>) -> Self {
95+
self.extra_params = extra_params;
96+
self
97+
}
8698
}
8799

88100
impl Service for OpRbuilderConfig {
@@ -137,9 +149,7 @@ impl Service for OpRbuilderConfig {
137149
if let Some(http_port) = self.http_port {
138150
cmd.arg("--http")
139151
.arg("--http.port")
140-
.arg(http_port.to_string())
141-
.arg("--http.api")
142-
.arg("eth,web3,txpool");
152+
.arg(http_port.to_string());
143153
}
144154

145155
if let Some(flashblocks_ws_url) = &self.flashblocks_ws_url {
@@ -159,6 +169,14 @@ impl Service for OpRbuilderConfig {
159169
.arg(flashbots_block_time.to_string());
160170
}
161171

172+
if let Some(namespaces) = &self.namespaces {
173+
cmd.arg("--http.api").arg(namespaces);
174+
}
175+
176+
if let Some(extra_params) = &self.extra_params {
177+
cmd.args(extra_params.split_ascii_whitespace());
178+
}
179+
162180
cmd
163181
}
164182

0 commit comments

Comments
 (0)