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(txpool): pooled tx constructor #3980

Merged
merged 1 commit into from
Jul 28, 2023
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
21 changes: 13 additions & 8 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,18 @@ pub struct PooledTransaction {
}

impl PooledTransaction {
/// Create new instance of [Self].
pub fn new(transaction: TransactionSignedEcRecovered) -> Self {
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),
};
let cost = gas_cost + U256::from(transaction.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we continue to need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cost is hot loaded in pool update fn. don't mind leaving this


Self { transaction, cost }
}

/// Return the reference to the underlying transaction.
pub fn transaction(&self) -> &TransactionSignedEcRecovered {
&self.transaction
Expand Down Expand Up @@ -634,14 +646,7 @@ impl PoolTransaction for PooledTransaction {

impl FromRecoveredTransaction for PooledTransaction {
fn from_recovered_transaction(tx: TransactionSignedEcRecovered) -> Self {
let gas_cost = match &tx.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),
};
let cost = gas_cost + U256::from(tx.value());

PooledTransaction { transaction: tx, cost }
PooledTransaction::new(tx)
}
}

Expand Down