Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable l1 data gas cost in --dev mode #10332

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct OpTransactionValidator<Client, Tx> {
inner: EthTransactionValidator<Client, Tx>,
/// Additional block info required for validation.
block_info: Arc<OpL1BlockInfo>,
/// 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<Client, Tx> OpTransactionValidator<Client, Tx> {
Expand All @@ -41,6 +45,18 @@ impl<Client, Tx> OpTransactionValidator<Client, Tx> {
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<Client, Tx> OpTransactionValidator<Client, Tx>
Expand Down Expand Up @@ -71,7 +87,7 @@ where
inner: EthTransactionValidator<Client, Tx>,
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.
Expand Down Expand Up @@ -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 {
Comment on lines +121 to 127
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would prefer to do if self.requires_l1_data_gas_fee() { and check the data gas fee inside the clause, so that if we add something after balance check for l1 gas cost, we don't short circuit here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense when we need additional checks but currently this is the only thing we're checking

balance,
Expand Down
Loading