fix: use cached encoded length (#4577)

This commit is contained in:
Matthias Seitz
2023-09-14 00:04:02 +02:00
committed by GitHub
parent c531c1b60a
commit c831d30d2d

View File

@ -22,7 +22,6 @@ use reth_primitives::{
FromRecoveredPooledTransaction, IntoRecoveredTransaction, PeerId, PooledTransactionsElement,
TransactionSigned, TxHash, H256,
};
use reth_rlp::Encodable;
use reth_transaction_pool::{
error::PoolResult, GetPooledTransactionLimit, PoolTransaction, PropagateKind,
PropagatedTransactions, TransactionPool, ValidPoolTransaction,
@ -205,7 +204,7 @@ where
}
}
/// Invoked when a new transaction is pending.
/// Invoked when a new transaction is pending in the local pool.
///
/// When new transactions appear in the pool, we propagate them to the network using the
/// `Transactions` and `NewPooledTransactionHashes` messages. The Transactions message relays
@ -224,15 +223,10 @@ where
trace!(target: "net::tx", "Start propagating transactions");
// This fetches all transaction from the pool, including the blob transactions, which are
// only ever sent as hashes.
let propagated = self.propagate_transactions(
self.pool
.get_all(hashes)
.into_iter()
.map(|tx| {
let tx = Arc::new(tx.transaction.to_recovered_transaction().into_signed());
PropagateTransaction::new(tx)
})
.collect(),
self.pool.get_all(hashes).into_iter().map(PropagateTransaction::new).collect(),
);
// notify pool so events get fired
@ -672,8 +666,11 @@ impl PropagateTransaction {
self.transaction.hash()
}
fn new(transaction: Arc<TransactionSigned>) -> Self {
Self { size: transaction.length(), transaction }
/// Create a new instance from a pooled transaction
fn new<T: PoolTransaction>(tx: Arc<ValidPoolTransaction<T>>) -> Self {
let size = tx.encoded_length;
let transaction = Arc::new(tx.transaction.to_recovered_transaction().into_signed());
Self { size, transaction }
}
}