Trait transaction_pool::scoring::Scoring
[−]
[src]
pub trait Scoring<T> { type Score: Ord + Clone + Default + Debug; fn compare(&self, old: &T, other: &T) -> Ordering; fn choose(&self, old: &T, new: &T) -> Choice; fn update_scores(
&self,
txs: &[Arc<T>],
scores: &mut [Self::Score],
change: Change
); fn should_replace(&self, old: &T, new: &T) -> bool; }
A transaction ordering.
The implementation should decide on order of transactions in the pool.
Each transaction should also get assigned a Score
which is used to later
prioritize transactions in the pending set.
Implementation notes:
- Returned Score
s should match ordering of compare
method.
- compare
will be called only within a context of transactions from the same sender.
- choose
will be called only if compare
returns Ordering::Equal
- should_replace
is used to decide if new transaction should push out an old transaction already in the queue.
- Score
s and compare
should align with Ready
implementation.
Example: Natural ordering of Ethereum transactions.
- compare
: compares transaction nonce
()
- choose
: compares transactions gasPrice
(decides if old transaction should be replaced)
- update_scores
: score defined as gasPrice
if n==0
and max(scores[n-1], gasPrice)
if n>0
- should_replace
: compares gasPrice
(decides if transaction from a different sender is more valuable)
Associated Types
Required Methods
fn compare(&self, old: &T, other: &T) -> Ordering
Decides on ordering of T
s from a particular sender.
fn choose(&self, old: &T, new: &T) -> Choice
Decides how to deal with two transactions from a sender that seem to occupy the same slot in the queue.
fn update_scores(
&self,
txs: &[Arc<T>],
scores: &mut [Self::Score],
change: Change
)
&self,
txs: &[Arc<T>],
scores: &mut [Self::Score],
change: Change
)
Updates the transaction scores given a list of transactions and a change to previous scoring.
NOTE: you can safely assume that both slices have the same length.
(i.e. score at index i
represents transaction at the same index)
fn should_replace(&self, old: &T, new: &T) -> bool
Decides if new
should push out old
transaction from the pool.