Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pool from upstream #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "txpool"
version = "1.0.0-alpha"
version = "1.0.0-alpha.2"
authors = ["Dragan Rakita <[email protected]","Karim Agha <[email protected]>"]
edition = "2018"
description = "Generic transaction pool."
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 10 additions & 6 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>;
Expand Down