From 6eca0e74e9852f1e4e2d3c870526793c8fdeb904 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 15 Aug 2024 12:45:01 -0700 Subject: [PATCH] feat: disable l1 data gas cost in --dev mode --- crates/optimism/node/src/node.rs | 7 ++++++- crates/optimism/node/src/txpool.rs | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index ac7711dd2ee9..e276ccdd5435 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -161,7 +161,12 @@ where ctx.task_executor().clone(), blob_store.clone(), ) - .map(OpTransactionValidator::new); + .map(|validator| { + OpTransactionValidator::new(validator) + // In --dev mode we can't require gas fees because we're unable to decode the L1 + // block info + .require_l1_data_gas_fee(!ctx.config().dev.dev) + }); let transaction_pool = reth_transaction_pool::Pool::new( validator, diff --git a/crates/optimism/node/src/txpool.rs b/crates/optimism/node/src/txpool.rs index 3edc5dc0b47c..6f9e6475052d 100644 --- a/crates/optimism/node/src/txpool.rs +++ b/crates/optimism/node/src/txpool.rs @@ -29,6 +29,10 @@ pub struct OpTransactionValidator { inner: EthTransactionValidator, /// Additional block info required for validation. block_info: Arc, + /// If true, ensure that the transaction's sender has enough balance to cover the L1 gas fee + /// derived from the tracked L1 block info that is extracted from the first transaction in the + /// L2 block. + require_l1_data_gas_fee: bool, } impl OpTransactionValidator { @@ -41,6 +45,18 @@ impl OpTransactionValidator { fn block_timestamp(&self) -> u64 { self.block_info.timestamp.load(Ordering::Relaxed) } + + /// Whether to ensure that the transaction's sender has enough balance to also cover the L1 gas + /// fee. + pub fn require_l1_data_gas_fee(self, require_l1_data_gas_fee: bool) -> Self { + Self { require_l1_data_gas_fee, ..self } + } + + /// Returns whether this validator also requires the transaction's sender to have enough balance + /// to cover the L1 gas fee. + pub const fn requires_l1_data_gas_fee(&self) -> bool { + self.require_l1_data_gas_fee + } } impl OpTransactionValidator @@ -71,7 +87,7 @@ where inner: EthTransactionValidator, block_info: OpL1BlockInfo, ) -> Self { - Self { inner, block_info: Arc::new(block_info) } + Self { inner, block_info: Arc::new(block_info), require_l1_data_gas_fee: true } } /// Update the L1 block info. @@ -102,6 +118,11 @@ where let outcome = self.inner.validate_one(origin, transaction); + if !self.requires_l1_data_gas_fee() { + // no need to check L1 gas fee + return outcome + } + // ensure that the account has enough balance to cover the L1 gas cost if let TransactionValidationOutcome::Valid { balance,