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

chore: relax eth pooled tx #13271

Merged
merged 3 commits into from
Dec 12, 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
20 changes: 11 additions & 9 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,9 @@ pub trait EthPoolTransaction: PoolTransaction {
/// This type is essentially a wrapper around [`RecoveredTx`] with additional
/// fields derived from the transaction that are frequently used by the pools for ordering.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EthPooledTransaction<T = RecoveredTx> {
pub struct EthPooledTransaction<T = TransactionSigned> {
/// `EcRecovered` transaction, the consensus format.
pub(crate) transaction: T,
pub(crate) transaction: RecoveredTx<T>,

/// For EIP-1559 transactions: `max_fee_per_gas * gas_limit + tx_value`.
/// For legacy transactions: `gas_price * gas_limit + tx_value`.
Expand All @@ -1197,23 +1197,25 @@ pub struct EthPooledTransaction<T = RecoveredTx> {
pub(crate) blob_sidecar: EthBlobTransactionSidecar,
}

impl EthPooledTransaction {
impl<T: SignedTransaction> EthPooledTransaction<T> {
/// Create new instance of [Self].
///
/// Caution: In case of blob transactions, this does marks the blob sidecar as
/// [`EthBlobTransactionSidecar::Missing`]
pub fn new(transaction: RecoveredTx, encoded_length: usize) -> Self {
pub fn new(transaction: RecoveredTx<T>, encoded_length: usize) -> Self {
let mut blob_sidecar = EthBlobTransactionSidecar::None;

let gas_cost = U256::from(transaction.transaction.max_fee_per_gas())
.saturating_mul(U256::from(transaction.transaction.gas_limit()));
let gas_cost = U256::from(transaction.max_fee_per_gas())
.saturating_mul(U256::from(transaction.gas_limit()));

let mut cost = gas_cost.saturating_add(transaction.value());

if let Some(blob_tx) = transaction.as_eip4844() {
if let (Some(blob_gas_used), Some(max_fee_per_blob_gas)) =
(transaction.blob_gas_used(), transaction.max_fee_per_blob_gas())
{
// 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),
max_fee_per_blob_gas.saturating_mul(blob_gas_used as u128),
));

// because the blob sidecar is not included in this transaction variant, mark it as
Expand All @@ -1225,7 +1227,7 @@ impl EthPooledTransaction {
}

/// Return the reference to the underlying transaction.
pub const fn transaction(&self) -> &RecoveredTx {
pub const fn transaction(&self) -> &RecoveredTx<T> {
&self.transaction
}
}
Expand Down
Loading