mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(validate-tx-pool): fast non-allocating is_local (#13096)
This commit is contained in:
@ -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]
|
||||
|
||||
@ -1462,7 +1462,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
|
||||
transaction: ValidPoolTransaction<T>,
|
||||
on_chain_nonce: u64,
|
||||
) -> Result<ValidPoolTransaction<T>, InsertErr<T>> {
|
||||
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();
|
||||
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -282,6 +282,11 @@ impl<T: PoolTransaction> ValidPoolTransaction<T> {
|
||||
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<Address> {
|
||||
self.transaction.to()
|
||||
|
||||
Reference in New Issue
Block a user