From 3814bbc83d63118785824b806f163f7a62a8de9f Mon Sep 17 00:00:00 2001 From: Maksim Vykhota Date: Sat, 19 Feb 2022 21:45:05 +0300 Subject: [PATCH] Update pool from upstream --- Cargo.toml | 2 +- src/lib.rs | 3 +++ src/pool.rs | 16 ++++++++++------ src/tests/mod.rs | 3 +++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 664ad16..6ecd51e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "txpool" -version = "1.0.0-alpha" +version = "1.0.0-alpha.2" authors = ["Dragan Rakita "] edition = "2018" description = "Generic transaction pool." diff --git a/src/lib.rs b/src/lib.rs index a15be05..0cb0ae6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,4 +113,7 @@ pub trait VerifiedTransaction: fmt::Debug { /// Transaction sender fn sender(&self) -> &Self::Sender; + + /// Does it have zero gas price? + fn has_zero_gas_price(&self) -> bool; } diff --git a/src/pool.rs b/src/pool.rs index 8ba64ea..10b1458 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -321,14 +321,14 @@ where } Some(old) => { let txs = &self.transactions; - let get_replace_tx = |tx| { + let get_replace_tx = |sender, tx| { let sender_txs = txs - .get(transaction.sender()) + .get(sender) .map(|txs| txs.iter_transactions().as_slice()); ReplaceTransaction::new(tx, sender_txs) }; - let old_replace = get_replace_tx(&old.transaction); - let new_replace = get_replace_tx(transaction); + let old_replace = get_replace_tx(&old.transaction.sender(), &old.transaction); + let new_replace = get_replace_tx(&transaction.sender(), transaction); match replace.should_replace(&old_replace, &new_replace) { // We can't decide which of them should be removed, so accept both. @@ -650,7 +650,9 @@ where match self.ready.is_ready(&tx) { Readiness::Ready => { //return transaction with score higher or equal to desired - if score >= &self.includable_boundary { + if score >= &self.includable_boundary + || tx.transaction.has_zero_gas_price() + { return Some(tx.transaction.clone()); } } @@ -737,7 +739,9 @@ where if tx_state == Readiness::Ready { //return transaction with score higher or equal to desired - if best.score >= self.includable_boundary { + if best.score >= self.includable_boundary + || best.transaction.transaction.has_zero_gas_price() + { return Some(best.transaction.transaction); } } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 5ba235d..3e1d87c 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -50,6 +50,9 @@ impl VerifiedTransaction for Transaction { fn sender(&self) -> &Address { &self.sender } + fn has_zero_gas_price(&self) -> bool { + false + } } pub type SharedTransaction = Arc;