pub struct Pool<T: VerifiedTransaction, S: Scoring<T>, L = NoopListener> { /* private fields */ }
Expand description
A transaction pool.
Implementations
sourceimpl<T: VerifiedTransaction, S: Scoring<T> + Default> Pool<T, S>
impl<T: VerifiedTransaction, S: Scoring<T> + Default> Pool<T, S>
sourcepub fn with_options(options: Options) -> Self
pub fn with_options(options: Options) -> Self
Creates a new Pool
with given options
and default Scoring
and Listener
.
sourceimpl<T: VerifiedTransaction, S: Scoring<T>> Pool<T, S>
impl<T: VerifiedTransaction, S: Scoring<T>> Pool<T, S>
sourcepub fn with_scoring(scoring: S, options: Options) -> Self
pub fn with_scoring(scoring: S, options: Options) -> Self
Creates a new Pool
with given Scoring
and options.
sourceimpl<T, S, L> Pool<T, S, L> where
T: VerifiedTransaction,
S: Scoring<T>,
L: Listener<T>,
impl<T, S, L> Pool<T, S, L> where
T: VerifiedTransaction,
S: Scoring<T>,
L: Listener<T>,
sourcepub fn new(listener: L, scoring: S, options: Options) -> Self
pub fn new(listener: L, scoring: S, options: Options) -> Self
Creates new Pool
with given Scoring
, Listener
and options.
sourcepub fn import(
&mut self,
transaction: T,
replace: &dyn ShouldReplace<T>
) -> Result<Arc<T>, Error<T::Hash>>
pub fn import(
&mut self,
transaction: T,
replace: &dyn ShouldReplace<T>
) -> Result<Arc<T>, Error<T::Hash>>
Attempts to import new transaction to the pool, returns a Arc<T>
or an Error
.
NOTE: Since Ready
ness is separate from the pool it’s possible to import stalled transactions.
It’s the caller responsibility to make sure that’s not the case.
NOTE: The transaction may push out some other transactions from the pool
either because of limits (see Options
) or because Scoring
decides that the transaction
replaces an existing transaction from that sender.
If any limit is reached the transaction with the lowest Score
will be compared with the
new transaction via the supplied ShouldReplace
implementation and may be evicted.
The Listener
will be informed on any drops or rejections.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears pool from all transactions. This causes a listener notification that all transactions were dropped. NOTE: the drop-notification order will be arbitrary.
sourcepub fn remove(&mut self, hash: &T::Hash, is_invalid: bool) -> Option<Arc<T>>
pub fn remove(&mut self, hash: &T::Hash, is_invalid: bool) -> Option<Arc<T>>
Removes single transaction from the pool.
Depending on the is_invalid
flag the listener
will either get a cancelled
or invalid
notification.
sourcepub fn cull<R: Ready<T>>(
&mut self,
senders: Option<&[T::Sender]>,
ready: R
) -> usize
pub fn cull<R: Ready<T>>(
&mut self,
senders: Option<&[T::Sender]>,
ready: R
) -> usize
Removes all stalled transactions from given sender list (or from all senders).
sourcepub fn find(&self, hash: &T::Hash) -> Option<Arc<T>>
pub fn find(&self, hash: &T::Hash) -> Option<Arc<T>>
Returns a transaction if it’s part of the pool or None
otherwise.
sourcepub fn worst_transaction(&self) -> Option<Arc<T>>
pub fn worst_transaction(&self) -> Option<Arc<T>>
Returns worst transaction in the queue (if any).
sourcepub fn senders(&self) -> impl Iterator<Item = &T::Sender>
pub fn senders(&self) -> impl Iterator<Item = &T::Sender>
Returns senders ordered by priority of their transactions.
sourcepub fn pending<R: Ready<T>>(
&self,
ready: R,
includable_boundary: S::Score
) -> PendingIterator<'_, T, R, S, L>ⓘNotable traits for PendingIterator<'a, T, R, S, L>impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
pub fn pending<R: Ready<T>>(
&self,
ready: R,
includable_boundary: S::Score
) -> PendingIterator<'_, T, R, S, L>ⓘNotable traits for PendingIterator<'a, T, R, S, L>impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
Returns an iterator of pending (ready) transactions.
sourcepub fn pending_from_sender<R: Ready<T>>(
&self,
ready: R,
sender: &T::Sender,
includable_boundary: S::Score
) -> PendingIterator<'_, T, R, S, L>ⓘNotable traits for PendingIterator<'a, T, R, S, L>impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
pub fn pending_from_sender<R: Ready<T>>(
&self,
ready: R,
sender: &T::Sender,
includable_boundary: S::Score
) -> PendingIterator<'_, T, R, S, L>ⓘNotable traits for PendingIterator<'a, T, R, S, L>impl<'a, T, R, S, L> Iterator for PendingIterator<'a, T, R, S, L> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
Returns pending (ready) transactions from given sender.
sourcepub fn unordered_pending<R: Ready<T>>(
&self,
ready: R,
includable_boundary: S::Score
) -> UnorderedIterator<'_, T, R, S>ⓘNotable traits for UnorderedIterator<'a, T, R, S>impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
pub fn unordered_pending<R: Ready<T>>(
&self,
ready: R,
includable_boundary: S::Score
) -> UnorderedIterator<'_, T, R, S>ⓘNotable traits for UnorderedIterator<'a, T, R, S>impl<'a, T, R, S> Iterator for UnorderedIterator<'a, T, R, S> where
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
T: VerifiedTransaction,
R: Ready<T>,
S: Scoring<T>, type Item = Arc<T>;
Returns unprioritized list of ready transactions.
sourcepub fn update_scores(&mut self, sender: &T::Sender, event: S::Event)
pub fn update_scores(&mut self, sender: &T::Sender, event: S::Event)
Update score of transactions of a particular sender.
sourcepub fn status<R: Ready<T>>(&self, ready: R) -> Status
pub fn status<R: Ready<T>>(&self, ready: R) -> Status
Computes the full status of the pool (including readiness).
sourcepub fn light_status(&self) -> LightStatus
pub fn light_status(&self) -> LightStatus
Returns light status of the pool.
sourcepub fn set_scoring(&mut self, scoring: S, event: S::Event)
pub fn set_scoring(&mut self, scoring: S, event: S::Event)
Set scoring instance.
sourcepub fn listener_mut(&mut self) -> &mut L
pub fn listener_mut(&mut self) -> &mut L
Borrows listener mutably.
Trait Implementations
Auto Trait Implementations
impl<T, S, L> RefUnwindSafe for Pool<T, S, L> where
L: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
<T as VerifiedTransaction>::Hash: RefUnwindSafe,
<S as Scoring<T>>::Score: RefUnwindSafe,
<T as VerifiedTransaction>::Sender: RefUnwindSafe,
impl<T, S, L> Send for Pool<T, S, L> where
L: Send,
S: Send,
T: Send + Sync,
<T as VerifiedTransaction>::Hash: Send,
impl<T, S, L> Sync for Pool<T, S, L> where
L: Sync,
S: Sync,
T: Send + Sync,
<T as VerifiedTransaction>::Hash: Sync,
<S as Scoring<T>>::Score: Sync,
<T as VerifiedTransaction>::Sender: Sync,
impl<T, S, L> Unpin for Pool<T, S, L> where
L: Unpin,
S: Unpin,
<T as VerifiedTransaction>::Hash: Unpin,
<S as Scoring<T>>::Score: Unpin,
<T as VerifiedTransaction>::Sender: Unpin,
impl<T, S, L> UnwindSafe for Pool<T, S, L> where
L: UnwindSafe,
S: UnwindSafe,
T: RefUnwindSafe,
<T as VerifiedTransaction>::Hash: UnwindSafe,
<S as Scoring<T>>::Score: UnwindSafe + RefUnwindSafe,
<T as VerifiedTransaction>::Sender: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more