pub trait TxPool:
Send
+ Sync
+ 'static {
// Required methods
fn validate_transaction(&self, tx: Transaction) -> TxValidationResult;
fn contains(&self, txid: &Txid) -> bool;
fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>;
fn pending_broadcast(&self) -> Vec<(Txid, u64)>;
fn mark_broadcast(&self, txids: &[Txid]);
fn iter_txids(&self) -> Box<dyn Iterator<Item = (Txid, u64)> + Send>;
fn info(&self) -> TxPoolInfo;
}Expand description
Bitcoin transaction pool trait for network integration.
This trait abstracts mempool operations needed by the network layer, avoiding circular dependencies and enabling testing with mock implementations.
All methods are synchronous - the caller can decide whether to run them
on a blocking executor (e.g., Substrate’s spawn_blocking) or inline.
Required Methods§
Sourcefn validate_transaction(&self, tx: Transaction) -> TxValidationResult
fn validate_transaction(&self, tx: Transaction) -> TxValidationResult
Validate and potentially accept a transaction into the mempool.
This is a blocking operation that holds internal locks and performs
script validation. The caller should run this on a blocking executor
if needed (e.g., task_manager.spawn_blocking()).
Sourcefn get(&self, txid: &Txid) -> Option<Arc<Transaction>>
fn get(&self, txid: &Txid) -> Option<Arc<Transaction>>
Get transaction from mempool if present.
Sourcefn pending_broadcast(&self) -> Vec<(Txid, u64)>
fn pending_broadcast(&self) -> Vec<(Txid, u64)>
Get transactions pending broadcast to peers. Returns (txid, fee_rate) pairs.
Sourcefn mark_broadcast(&self, txids: &[Txid])
fn mark_broadcast(&self, txids: &[Txid])
Mark transactions as broadcast to peers.
Sourcefn iter_txids(&self) -> Box<dyn Iterator<Item = (Txid, u64)> + Send>
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.
Sourcefn info(&self) -> TxPoolInfo
fn info(&self) -> TxPoolInfo
Get mempool statistics.