Struct MemPool

Source
pub struct MemPool<Block: BlockT, Client> { /* private fields */ }
Expand description

Thread-safe Bitcoin mempool.

Uses RwLock for interior mutability with the following lock hierarchy:

  1. MemPool::inner (RwLock)
  2. MemPool::coins_cache (RwLock)
  3. Runtime state backend (internal to client)

CRITICAL: Always acquire locks in this order to avoid deadlocks.

Implementations§

Source§

impl<Block, Client> MemPool<Block, Client>
where Block: BlockT, Client: ProvideRuntimeApi<Block> + HeaderBackend<Block> + AuxStore + Send + Sync, Client::Api: SubcoinApi<Block>,

Source

pub fn new(client: Arc<Client>) -> Self

Create a new mempool with default options.

Source

pub fn with_options(client: Arc<Client>, options: MemPoolOptions) -> Self

Create a new mempool with custom options.

Source

pub fn accept_single_transaction( &self, tx: Transaction, ) -> Result<(), MempoolError>

Accept a single transaction into the mempool.

CRITICAL: Holds write lock for entire ATMP flow to prevent TOCTOU races.

Source

pub fn size(&self) -> usize

Get number of transactions in mempool.

Source

pub fn total_size(&self) -> u64

Get total size of all transactions in bytes.

Source

pub fn trim_to_size(&self, max_size: u64)

Trim mempool to maximum size.

Source

pub fn expire(&self, max_age_seconds: i64)

Expire old transactions.

Source

pub fn options(&self) -> &MemPoolOptions

Get mempool options.

Source

pub fn remove_for_block( &self, confirmed_txs: &[Transaction], new_best_block: Block::Hash, ) -> Result<(), MempoolError>

Remove transactions confirmed in a block.

This is called after a new block is connected to remove transactions that were included in the block, as well as any conflicts.

Lock hierarchy: Acquires inner write lock, then coins_cache write lock.

Source

pub fn remove_conflicts(&self, txs: &[Transaction]) -> Result<(), MempoolError>

Remove conflicts for a set of transactions.

This is used when accepting a package of transactions to remove any existing mempool transactions that conflict with the package.

Source

pub fn remove_for_reorg( &self, new_tip_height: u32, new_best_block: Block::Hash, ) -> Result<(), MempoolError>

Remove transactions that are no longer valid after a reorg.

Prunes transactions based on:

  • Height-based timelocks (nLockTime)
  • Coinbase maturity violations
  • Sequence-based timelocks (BIP68)
  • Max input block no longer on active chain

Lock hierarchy: Acquires inner write lock, then coins_cache write lock.

Source

pub fn accept_package( &self, transactions: Vec<Transaction>, ) -> Result<PackageValidationResult, MempoolError>

Accept a package of related transactions (CPFP support).

All transactions are validated as a unit. If any fails, none are accepted.

Source

pub fn contains_txid(&self, txid: &Txid) -> bool

Check if transaction exists in mempool.

Source

pub fn get_transaction(&self, txid: &Txid) -> Option<Arc<Transaction>>

Get transaction from mempool if present.

Source

pub fn pending_broadcast_txs(&self) -> Vec<(Txid, u64)>

Get transactions pending broadcast with their fee rates.

Source

pub fn mark_broadcast_txs(&self, txids: &[Txid])

Mark transactions as broadcast.

Source

pub fn iter_txids_by_priority(&self) -> Vec<(Txid, u64)>

Iterate over all transaction IDs with their fee rates, sorted by mining priority.

Trait Implementations§

Source§

impl<Block, Client> TxPool for MemPool<Block, Client>
where Block: BlockT + 'static, Client: ProvideRuntimeApi<Block> + HeaderBackend<Block> + AuxStore + Send + Sync + 'static, Client::Api: SubcoinApi<Block>,

Source§

fn validate_transaction(&self, tx: Transaction) -> TxValidationResult

Validate and potentially accept a transaction into the mempool. Read more
Source§

fn contains(&self, txid: &Txid) -> bool

Check if transaction is already in mempool.
Source§

fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>

Get transaction from mempool if present.
Source§

fn pending_broadcast(&self) -> Vec<(Txid, u64)>

Get transactions pending broadcast to peers. Returns (txid, fee_rate) pairs.
Source§

fn mark_broadcast(&self, txids: &[Txid])

Mark transactions as broadcast to peers.
Source§

fn iter_txids(&self) -> Box<dyn Iterator<Item = (Txid, u64)> + Send>

Iterate over all transaction IDs with their fee rates. Returns (txid, fee_rate) pairs sorted by mining priority.
Source§

fn info(&self) -> TxPoolInfo

Get mempool statistics.

Auto Trait Implementations§

§

impl<Block, Client> !Freeze for MemPool<Block, Client>

§

impl<Block, Client> RefUnwindSafe for MemPool<Block, Client>
where Block: RefUnwindSafe, Client: RefUnwindSafe,

§

impl<Block, Client> Send for MemPool<Block, Client>
where Client: Sync + Send,

§

impl<Block, Client> Sync for MemPool<Block, Client>
where Client: Sync + Send,

§

impl<Block, Client> Unpin for MemPool<Block, Client>
where Block: Unpin, <Block as Block>::Hash: Unpin,

§

impl<Block, Client> UnwindSafe for MemPool<Block, Client>
where Client: RefUnwindSafe, Block: UnwindSafe,

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
§

impl<T> CheckedConversion for T

§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<Src, Dest> IntoTuple<Dest> for Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SaturatedConversion for T

§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
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.
§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,