From 03b74657bdbd2340d70c8a1dbc4576014cbc6921 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:23:27 +0200 Subject: [PATCH] fix: max tx cost calculation for blobs --- bolt-sidecar/src/common.rs | 13 +++++++++++-- bolt-sidecar/src/state/execution.rs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bolt-sidecar/src/common.rs b/bolt-sidecar/src/common.rs index e73c8dbd..29476f51 100644 --- a/bolt-sidecar/src/common.rs +++ b/bolt-sidecar/src/common.rs @@ -29,11 +29,20 @@ pub fn calculate_max_basefee(current: u128, block_diff: u64) -> Option { } /// Calculates the max transaction cost (gas + value) in wei. +/// +/// - For EIP-1559 transactions: `max_fee_per_gas * gas_limit + tx_value`. +/// - For legacy transactions: `gas_price * gas_limit + tx_value`. +/// - For EIP-4844 blob transactions: `max_fee_per_gas * gas_limit + tx_value + +/// max_blob_fee_per_gas * blob_gas_used`. pub fn max_transaction_cost(transaction: &PooledTransactionsElement) -> U256 { let gas_limit = transaction.gas_limit() as u128; - let fee_cap = transaction.max_fee_per_gas(); - let fee_cap = fee_cap + transaction.max_priority_fee_per_gas().unwrap_or(0); + let mut fee_cap = transaction.max_fee_per_gas(); + fee_cap += transaction.max_priority_fee_per_gas().unwrap_or(0); + + if let Some(eip4844) = transaction.as_eip4844() { + fee_cap += eip4844.max_fee_per_blob_gas + eip4844.blob_gas() as u128; + } U256::from(gas_limit * fee_cap) + transaction.value() } diff --git a/bolt-sidecar/src/state/execution.rs b/bolt-sidecar/src/state/execution.rs index 6ba0b28b..60510457 100644 --- a/bolt-sidecar/src/state/execution.rs +++ b/bolt-sidecar/src/state/execution.rs @@ -245,7 +245,7 @@ impl ExecutionState { let max_basefee = calculate_max_basefee(self.basefee, slot_diff) .ok_or(ValidationError::MaxBaseFeeCalcOverflow)?; - tracing::debug!(%slot_diff, %max_basefee, "Validating basefee"); + tracing::debug!(%slot_diff, basefee = self.basefee, %max_basefee, "Validating basefee"); // Validate the base fee if !req.validate_basefee(max_basefee) {