Struct Pool

Source
pub struct Pool<T: VerifiedTransaction, S: Scoring<T>, L = NoopListener> { /* private fields */ }
Expand description

A transaction pool.

Implementations§

Source§

impl<T: VerifiedTransaction, S: Scoring<T> + Default> Pool<T, S>

Source

pub fn with_options(options: Options) -> Self

Creates a new Pool with given options and default Scoring and Listener.

Source§

impl<T: VerifiedTransaction, S: Scoring<T>> Pool<T, S>

Source

pub fn with_scoring(scoring: S, options: Options) -> Self

Creates a new Pool with given Scoring and options.

Source§

impl<T, S, L> Pool<T, S, L>
where T: VerifiedTransaction, S: Scoring<T>, L: Listener<T>,

Source

pub fn new(listener: L, scoring: S, options: Options) -> Self

Creates new Pool with given Scoring, Listener and options.

Source

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 Readyness 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.

Source

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.

Source

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.

Source

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).

Source

pub fn find(&self, hash: &T::Hash) -> Option<Arc<T>>

Returns a transaction if it’s part of the pool or None otherwise.

Source

pub fn worst_transaction(&self) -> Option<Arc<T>>

Returns worst transaction in the queue (if any).

Source

pub fn is_full(&self) -> bool

Returns true if the pool is at it’s capacity.

Source

pub fn senders(&self) -> impl Iterator<Item = &T::Sender>

Returns senders ordered by priority of their transactions.

Source

pub fn pending<R: Ready<T>>(&self, ready: R) -> PendingIterator<'_, T, R, S, L>

Returns an iterator of pending (ready) transactions.

Source

pub fn pending_from_sender<R: Ready<T>>( &self, ready: R, sender: &T::Sender, ) -> PendingIterator<'_, T, R, S, L>

Returns pending (ready) transactions from given sender.

Source

pub fn unordered_pending<R: Ready<T>>( &self, ready: R, ) -> UnorderedIterator<'_, T, R, S>

Returns unprioritized list of ready transactions.

Source

pub fn update_scores(&mut self, sender: &T::Sender, event: S::Event)

Update score of transactions of a particular sender.

Source

pub fn status<R: Ready<T>>(&self, ready: R) -> Status

Computes the full status of the pool (including readiness).

Source

pub fn light_status(&self) -> LightStatus

Returns light status of the pool.

Source

pub fn options(&self) -> Options

Returns current pool options.

Source

pub fn listener(&self) -> &L

Borrows listener instance.

Source

pub fn scoring(&self) -> &S

Borrows scoring instance.

Source

pub fn listener_mut(&mut self) -> &mut L

Borrows listener mutably.

Trait Implementations§

Source§

impl<T: Debug + VerifiedTransaction, S: Debug + Scoring<T>, L: Debug> Debug for Pool<T, S, L>
where T::Sender: Debug, T::Hash: Debug, S::Score: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: VerifiedTransaction, S: Scoring<T> + Default> Default for Pool<T, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, S, L> Freeze for Pool<T, S, L>
where L: Freeze, S: Freeze,

§

impl<T, S, L> RefUnwindSafe for Pool<T, S, L>

§

impl<T, S, L> Send for Pool<T, S, L>
where L: Send, S: Send, <T as VerifiedTransaction>::Hash: Send, T: Sync + Send,

§

impl<T, S, L> Sync for Pool<T, S, L>
where L: Sync, S: Sync, <T as VerifiedTransaction>::Sender: Sync, <T as VerifiedTransaction>::Hash: Sync, <S as Scoring<T>>::Score: Sync, T: Sync + Send,

§

impl<T, S, L> Unpin for Pool<T, S, L>
where L: Unpin, S: Unpin, <T as VerifiedTransaction>::Sender: Unpin, <T as VerifiedTransaction>::Hash: Unpin, <S as Scoring<T>>::Score: Unpin,

§

impl<T, S, L> UnwindSafe for Pool<T, S, L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.