Skip to content

Commit

Permalink
fix: max tx cost calculation for blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Jul 18, 2024
1 parent d179cdd commit 03b7465
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions bolt-sidecar/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ pub fn calculate_max_basefee(current: u128, block_diff: u64) -> Option<u128> {
}

/// 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()
}
Expand Down
2 changes: 1 addition & 1 deletion bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<C: StateFetcher> ExecutionState<C> {
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) {
Expand Down

0 comments on commit 03b7465

Please sign in to comment.