From 522a4e689e398036ff29e844ebecc47c62e267d7 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 17 Oct 2022 20:43:27 +0200 Subject: [PATCH] refactor(txpool): simplify is local (#87) --- crates/transaction-pool/src/pool/mod.rs | 1 - crates/transaction-pool/src/pool/state.rs | 3 +-- crates/transaction-pool/src/test_util/mock.rs | 1 - crates/transaction-pool/src/validate.rs | 8 +++++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 83810c2c2..9cf1ae8a5 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -179,7 +179,6 @@ where transaction, transaction_id, propagate: false, - is_local: false, timestamp: Instant::now(), origin, }; diff --git a/crates/transaction-pool/src/pool/state.rs b/crates/transaction-pool/src/pool/state.rs index 2d7d74241..0a3af14aa 100644 --- a/crates/transaction-pool/src/pool/state.rs +++ b/crates/transaction-pool/src/pool/state.rs @@ -19,7 +19,6 @@ bitflags::bitflags! { /// /// Set to 1 if `feeCap` of the transaction meets the requirement of the pending block. const ENOUGH_FEE_CAP_BLOCK = 0b000010; - const IS_LOCAL = 0b000001; const PENDING_POOL_BITS = Self::NO_PARKED_ANCESTORS.bits | Self::NO_NONCE_GAPS.bits | Self::ENOUGH_BALANCE.bits | Self::NOT_TOO_MUCH_GAS.bits | Self::ENOUGH_FEE_CAP_BLOCK.bits; @@ -112,7 +111,7 @@ mod tests { assert_eq!(SubPool::Pending, state.into()); assert!(state.is_pending()); - let bits = 0b111111; + let bits = 0b111110; let state = TxState::from_bits(bits).unwrap(); assert_eq!(SubPool::Pending, state.into()); assert!(state.is_pending()); diff --git a/crates/transaction-pool/src/test_util/mock.rs b/crates/transaction-pool/src/test_util/mock.rs index b650c1e92..8b9b0f9d5 100644 --- a/crates/transaction-pool/src/test_util/mock.rs +++ b/crates/transaction-pool/src/test_util/mock.rs @@ -355,7 +355,6 @@ impl MockTransactionFactory { let transaction_id = self.tx_id(&transaction); MockValidTx { propagate: false, - is_local: false, transaction_id, cost: transaction.cost(), transaction, diff --git a/crates/transaction-pool/src/validate.rs b/crates/transaction-pool/src/validate.rs index ed0762c08..902bc2270 100644 --- a/crates/transaction-pool/src/validate.rs +++ b/crates/transaction-pool/src/validate.rs @@ -51,8 +51,6 @@ pub struct ValidPoolTransaction { pub transaction_id: TransactionId, /// Whether to propagate the transaction. pub propagate: bool, - /// Whether the tx is from a local source. - pub is_local: bool, /// Total cost of the transaction: `feeCap x gasLimit + transferred_value`. pub cost: U256, /// Timestamp when this was added to the pool. @@ -103,6 +101,11 @@ impl ValidPoolTransaction { pub(crate) fn is_underpriced(&self, other: &Self) -> bool { self.transaction.effective_gas_price() <= other.transaction.effective_gas_price() } + + /// Whether the transaction originated locally. + pub(crate) fn is_local(&self) -> bool { + self.origin.is_local() + } } #[cfg(test)] @@ -112,7 +115,6 @@ impl Clone for ValidPoolTransaction { transaction: self.transaction.clone(), transaction_id: self.transaction_id, propagate: self.propagate, - is_local: self.is_local, cost: self.cost, timestamp: self.timestamp, origin: self.origin,