feat: add blob costs to cost value (#4489)

This commit is contained in:
Matthias Seitz
2023-09-05 21:12:42 +02:00
committed by GitHub
parent 01d4933125
commit ca3753d53f
2 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,5 @@
use crate::{
compression::{TRANSACTION_COMPRESSOR, TRANSACTION_DECOMPRESSOR},
constants::eip4844::DATA_GAS_PER_BLOB,
keccak256, Address, Bytes, TxHash, H256,
};
pub use access_list::{AccessList, AccessListItem, AccessListWithGasUsed};
@ -236,10 +235,10 @@ impl Transaction {
/// Returns the blob gas used for all blobs of the EIP-4844 transaction if it is an EIP-4844
/// transaction.
///
/// This is the number of blobs times the [DATA_GAS_PER_BLOB] a single blob consumes.
pub fn blob_gas_used(&self) -> Option<u128> {
let tx = self.as_eip4844()?;
Some(tx.blob_versioned_hashes.len() as u128 * DATA_GAS_PER_BLOB as u128)
/// This is the number of blobs times the
/// [DATA_GAS_PER_BLOB](crate::constants::eip4844::DATA_GAS_PER_BLOB) a single blob consumes.
pub fn blob_gas_used(&self) -> Option<u64> {
self.as_eip4844().map(TxEip4844::blob_gas)
}
/// Return the max priority fee per gas if the transaction is an EIP-1559 transaction, and

View File

@ -629,6 +629,8 @@ pub trait PoolTransaction:
///
/// 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`.
fn cost(&self) -> U256;
/// Amount of gas that should be used in executing this transaction. This is paid up-front.
@ -721,6 +723,8 @@ pub struct EthPooledTransaction {
/// 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(crate) cost: U256,
/// The blob side car this transaction
@ -754,7 +758,12 @@ impl EthPooledTransaction {
U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit)
}
};
let cost = gas_cost + U256::from(transaction.value());
let mut cost = gas_cost + U256::from(transaction.value());
if let Some(blob_tx) = transaction.as_eip4844() {
// add max blob cost
cost += U256::from(blob_tx.max_fee_per_gas * blob_tx.blob_gas() as u128);
}
Self { transaction, cost, blob_sidecar }
}
@ -806,6 +815,8 @@ impl PoolTransaction for EthPooledTransaction {
///
/// 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`.
fn cost(&self) -> U256 {
self.cost
}