mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: sat math for tx value (#6900)
This commit is contained in:
@ -918,22 +918,30 @@ impl EthPooledTransaction {
|
||||
pub fn new(transaction: TransactionSignedEcRecovered, encoded_length: usize) -> Self {
|
||||
let mut blob_sidecar = EthBlobTransactionSidecar::None;
|
||||
let gas_cost = match &transaction.transaction {
|
||||
Transaction::Legacy(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip2930(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip1559(t) => U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit),
|
||||
Transaction::Legacy(t) => {
|
||||
U256::from(t.gas_price).saturating_mul(U256::from(t.gas_limit))
|
||||
}
|
||||
Transaction::Eip2930(t) => {
|
||||
U256::from(t.gas_price).saturating_mul(U256::from(t.gas_limit))
|
||||
}
|
||||
Transaction::Eip1559(t) => {
|
||||
U256::from(t.max_fee_per_gas).saturating_mul(U256::from(t.gas_limit))
|
||||
}
|
||||
Transaction::Eip4844(t) => {
|
||||
blob_sidecar = EthBlobTransactionSidecar::Missing;
|
||||
U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit)
|
||||
U256::from(t.max_fee_per_gas).saturating_mul(U256::from(t.gas_limit))
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Transaction::Deposit(_) => U256::ZERO,
|
||||
};
|
||||
let mut cost: U256 = transaction.value();
|
||||
cost += gas_cost;
|
||||
let mut cost = transaction.value();
|
||||
cost = cost.saturating_add(gas_cost);
|
||||
|
||||
if let Some(blob_tx) = transaction.as_eip4844() {
|
||||
// add max blob cost
|
||||
cost += U256::from(blob_tx.max_fee_per_blob_gas * blob_tx.blob_gas() as u128);
|
||||
// Add max blob cost using saturating math to avoid overflow
|
||||
cost = cost.saturating_add(U256::from(
|
||||
blob_tx.max_fee_per_blob_gas.saturating_mul(blob_tx.blob_gas() as u128),
|
||||
));
|
||||
}
|
||||
|
||||
Self { transaction, cost, encoded_length, blob_sidecar }
|
||||
|
||||
Reference in New Issue
Block a user