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: add blob_gas_used #1704

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
10 changes: 10 additions & 0 deletions crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub use eip7702::TxEip7702;
/// [EIP-4844] constants, helpers, and types.
pub mod eip4844;

use alloy_eips::eip4844::DATA_GAS_PER_BLOB;
pub use alloy_eips::eip4844::{
builder::{SidecarBuilder, SidecarCoder, SimpleCoder},
utils as eip4844_utils, Blob, BlobTransactionSidecar, Bytes48,
Expand Down Expand Up @@ -158,6 +159,15 @@ pub trait Transaction: fmt::Debug + any::Any + Send + Sync + 'static {
/// `None`.
fn blob_versioned_hashes(&self) -> Option<&[B256]>;

/// Returns the total gas for all blobs in this transaction.
///
/// Returns `None` for non-eip4844 transactions.
#[inline]
fn blob_gas_used(&self) -> Option<u64> {
// SAFETY: we don't expect u64::MAX / DATA_GAS_PER_BLOB hashes in a single transaction
self.blob_versioned_hashes().map(|blobs| blobs.len() as u64 * DATA_GAS_PER_BLOB)
}

/// Returns the [`SignedAuthorization`] list of the transaction.
///
/// Returns `None` if this transaction is not EIP-7702.
Expand Down