pub struct MemPool<Block: BlockT, Client> { /* private fields */ }Expand description
Thread-safe Bitcoin mempool.
Uses RwLock for interior mutability with the following lock hierarchy:
- MemPool::inner (RwLock)
- MemPool::coins_cache (RwLock)
- Runtime state backend (internal to client)
CRITICAL: Always acquire locks in this order to avoid deadlocks.
Implementations§
Source§impl<Block, Client> MemPool<Block, Client>
impl<Block, Client> MemPool<Block, Client>
Sourcepub fn with_options(client: Arc<Client>, options: MemPoolOptions) -> Self
pub fn with_options(client: Arc<Client>, options: MemPoolOptions) -> Self
Create a new mempool with custom options.
Sourcepub fn accept_single_transaction(
&self,
tx: Transaction,
) -> Result<(), MempoolError>
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.
Sourcepub fn total_size(&self) -> u64
pub fn total_size(&self) -> u64
Get total size of all transactions in bytes.
Sourcepub fn trim_to_size(&self, max_size: u64)
pub fn trim_to_size(&self, max_size: u64)
Trim mempool to maximum size.
Sourcepub fn options(&self) -> &MemPoolOptions
pub fn options(&self) -> &MemPoolOptions
Get mempool options.
Sourcepub fn remove_for_block(
&self,
confirmed_txs: &[Transaction],
new_best_block: Block::Hash,
) -> Result<(), MempoolError>
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.
Sourcepub fn remove_conflicts(&self, txs: &[Transaction]) -> Result<(), MempoolError>
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.
Sourcepub fn remove_for_reorg(
&self,
new_tip_height: u32,
new_best_block: Block::Hash,
) -> Result<(), MempoolError>
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.
Sourcepub fn accept_package(
&self,
transactions: Vec<Transaction>,
) -> Result<PackageValidationResult, MempoolError>
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.
Sourcepub fn contains_txid(&self, txid: &Txid) -> bool
pub fn contains_txid(&self, txid: &Txid) -> bool
Check if transaction exists in mempool.
Sourcepub fn get_transaction(&self, txid: &Txid) -> Option<Arc<Transaction>>
pub fn get_transaction(&self, txid: &Txid) -> Option<Arc<Transaction>>
Get transaction from mempool if present.
Sourcepub fn pending_broadcast_txs(&self) -> Vec<(Txid, u64)>
pub fn pending_broadcast_txs(&self) -> Vec<(Txid, u64)>
Get transactions pending broadcast with their fee rates.
Sourcepub fn mark_broadcast_txs(&self, txids: &[Txid])
pub fn mark_broadcast_txs(&self, txids: &[Txid])
Mark transactions as broadcast.
Sourcepub fn iter_txids_by_priority(&self) -> Vec<(Txid, u64)>
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>
impl<Block, Client> TxPool for MemPool<Block, Client>
Source§fn validate_transaction(&self, tx: Transaction) -> TxValidationResult
fn validate_transaction(&self, tx: Transaction) -> TxValidationResult
Source§fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>
fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>
Source§fn pending_broadcast(&self) -> Vec<(Txid, u64)>
fn pending_broadcast(&self) -> Vec<(Txid, u64)>
Source§fn mark_broadcast(&self, txids: &[Txid])
fn mark_broadcast(&self, txids: &[Txid])
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>
impl<Block, Client> Sync for MemPool<Block, Client>
impl<Block, Client> Unpin for MemPool<Block, Client>
impl<Block, Client> UnwindSafe for MemPool<Block, Client>where
Client: RefUnwindSafe,
Block: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.