refactor(txpool): simplify is local (#87)

This commit is contained in:
Matthias Seitz
2022-10-17 20:43:27 +02:00
committed by GitHub
parent 6bc09809f3
commit 522a4e689e
4 changed files with 6 additions and 7 deletions

View File

@ -179,7 +179,6 @@ where
transaction, transaction,
transaction_id, transaction_id,
propagate: false, propagate: false,
is_local: false,
timestamp: Instant::now(), timestamp: Instant::now(),
origin, origin,
}; };

View File

@ -19,7 +19,6 @@ bitflags::bitflags! {
/// ///
/// Set to 1 if `feeCap` of the transaction meets the requirement of the pending block. /// Set to 1 if `feeCap` of the transaction meets the requirement of the pending block.
const ENOUGH_FEE_CAP_BLOCK = 0b000010; 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; 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_eq!(SubPool::Pending, state.into());
assert!(state.is_pending()); assert!(state.is_pending());
let bits = 0b111111; let bits = 0b111110;
let state = TxState::from_bits(bits).unwrap(); let state = TxState::from_bits(bits).unwrap();
assert_eq!(SubPool::Pending, state.into()); assert_eq!(SubPool::Pending, state.into());
assert!(state.is_pending()); assert!(state.is_pending());

View File

@ -355,7 +355,6 @@ impl MockTransactionFactory {
let transaction_id = self.tx_id(&transaction); let transaction_id = self.tx_id(&transaction);
MockValidTx { MockValidTx {
propagate: false, propagate: false,
is_local: false,
transaction_id, transaction_id,
cost: transaction.cost(), cost: transaction.cost(),
transaction, transaction,

View File

@ -51,8 +51,6 @@ pub struct ValidPoolTransaction<T: PoolTransaction> {
pub transaction_id: TransactionId, pub transaction_id: TransactionId,
/// Whether to propagate the transaction. /// Whether to propagate the transaction.
pub propagate: bool, 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`. /// Total cost of the transaction: `feeCap x gasLimit + transferred_value`.
pub cost: U256, pub cost: U256,
/// Timestamp when this was added to the pool. /// Timestamp when this was added to the pool.
@ -103,6 +101,11 @@ impl<T: PoolTransaction> ValidPoolTransaction<T> {
pub(crate) fn is_underpriced(&self, other: &Self) -> bool { pub(crate) fn is_underpriced(&self, other: &Self) -> bool {
self.transaction.effective_gas_price() <= other.transaction.effective_gas_price() 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)] #[cfg(test)]
@ -112,7 +115,6 @@ impl<T: PoolTransaction + Clone> Clone for ValidPoolTransaction<T> {
transaction: self.transaction.clone(), transaction: self.transaction.clone(),
transaction_id: self.transaction_id, transaction_id: self.transaction_id,
propagate: self.propagate, propagate: self.propagate,
is_local: self.is_local,
cost: self.cost, cost: self.cost,
timestamp: self.timestamp, timestamp: self.timestamp,
origin: self.origin, origin: self.origin,