pub trait Scoring<T>: Debug {
type Score: Ord + Clone + Default + Debug + Send + LowerHex;
type Event: Debug + Copy;
fn compare(&self, old: &T, other: &T) -> Ordering;
fn choose(&self, old: &T, new: &T) -> Choice;
fn update_scores(
&self,
txs: &[Transaction<T>],
scores: &mut [Self::Score],
change: Change<Self::Event>
);
fn should_ignore_sender_limit(&self, _new: &T) -> bool { ... }
}Expand description
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
Scores should match ordering ofcomparemethod. comparewill be called only within a context of transactions from the same sender.choosemay be called even ifcomparereturnsOrdering::EqualScores andcompareshould align withReadyimplementation.
Example: Natural ordering of Ethereum transactions.
compare: compares transactionnonce()choose: compares transactionsgasPrice(decides if old transaction should be replaced)update_scores: score defined asgasPriceifn==0andmax(scores[n-1], gasPrice)ifn>0
Associated Types
Required methods
Decides on ordering of Ts from a particular sender.
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: &[Transaction<T>],
scores: &mut [Self::Score],
change: Change<Self::Event>
)
fn update_scores(
&self,
txs: &[Transaction<T>],
scores: &mut [Self::Score],
change: Change<Self::Event>
)
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)
Provided methods
fn should_ignore_sender_limit(&self, _new: &T) -> bool
fn should_ignore_sender_limit(&self, _new: &T) -> bool
Decides if the transaction should ignore per-sender limit in the pool.
If you return true for given transaction it’s going to be accepted even though
the per-sender limit is exceeded.