Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Use natural priority ordering to simplify should_replace.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo committed Jun 25, 2018
1 parent 8355d31 commit 2b54be2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
16 changes: 8 additions & 8 deletions miner/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ impl PendingSettings {
}

/// Transaction priority.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone, Copy)]
pub(crate) enum Priority {
/// Local transactions (high priority)
///
/// Transactions either from a local account or
/// submitted over local RPC connection via `eth_sendRawTransaction`
Local,
/// Regular transactions received over the network. (no priority boost)
Regular,
/// Transactions from retracted blocks (medium priority)
///
/// When block becomes non-canonical we re-import the transactions it contains
/// to the queue and boost their priority.
Retracted,
/// Regular transactions received over the network. (no priority boost)
Regular,
/// Local transactions (high priority)
///
/// Transactions either from a local account or
/// submitted over local RPC connection via `eth_sendRawTransaction`
Local,
}

impl Priority {
Expand Down
15 changes: 3 additions & 12 deletions miner/src/pool/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,9 @@ impl txpool::Scoring<VerifiedTransaction> for NonceAndGasPrice {
cmp::Ordering::Equal => self.choose(old, new) == txpool::scoring::Choice::ReplaceOld,
}
} else {
// Always kick out non-local transactions in favour of local ones.
if new.priority().is_local() && !old.priority().is_local() {
return true;
}
// And never kick out local transactions in favour of external ones.
if !new.priority().is_local() && old.priority.is_local() {
return false;
}

let old_gp = old.transaction.gas_price;
let new_gp = new.transaction.gas_price;
old_gp < new_gp
let old_score = (old.priority(), old.transaction.gas_price);
let new_score = (new.priority(), new.transaction.gas_price);
new_score > old_score
}
}
}
Expand Down

0 comments on commit 2b54be2

Please sign in to comment.