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: use alloy traits for PoolTransaction #14228

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ impl PooledTransactionsHashesBuilder {
Self::Eth68(msg) => {
msg.hashes.push(*pooled_tx.hash());
msg.sizes.push(pooled_tx.encoded_length());
msg.types.push(pooled_tx.transaction.tx_type());
msg.types.push(pooled_tx.transaction.ty());
}
}
}
Expand Down
100 changes: 57 additions & 43 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
use alloy_consensus::{
BlobTransactionSidecar, BlobTransactionValidationError, BlockHeader, Transaction, Typed2718,
};
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{Address, TxHash, TxKind, U256};
use op_alloy_consensus::OpTypedTransaction;
use alloy_eips::{eip2718::Encodable2718, eip7702::SignedAuthorization};
use alloy_primitives::{Address, Bytes, TxHash, TxKind, B256, U256};
use parking_lot::RwLock;
use reth_node_api::{Block, BlockBody};
use reth_optimism_evm::RethL1BlockInfo;
Expand All @@ -14,7 +13,7 @@ use reth_primitives::{
transaction::TransactionConversionError, GotExpected, InvalidTransactionError, Recovered,
SealedBlock,
};
use reth_primitives_traits::SignedTransaction;
use reth_primitives_traits::{InMemorySize, SignedTransaction};
use reth_provider::{BlockReaderIdExt, ChainSpecProvider, StateProviderFactory};
use reth_revm::L1BlockInfo;
use reth_transaction_pool::{
Expand Down Expand Up @@ -123,68 +122,94 @@ impl PoolTransaction for OpPooledTransaction {
self.inner.transaction.signer_ref()
}

fn nonce(&self) -> u64 {
self.inner.transaction.nonce()
}

fn cost(&self) -> &U256 {
&self.inner.cost
}

fn encoded_length(&self) -> usize {
self.inner.encoded_length
}
}

impl Typed2718 for OpPooledTransaction {
fn ty(&self) -> u8 {
self.inner.ty()
}
}

impl InMemorySize for OpPooledTransaction {
fn size(&self) -> usize {
self.inner.size()
}
}

impl alloy_consensus::Transaction for OpPooledTransaction {
fn chain_id(&self) -> Option<alloy_primitives::ChainId> {
self.inner.chain_id()
}

fn nonce(&self) -> u64 {
self.inner.nonce()
}

fn gas_limit(&self) -> u64 {
self.inner.transaction.gas_limit()
self.inner.gas_limit()
}

fn max_fee_per_gas(&self) -> u128 {
self.inner.transaction.max_fee_per_gas()
fn gas_price(&self) -> Option<u128> {
self.inner.gas_price()
}

fn access_list(&self) -> Option<&AccessList> {
self.inner.transaction.access_list()
fn max_fee_per_gas(&self) -> u128 {
self.inner.max_fee_per_gas()
}

fn max_priority_fee_per_gas(&self) -> Option<u128> {
self.inner.transaction.max_priority_fee_per_gas()
self.inner.max_priority_fee_per_gas()
}

fn max_fee_per_blob_gas(&self) -> Option<u128> {
self.inner.transaction.max_fee_per_blob_gas()
self.inner.max_fee_per_blob_gas()
}

fn effective_tip_per_gas(&self, base_fee: u64) -> Option<u128> {
self.inner.transaction.effective_tip_per_gas(base_fee)
fn priority_fee_or_price(&self) -> u128 {
self.inner.priority_fee_or_price()
}

fn priority_fee_or_price(&self) -> u128 {
self.inner.transaction.priority_fee_or_price()
fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
self.inner.effective_gas_price(base_fee)
}

fn is_dynamic_fee(&self) -> bool {
self.inner.is_dynamic_fee()
}

fn kind(&self) -> TxKind {
self.inner.transaction.kind()
self.inner.kind()
}

fn is_create(&self) -> bool {
self.inner.transaction.is_create()
self.inner.is_create()
}

fn input(&self) -> &[u8] {
self.inner.transaction.input()
fn value(&self) -> U256 {
self.inner.value()
}

fn size(&self) -> usize {
self.inner.transaction.input().len()
fn input(&self) -> &Bytes {
self.inner.input()
}

fn tx_type(&self) -> u8 {
self.inner.transaction.ty()
fn access_list(&self) -> Option<&AccessList> {
self.inner.access_list()
}

fn encoded_length(&self) -> usize {
self.inner.encoded_length
fn blob_versioned_hashes(&self) -> Option<&[B256]> {
self.inner.blob_versioned_hashes()
}

fn chain_id(&self) -> Option<u64> {
self.inner.transaction.chain_id()
fn authorization_list(&self) -> Option<&[SignedAuthorization]> {
self.inner.authorization_list()
}
}

Expand All @@ -193,10 +218,6 @@ impl EthPoolTransaction for OpPooledTransaction {
EthBlobTransactionSidecar::None
}

fn blob_count(&self) -> usize {
0
}

fn try_into_pooled_eip4844(
self,
_sidecar: Arc<BlobTransactionSidecar>,
Expand All @@ -216,14 +237,7 @@ impl EthPoolTransaction for OpPooledTransaction {
_sidecar: &BlobTransactionSidecar,
_settings: &KzgSettings,
) -> Result<(), BlobTransactionValidationError> {
Err(BlobTransactionValidationError::NotBlobTransaction(self.tx_type()))
}

fn authorization_count(&self) -> usize {
match self.inner.transaction.transaction() {
OpTypedTransaction::Eip7702(tx) => tx.authorization_list.len(),
_ => 0,
}
Err(BlobTransactionValidationError::NotBlobTransaction(self.ty()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/benches/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn generate_test_data(

mod implementations {
use super::*;
use reth_transaction_pool::PoolTransaction;
use alloy_consensus::Transaction;
use std::collections::BinaryHeap;

/// This implementation appends the transactions and uses [`Vec::sort_by`] function for sorting.
Expand Down
2 changes: 2 additions & 0 deletions crates/transaction-pool/src/pool/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::{
pool::pending::PendingTransaction,
PoolTransaction, TransactionOrdering, ValidPoolTransaction,
};
use alloy_consensus::Transaction;
use alloy_eips::Typed2718;
use alloy_primitives::Address;
use core::fmt;
use reth_payload_util::PayloadTransactions;
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) struct BlobTransactions<T: PoolTransaction> {
pending_fees: PendingFees,
/// Keeps track of the size of this pool.
///
/// See also [`PoolTransaction::size`].
/// See also [`reth_primitives_traits::InMemorySize::size`].
size_of: SizeTracker,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use reth_eth_wire_types::HandleMempoolData;
use reth_execution_types::ChangedAccount;

use alloy_eips::eip4844::BlobTransactionSidecar;
use alloy_eips::{eip4844::BlobTransactionSidecar, Typed2718};
use reth_primitives::Recovered;
use rustc_hash::FxHashMap;
use std::{collections::HashSet, fmt, sync::Arc, time::Instant};
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/pool/parked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct ParkedPool<T: ParkedOrd> {
sender_transaction_count: FxHashMap<SenderId, SenderTransactionCount>,
/// Keeps track of the size of this pool.
///
/// See also [`PoolTransaction::size`].
/// See also [`reth_primitives_traits::InMemorySize::size`].
size_of: SizeTracker,
}

Expand Down Expand Up @@ -520,6 +520,7 @@ impl<T: PoolTransaction> Ord for QueuedOrd<T> {
mod tests {
use super::*;
use crate::test_utils::{MockTransaction, MockTransactionFactory, MockTransactionSet};
use alloy_consensus::Transaction;
use alloy_primitives::address;
use reth_primitives::TxType;
use std::collections::HashSet;
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/pool/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct PendingPool<T: TransactionOrdering> {
independent_transactions: FxHashMap<SenderId, PendingTransaction<T>>,
/// Keeps track of the size of this pool.
///
/// See also [`PoolTransaction::size`](crate::traits::PoolTransaction::size).
/// See also [`reth_primitives_traits::InMemorySize::size`].
size_of: SizeTracker,
/// Used to broadcast new transactions that have been added to the `PendingPool` to existing
/// `static_files` of this pool.
Expand Down Expand Up @@ -613,6 +613,7 @@ mod tests {
test_utils::{MockOrdering, MockTransaction, MockTransactionFactory, MockTransactionSet},
PoolTransaction,
};
use alloy_consensus::Transaction;
use alloy_primitives::address;
use reth_primitives::TxType;
use std::collections::HashSet;
Expand Down
4 changes: 3 additions & 1 deletion crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use alloy_consensus::constants::{
use alloy_eips::{
eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE},
eip4844::BLOB_TX_MIN_BLOB_GASPRICE,
Typed2718,
};
use alloy_primitives::{Address, TxHash, B256};
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -571,7 +572,7 @@ impl<T: TransactionOrdering> TxPool<T> {
let mut eip7702_count = 0;

for tx in self.all_transactions.transactions_iter() {
match tx.transaction.tx_type() {
match tx.transaction.ty() {
LEGACY_TX_TYPE_ID => legacy_count += 1,
EIP2930_TX_TYPE_ID => eip2930_count += 1,
EIP1559_TX_TYPE_ID => eip1559_count += 1,
Expand Down Expand Up @@ -1978,6 +1979,7 @@ mod tests {
traits::TransactionOrigin,
SubPoolLimit,
};
use alloy_consensus::Transaction;
use alloy_primitives::address;
use reth_primitives::TxType;

Expand Down
Loading
Loading