pub struct RebalancingWeightedTransactionSelector { /* private fields */ }Implementations§
Source§impl RebalancingWeightedTransactionSelector
impl RebalancingWeightedTransactionSelector
pub fn new(policy: Policy, transactions: Vec<CandidateTransaction>) -> Self
Sourcepub fn select_transactions(&mut self) -> Vec<Transaction>
pub fn select_transactions(&mut self) -> Vec<Transaction>
select_transactions implements a probabilistic transaction selection algorithm. The algorithm, roughly, is as follows:
- We assign a probability to each transaction equal to: (candidateTx.Value^alpha) / Σ(tx.Value^alpha) Where the sum of the probabilities of all txs is 1.
- We draw a random number in [0,1) and select a transaction accordingly.
- If it’s valid, add it to the selectedTxs and remove it from the candidates.
- Continue iterating the above until we have either selected all available transactions or ran out of gas/block space.
Note that we make two optimizations here:
- Draw a number in [0,Σ(tx.Value^alpha)) to avoid normalization
- Instead of removing a candidate after each iteration, mark it for deletion. Once the sum of probabilities of marked transactions is greater than REBALANCE_THRESHOLD percent of the sum of probabilities of all transactions, rebalance.
select_transactions loops over the candidate transactions and appends the ones that will be included in the next block into selected_txs.
Trait Implementations§
Source§impl TemplateTransactionSelector for RebalancingWeightedTransactionSelector
impl TemplateTransactionSelector for RebalancingWeightedTransactionSelector
Source§fn select_transactions(&mut self) -> Vec<Transaction>
fn select_transactions(&mut self) -> Vec<Transaction>
Expected to return a batch of transactions which were not previously selected.
The batch will typically contain sufficient transactions to fill the block
mass (along with the previously unrejected txs), or will drain the selector
Source§fn reject_selection(&mut self, tx_id: TransactionId)
fn reject_selection(&mut self, tx_id: TransactionId)
Should be used to report invalid transactions obtained from the most recent
select_transactions call. Implementors should use this call to internally
track the selection state and discard the rejected tx from internal occupation calculationsSource§fn is_successful(&self) -> bool
fn is_successful(&self) -> bool
Determine whether this was an overall successful selection episode
Auto Trait Implementations§
impl Freeze for RebalancingWeightedTransactionSelector
impl RefUnwindSafe for RebalancingWeightedTransactionSelector
impl Send for RebalancingWeightedTransactionSelector
impl Sync for RebalancingWeightedTransactionSelector
impl Unpin for RebalancingWeightedTransactionSelector
impl UnwindSafe for RebalancingWeightedTransactionSelector
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S> CastArc for Swhere
S: CastFromSync + ?Sized,
impl<S> CastArc for Swhere
S: CastFromSync + ?Sized,
Source§impl<T> CastFrom for Twhere
T: Any + 'static,
impl<T> CastFrom for Twhere
T: Any + 'static,
Source§fn ref_any(&self) -> &(dyn Any + 'static)
fn ref_any(&self) -> &(dyn Any + 'static)
Returns a immutable reference to
Any, which is backed by the type implementing this trait.Source§fn mut_any(&mut self) -> &mut (dyn Any + 'static)
fn mut_any(&mut self) -> &mut (dyn Any + 'static)
Returns a mutable reference to
Any, which is backed by the type implementing this trait.Source§impl<T> CastFromSync for T
impl<T> CastFromSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more