diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 6fd8fb55a6d9..aaa6b82dc4ef 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1624,6 +1624,11 @@ impl RecoveredTx { self.signer } + /// Reference to the signer of transaction recovered from signature + pub const fn signer_ref(&self) -> &Address { + &self.signer + } + /// Returns a reference to [`TransactionSigned`] pub const fn as_signed(&self) -> &T { &self.signed_transaction diff --git a/crates/transaction-pool/src/config.rs b/crates/transaction-pool/src/config.rs index 212df34bd371..a9603215c834 100644 --- a/crates/transaction-pool/src/config.rs +++ b/crates/transaction-pool/src/config.rs @@ -196,15 +196,15 @@ impl LocalTransactionConfig { /// Returns whether the local addresses vector contains the given address. #[inline] - pub fn contains_local_address(&self, address: Address) -> bool { - self.local_addresses.contains(&address) + pub fn contains_local_address(&self, address: &Address) -> bool { + self.local_addresses.contains(address) } /// Returns whether the particular transaction should be considered local. /// /// This always returns false if the local exemptions are disabled. #[inline] - pub fn is_local(&self, origin: TransactionOrigin, sender: Address) -> bool { + pub fn is_local(&self, origin: TransactionOrigin, sender: &Address) -> bool { if self.no_local_exemptions() { return false } @@ -286,10 +286,10 @@ mod tests { let config = LocalTransactionConfig { local_addresses, ..Default::default() }; // Should contain the inserted address - assert!(config.contains_local_address(address)); + assert!(config.contains_local_address(&address)); // Should not contain another random address - assert!(!config.contains_local_address(Address::new([2; 20]))); + assert!(!config.contains_local_address(&Address::new([2; 20]))); } #[test] @@ -302,7 +302,7 @@ mod tests { }; // Should return false as no exemptions is set to true - assert!(!config.is_local(TransactionOrigin::Local, address)); + assert!(!config.is_local(TransactionOrigin::Local, &address)); } #[test] @@ -315,13 +315,13 @@ mod tests { LocalTransactionConfig { no_exemptions: false, local_addresses, ..Default::default() }; // Should return true as the transaction origin is local - assert!(config.is_local(TransactionOrigin::Local, Address::new([2; 20]))); - assert!(config.is_local(TransactionOrigin::Local, address)); + assert!(config.is_local(TransactionOrigin::Local, &Address::new([2; 20]))); + assert!(config.is_local(TransactionOrigin::Local, &address)); // Should return true as the address is in the local_addresses set - assert!(config.is_local(TransactionOrigin::External, address)); + assert!(config.is_local(TransactionOrigin::External, &address)); // Should return false as the address is not in the local_addresses set - assert!(!config.is_local(TransactionOrigin::External, Address::new([2; 20]))); + assert!(!config.is_local(TransactionOrigin::External, &Address::new([2; 20]))); } #[test] diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 86bf5f741c3d..c9d4e0a488e3 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1462,7 +1462,7 @@ impl AllTransactions { transaction: ValidPoolTransaction, on_chain_nonce: u64, ) -> Result, InsertErr> { - if !self.local_transactions_config.is_local(transaction.origin, transaction.sender()) { + if !self.local_transactions_config.is_local(transaction.origin, transaction.sender_ref()) { let current_txs = self.tx_counter.get(&transaction.sender_id()).copied().unwrap_or_default(); diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index 471956fdca57..0e8b26faf83b 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -624,6 +624,10 @@ impl PoolTransaction for MockTransaction { *self.get_sender() } + fn sender_ref(&self) -> &Address { + self.get_sender() + } + fn nonce(&self) -> u64 { *self.get_nonce() } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 6d4d562b3bdf..15f824e7d436 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -1023,6 +1023,9 @@ pub trait PoolTransaction: /// The Sender of the transaction. fn sender(&self) -> Address; + /// Reference to the Sender of the transaction. + fn sender_ref(&self) -> &Address; + /// Returns the nonce for this transaction. fn nonce(&self) -> u64; @@ -1277,6 +1280,11 @@ impl PoolTransaction for EthPooledTransaction { self.transaction.signer() } + /// Returns a reference to the Sender of the transaction. + fn sender_ref(&self) -> &Address { + self.transaction.signer_ref() + } + /// Returns the nonce for this transaction. fn nonce(&self) -> u64 { self.transaction.nonce() diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index 5249c1befa2c..e3b7af736cd8 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -263,7 +263,7 @@ where // Drop non-local transactions with a fee lower than the configured fee for acceptance into // the pool. - if !self.local_transactions_config.is_local(origin, transaction.sender()) && + if !self.local_transactions_config.is_local(origin, transaction.sender_ref()) && transaction.is_eip1559() && transaction.max_priority_fee_per_gas() < self.minimum_priority_fee { diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index 6c625373401b..84caae6e7caa 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -282,6 +282,11 @@ impl ValidPoolTransaction { self.transaction.sender() } + /// Returns a reference to the address of the sender + pub fn sender_ref(&self) -> &Address { + self.transaction.sender_ref() + } + /// Returns the recipient of the transaction if it is not a CREATE transaction. pub fn to(&self) -> Option
{ self.transaction.to()