Skip to main content

Crate brk_mempool

Crate brk_mempool 

Source
Expand description

Live mempool monitor for the brk indexer.

One pull cycle, five steps:

  Fetcher  ->  Preparer  ->  Applier  ->  Prevouts  ->  Rebuilder
    RPC        decode &     write to       fill         build
               classify     State          missing      Snapshot
                                           prevouts
  1. [steps::Fetcher] - one mixed batched RPC for getblocktemplate + getrawmempool false + getmempoolinfo, then a single mixed getmempoolentry+getrawtransaction batch on new txids only. GBT-only txs are synthesized inline from the GBT payload so block 0 matches Core’s selection exactly without a follow-up entry fetch that could race the listing.
  2. [steps::Preparer] - decode and classify into TxsPulled { added, removed }. Pure CPU.
  3. [steps::Applier] - apply the diff to [state::State] under a single write lock.
  4. [steps::Prevouts::fill] - fills prevout: None inputs in one pass, using same-cycle in-mempool parents directly and the caller-supplied resolver (default: getrawtransaction) for confirmed parents.
  5. [snapshot::Rebuilder] - rebuilds the projected-blocks Snapshot from the same-cycle GBT and min fee.

§Locking domains

Two independent locks. No path holds both simultaneously.

  • State (RwLock<State>): the live mempool. Cycle steps 3 and 4 take the write guard. Every read-side accessor takes a read guard.
  • Rebuilder.{snapshot, history} (two RwLocks, written in that order each cycle): the published projection. Readers grab one or the other. The cycle drops its State guard before touching them.

§Usage

Drive the loop on a worker thread and read from any clone:

use brk_mempool::Mempool;
let client = make_client();
let mempool = Mempool::new(&client);
let reader = mempool.clone();
std::thread::spawn(move || mempool.start());
// `reader.snapshot()`, `reader.block_template()`, etc. on this thread.

A Mempool hosts at most one driver. Calling start / start_with a second time on the same instance panics. Spawn a separate Mempool::new if you need more loops.

Structs§

Cycle
One pull cycle’s worth of changes. Produced by crate::Mempool::tick after fetch → prepare → apply → prevouts → rebuild. The snapshot is always present (the rebuilder runs every cycle). Compare next_block_hash across cycles if you need to detect whether the projection actually changed.
Mempool
Cheaply cloneable: clones share one live mempool via Arc.
MempoolStats
RbfForTx
RbfNode
Snapshot
TxAdded
TxRemoved

Enums§

AddedKind
TxRemoval
Replaced = at least one freshly added tx this cycle spends one of its inputs (BIP-125 replacement inferred from conflicting outpoints). by is the immediate successor. The chain extends if by is itself later replaced. Walk it forward via TxGraveyard::replacement_root_of.