Skip to content

Commit b042d54

Browse files
committed
chore(runner): remove cloning by directly applying extensions
1 parent 6216fdf commit b042d54

File tree

5 files changed

+21
-109
lines changed

5 files changed

+21
-109
lines changed

crates/rpc/tests/eip7702_tests.rs

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! These tests verify that EIP-7702 authorization and delegation
44
//! transactions work correctly in the pending/flashblocks state.
55
6-
use alloy_consensus::{Receipt, SignableTransaction, TxEip1559, TxEip7702};
6+
use alloy_consensus::{SignableTransaction, TxEip1559, TxEip7702};
77
use alloy_eips::{eip2718::Encodable2718, eip7702::Authorization};
88
use alloy_primitives::{Address, B256, Bytes, U256};
99
use alloy_provider::Provider;
@@ -12,13 +12,10 @@ use base_flashtypes::{
1212
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, Flashblock, Metadata,
1313
};
1414
use base_reth_test_utils::{
15-
Account, FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, L1_BLOCK_INFO_DEPOSIT_TX_HASH,
16-
Minimal7702Account, SignerSync,
15+
Account, FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, Minimal7702Account, SignerSync,
1716
};
1817
use eyre::Result;
19-
use op_alloy_consensus::OpDepositReceipt;
2018
use op_alloy_network::ReceiptResponse;
21-
use reth_optimism_primitives::OpReceipt;
2219

2320
/// Cumulative gas used after the base flashblock (deposit tx + contract deployment)
2421
/// This value must be used as the starting point for subsequent flashblocks.
@@ -29,7 +26,6 @@ struct TestSetup {
2926
harness: FlashblocksHarness,
3027
account_contract_address: Address,
3128
account_deploy_tx: Bytes,
32-
account_deploy_hash: B256,
3329
}
3430

3531
impl TestSetup {
@@ -39,10 +35,10 @@ impl TestSetup {
3935

4036
// Deploy Minimal7702Account contract
4137
let deploy_data = Minimal7702Account::BYTECODE.to_vec();
42-
let (account_deploy_tx, account_contract_address, account_deploy_hash) =
38+
let (account_deploy_tx, account_contract_address, _account_deploy_hash) =
4339
deployer.create_deployment_tx(Bytes::from(deploy_data), 0)?;
4440

45-
Ok(Self { harness, account_contract_address, account_deploy_tx, account_deploy_hash })
41+
Ok(Self { harness, account_contract_address, account_deploy_tx })
4642
}
4743

4844
async fn send_flashblock(&self, flashblock: Flashblock) -> Result<()> {
@@ -155,38 +151,11 @@ fn create_base_flashblock(setup: &TestSetup) -> Flashblock {
155151
transactions: vec![L1_BLOCK_INFO_DEPOSIT_TX.clone(), setup.account_deploy_tx.clone()],
156152
..Default::default()
157153
},
158-
metadata: Metadata {
159-
block_number: 1,
160-
receipts: {
161-
let mut receipts = alloy_primitives::map::HashMap::default();
162-
receipts.insert(
163-
L1_BLOCK_INFO_DEPOSIT_TX_HASH,
164-
OpReceipt::Deposit(OpDepositReceipt {
165-
inner: Receipt {
166-
status: true.into(),
167-
cumulative_gas_used: 10000,
168-
logs: vec![],
169-
},
170-
deposit_nonce: Some(4012991u64),
171-
deposit_receipt_version: None,
172-
}),
173-
);
174-
receipts.insert(
175-
setup.account_deploy_hash,
176-
OpReceipt::Eip1559(Receipt {
177-
status: true.into(),
178-
cumulative_gas_used: 500000,
179-
logs: vec![],
180-
}),
181-
);
182-
receipts
183-
},
184-
new_account_balances: alloy_primitives::map::HashMap::default(),
185-
},
154+
metadata: Metadata { block_number: 1 },
186155
}
187156
}
188157

189-
fn create_eip7702_flashblock(eip7702_tx: Bytes, tx_hash: B256, cumulative_gas: u64) -> Flashblock {
158+
fn create_eip7702_flashblock(eip7702_tx: Bytes, cumulative_gas: u64) -> Flashblock {
190159
Flashblock {
191160
payload_id: alloy_rpc_types_engine::PayloadId::new([0; 8]),
192161
index: 1,
@@ -202,22 +171,7 @@ fn create_eip7702_flashblock(eip7702_tx: Bytes, tx_hash: B256, cumulative_gas: u
202171
logs_bloom: Default::default(),
203172
withdrawals_root: Default::default(),
204173
},
205-
metadata: Metadata {
206-
block_number: 1,
207-
receipts: {
208-
let mut receipts = alloy_primitives::map::HashMap::default();
209-
receipts.insert(
210-
tx_hash,
211-
OpReceipt::Eip7702(Receipt {
212-
status: true.into(),
213-
cumulative_gas_used: cumulative_gas,
214-
logs: vec![],
215-
}),
216-
);
217-
receipts
218-
},
219-
new_account_balances: alloy_primitives::map::HashMap::default(),
220-
},
174+
metadata: Metadata { block_number: 1 },
221175
}
222176
}
223177

@@ -252,8 +206,7 @@ async fn test_eip7702_delegation_in_pending_flashblock() -> Result<()> {
252206

253207
// Create flashblock with the EIP-7702 transaction
254208
// Cumulative gas must continue from where the base flashblock left off
255-
let eip7702_flashblock =
256-
create_eip7702_flashblock(eip7702_tx, tx_hash, BASE_CUMULATIVE_GAS + 50000);
209+
let eip7702_flashblock = create_eip7702_flashblock(eip7702_tx, BASE_CUMULATIVE_GAS + 50000);
257210
setup.send_flashblock(eip7702_flashblock).await?;
258211

259212
// Query pending transaction to verify it was included
@@ -307,7 +260,6 @@ async fn test_eip7702_multiple_delegations_same_flashblock() -> Result<()> {
307260

308261
// Create flashblock with both transactions
309262
// Cumulative gas must continue from where the base flashblock left off
310-
let alice_cumulative = BASE_CUMULATIVE_GAS + 50000;
311263
let bob_cumulative = BASE_CUMULATIVE_GAS + 100000;
312264
let flashblock = Flashblock {
313265
payload_id: alloy_rpc_types_engine::PayloadId::new([0; 8]),
@@ -324,30 +276,7 @@ async fn test_eip7702_multiple_delegations_same_flashblock() -> Result<()> {
324276
logs_bloom: Default::default(),
325277
withdrawals_root: Default::default(),
326278
},
327-
metadata: Metadata {
328-
block_number: 1,
329-
receipts: {
330-
let mut receipts = alloy_primitives::map::HashMap::default();
331-
receipts.insert(
332-
tx_hash_alice,
333-
OpReceipt::Eip7702(Receipt {
334-
status: true.into(),
335-
cumulative_gas_used: alice_cumulative,
336-
logs: vec![],
337-
}),
338-
);
339-
receipts.insert(
340-
tx_hash_bob,
341-
OpReceipt::Eip7702(Receipt {
342-
status: true.into(),
343-
cumulative_gas_used: bob_cumulative,
344-
logs: vec![],
345-
}),
346-
);
347-
receipts
348-
},
349-
new_account_balances: alloy_primitives::map::HashMap::default(),
350-
},
279+
metadata: Metadata { block_number: 1 },
351280
};
352281

353282
setup.send_flashblock(flashblock).await?;
@@ -388,8 +317,7 @@ async fn test_eip7702_pending_receipt() -> Result<()> {
388317

389318
let tx_hash = alloy_primitives::keccak256(&eip7702_tx);
390319
// Cumulative gas must continue from where the base flashblock left off
391-
let eip7702_flashblock =
392-
create_eip7702_flashblock(eip7702_tx, tx_hash, BASE_CUMULATIVE_GAS + 50000);
320+
let eip7702_flashblock = create_eip7702_flashblock(eip7702_tx, BASE_CUMULATIVE_GAS + 50000);
393321
setup.send_flashblock(eip7702_flashblock).await?;
394322

395323
// Query receipt from pending state
@@ -430,8 +358,7 @@ async fn test_eip7702_delegation_then_execution() -> Result<()> {
430358
);
431359

432360
let delegation_hash = alloy_primitives::keccak256(&delegation_tx);
433-
let delegation_flashblock =
434-
create_eip7702_flashblock(delegation_tx, delegation_hash, delegation_cumulative);
361+
let delegation_flashblock = create_eip7702_flashblock(delegation_tx, delegation_cumulative);
435362
setup.send_flashblock(delegation_flashblock).await?;
436363

437364
// Second flashblock: execute through delegated account
@@ -467,22 +394,7 @@ async fn test_eip7702_delegation_then_execution() -> Result<()> {
467394
logs_bloom: Default::default(),
468395
withdrawals_root: Default::default(),
469396
},
470-
metadata: Metadata {
471-
block_number: 1,
472-
receipts: {
473-
let mut receipts = alloy_primitives::map::HashMap::default();
474-
receipts.insert(
475-
execution_hash,
476-
OpReceipt::Eip1559(Receipt {
477-
status: true.into(),
478-
cumulative_gas_used: execution_cumulative,
479-
logs: vec![],
480-
}),
481-
);
482-
receipts
483-
},
484-
new_account_balances: alloy_primitives::map::HashMap::default(),
485-
},
397+
metadata: Metadata { block_number: 1 },
486398
};
487399

488400
setup.send_flashblock(execution_flashblock).await?;

crates/runner/src/extensions/canon.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ impl FlashblocksCanonExtension {
3030

3131
impl BaseNodeExtension for FlashblocksCanonExtension {
3232
/// Applies the extension to the supplied builder.
33-
fn apply(&self, builder: OpBuilder) -> OpBuilder {
34-
let flashblocks = self.config.clone();
33+
fn apply(self: Box<Self>, builder: OpBuilder) -> OpBuilder {
34+
let flashblocks = self.config;
3535
let flashblocks_enabled = flashblocks.is_some();
36-
let flashblocks_cell = self.cell.clone();
36+
let flashblocks_cell = self.cell;
3737

3838
builder.install_exex_if(flashblocks_enabled, "flashblocks-canon", move |mut ctx| {
3939
let flashblocks_cell = flashblocks_cell.clone();

crates/runner/src/extensions/extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{BaseNodeConfig, extensions::OpBuilder};
99
/// A node builder extension that can apply additional wiring to the builder.
1010
pub trait BaseNodeExtension: Send + Sync + Debug {
1111
/// Applies the extension to the supplied builder.
12-
fn apply(&self, builder: OpBuilder) -> OpBuilder;
12+
fn apply(self: Box<Self>, builder: OpBuilder) -> OpBuilder;
1313
}
1414

1515
/// An extension that can be constructed from [`BaseNodeConfig`].

crates/runner/src/extensions/rpc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ impl BaseRpcExtension {
4242

4343
impl BaseNodeExtension for BaseRpcExtension {
4444
/// Applies the extension to the supplied builder.
45-
fn apply(&self, builder: OpBuilder) -> OpBuilder {
46-
let flashblocks_cell = self.flashblocks_cell.clone();
47-
let flashblocks = self.flashblocks.clone();
45+
fn apply(self: Box<Self>, builder: OpBuilder) -> OpBuilder {
46+
let flashblocks_cell = self.flashblocks_cell;
47+
let flashblocks = self.flashblocks;
4848
let metering_enabled = self.metering_enabled;
49-
let sequencer_rpc = self.sequencer_rpc.clone();
49+
let sequencer_rpc = self.sequencer_rpc;
5050

5151
builder.extend_rpc_modules(move |ctx| {
5252
if metering_enabled {

crates/runner/src/extensions/tracing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl TransactionTracingExtension {
2424

2525
impl BaseNodeExtension for TransactionTracingExtension {
2626
/// Applies the extension to the supplied builder.
27-
fn apply(&self, builder: OpBuilder) -> OpBuilder {
27+
fn apply(self: Box<Self>, builder: OpBuilder) -> OpBuilder {
2828
let tracing = self.config;
2929
builder.install_exex_if(tracing.enabled, "tracex", move |ctx| async move {
3030
Ok(tracex_exex(ctx, tracing.logs_enabled))

0 commit comments

Comments
 (0)