Skip to content

Commit f9ec955

Browse files
committed
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.
1 parent 84ecc91 commit f9ec955

File tree

8 files changed

+93
-27
lines changed

8 files changed

+93
-27
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
@@ -131,6 +131,7 @@ op-alloy-rpc-types-engine = { version = "0.16.0", default-features = false }
131131
op-alloy-rpc-jsonrpsee = { version = "0.16.0", default-features = false }
132132
op-alloy-network = { version = "0.16.0", default-features = false }
133133
op-alloy-consensus = { version = "0.16.0", default-features = false }
134+
op-alloy-flz = { version = "0.13.0", default-features = false }
134135

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

crates/op-rbuilder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ alloy-op-evm.workspace = true
6262
op-alloy-consensus.workspace = true
6363
op-alloy-rpc-types-engine.workspace = true
6464
op-alloy-network.workspace = true
65+
op-alloy-flz.workspace = true
6566

6667
revm.workspace = true
6768
op-revm.workspace = true

crates/op-rbuilder/src/payload_builder_vanilla.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use alloy_consensus::{
88
constants::EMPTY_WITHDRAWALS, transaction::Recovered, Eip658Value, Header, Transaction,
99
TxEip1559, Typed2718, EMPTY_OMMER_ROOT_HASH,
1010
};
11-
use alloy_eips::{eip7685::EMPTY_REQUESTS_HASH, merge::BEACON_NONCE};
11+
use alloy_eips::{eip7685::EMPTY_REQUESTS_HASH, merge::BEACON_NONCE, Encodable2718};
1212
use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
13-
use alloy_primitives::{private::alloy_rlp::Encodable, Address, Bytes, TxHash, TxKind, U256};
13+
use alloy_primitives::{Address, Bytes, TxHash, TxKind, U256};
1414
use alloy_rpc_types_engine::PayloadId;
1515
use alloy_rpc_types_eth::Withdrawals;
1616
use op_alloy_consensus::{OpDepositReceipt, OpTypedTransaction};
@@ -582,15 +582,7 @@ impl<Txs> OpBuilder<'_, Txs> {
582582
let block_da_limit = ctx
583583
.da_config
584584
.max_da_block_size()
585-
.map(|da_size| da_size - builder_tx_da_size as u64);
586-
// Check that it's possible to create builder tx, considering max_da_tx_size, otherwise panic
587-
if let Some(tx_da_limit) = ctx.da_config.max_da_tx_size() {
588-
// Panic indicate max_da_tx_size misconfiguration
589-
assert!(
590-
tx_da_limit >= builder_tx_da_size as u64,
591-
"The configured da_config.max_da_tx_size is too small to accommodate builder tx."
592-
);
593-
}
585+
.map(|da_size| da_size.saturating_sub(builder_tx_da_size));
594586

595587
if !ctx.attributes().no_tx_pool {
596588
let best_txs_start_time = Instant::now();
@@ -1314,7 +1306,7 @@ where
13141306
db: &mut State<DB>,
13151307
builder_tx_gas: u64,
13161308
message: Vec<u8>,
1317-
) -> Option<usize>
1309+
) -> Option<u64>
13181310
where
13191311
DB: Database<Error = ProviderError>,
13201312
{
@@ -1325,7 +1317,9 @@ where
13251317
// Create and sign the transaction
13261318
let builder_tx =
13271319
signed_builder_tx(db, builder_tx_gas, message, signer, base_fee, chain_id)?;
1328-
Ok(builder_tx.length())
1320+
Ok(op_alloy_flz::tx_estimated_size_fjord(
1321+
builder_tx.encoded_2718().as_slice(),
1322+
))
13291323
})
13301324
.transpose()
13311325
.unwrap_or_else(|err: PayloadBuilderError| {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl TestHarnessBuilder {
6666
self.max_da_tx_size = Some(max_da_tx_size);
6767
self
6868
}
69-
69+
7070
pub fn with_max_da_block_size(mut self, max_da_block_size: u64) -> Self {
7171
self.max_da_block_size = Some(max_da_block_size);
7272
self
@@ -93,8 +93,9 @@ impl TestHarnessBuilder {
9393
.network_port(get_available_port())
9494
.http_port(builder_http_port)
9595
.with_builder_private_key(BUILDER_PRIVATE_KEY)
96-
.with_revert_protection(self.use_revert_protection);
97-
96+
.with_revert_protection(self.use_revert_protection)
97+
.with_max_da_block_size(self.max_da_block_size)
98+
.with_max_da_tx_size(self.max_da_tx_size);
9899
if let Some(flashblocks_ws_url) = self.flashblocks_ws_url {
99100
op_rbuilder_config = op_rbuilder_config.with_flashblocks_ws_url(&flashblocks_ws_url);
100101
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ impl OpRbuilderConfig {
8686
self
8787
}
8888

89-
pub fn with_max_da_tx_size(mut self, size: u64) -> Self {
90-
self.max_da_tx_size = Some(size);
89+
pub fn with_max_da_tx_size(mut self, size: Option<u64>) -> Self {
90+
self.max_da_tx_size = size;
9191
self
9292
}
9393

94-
pub fn with_max_da_block_size(mut self, size: u64) -> Self {
95-
self.max_da_block_size = Some(size);
94+
pub fn with_max_da_block_size(mut self, size: Option<u64>) -> Self {
95+
self.max_da_block_size = size;
9696
self
9797
}
9898
}
@@ -168,12 +168,12 @@ impl Service for OpRbuilderConfig {
168168
}
169169

170170
if let Some(max_da_tx_size) = self.max_da_tx_size {
171-
cmd.arg("--rollup.max-da-tx-size")
171+
cmd.arg("--builder.max-da-tx-size")
172172
.arg(max_da_tx_size.to_string());
173173
}
174174

175175
if let Some(max_da_block_size) = self.max_da_block_size {
176-
cmd.arg("--rollup.max-da-block-size")
176+
cmd.arg("--builder.max-da-block-size")
177177
.arg(max_da_block_size.to_string());
178178
}
179179

crates/op-rbuilder/src/tests/vanilla/data_availability.rs

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::tests::framework::{TestHarnessBuilder};
1+
use crate::tests::framework::TestHarnessBuilder;
22

33
/// This test ensures that the transaction size limit is respected.
44
/// We will set limit to 1 byte and see that the builder will not include any transactions.
55
#[tokio::test]
66
async fn data_availability_tx_size_limit() -> eyre::Result<()> {
7-
let harness = TestHarnessBuilder::new("integration_test_data_availability")
7+
let harness = TestHarnessBuilder::new("data_availability_tx_size_limit")
88
.with_max_da_tx_size(1)
99
.build()
1010
.await?;
@@ -17,7 +17,75 @@ async fn data_availability_tx_size_limit() -> eyre::Result<()> {
1717
let block = generator.generate_block().await?;
1818

1919
// tx should not be included because we set the tx_size_limit to 1
20-
assert!(block.not_includes(*invalid_tx.tx_hash()), "transaction should not be included in the block");
21-
20+
assert!(
21+
block.not_includes(*invalid_tx.tx_hash()),
22+
"transaction should not be included in the block"
23+
);
24+
25+
Ok(())
26+
}
27+
28+
/// This test ensures that the block size limit is respected.
29+
/// We will set limit to 1 byte and see that the builder will not include any transactions.
30+
#[tokio::test]
31+
async fn data_availability_block_size_limit() -> eyre::Result<()> {
32+
let harness = TestHarnessBuilder::new("data_availability_block_size_limit")
33+
.with_max_da_block_size(1)
34+
.build()
35+
.await?;
36+
37+
let mut generator = harness.block_generator().await?;
38+
39+
// generate regualr tx
40+
let invalid_tx = harness.send_valid_transaction().await?;
41+
42+
let block = generator.generate_block().await?;
43+
44+
// tx should not be included because we set the tx_size_limit to 1
45+
assert!(
46+
block.not_includes(*invalid_tx.tx_hash()),
47+
"transaction should not be included in the block"
48+
);
49+
50+
Ok(())
51+
}
52+
53+
/// This test ensures that block will fill up to the limit.
54+
/// Size of each transaction is 100000000
55+
/// We will set limit to 3 txs and see that the builder will include 3 transactions.
56+
/// We should not forget about builder transaction so we will spawn only 2 regular txs.
57+
#[tokio::test]
58+
async fn data_availability_block_fill() -> eyre::Result<()> {
59+
let harness = TestHarnessBuilder::new("data_availability_block_fill")
60+
.with_max_da_block_size(100000000 * 3)
61+
.build()
62+
.await?;
63+
64+
let mut generator = harness.block_generator().await?;
65+
66+
// generate regualr tx
67+
let valid_tx_1 = harness.send_valid_transaction().await?;
68+
let valid_tx_2 = harness.send_valid_transaction().await?;
69+
let unfit_tx_3 = harness.send_valid_transaction().await?;
70+
71+
let block = generator.generate_block().await?;
72+
73+
// tx should not be included because we set the tx_size_limit to 1
74+
assert!(
75+
block.includes(*valid_tx_1.tx_hash()),
76+
"tx should be in block"
77+
);
78+
assert!(
79+
block.includes(*valid_tx_2.tx_hash()),
80+
"tx should be in block"
81+
);
82+
assert!(
83+
block.not_includes(*unfit_tx_3.tx_hash()),
84+
"unfit tx should not be in block"
85+
);
86+
assert!(
87+
harness.latest_block().await.transactions.len() == 4,
88+
"builder + deposit + 2 valid txs should be in the block"
89+
);
2290
Ok(())
2391
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![cfg(test)]
22

3+
mod data_availability;
34
mod ordering;
45
mod revert;
56
mod smoke;
6-
mod data_availability;
77

88
use super::*;

0 commit comments

Comments
 (0)