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- [
steps::Fetcher] - one mixed batched RPC forgetblocktemplate+getrawmempool false+getmempoolinfo, then a single mixedgetmempoolentry+getrawtransactionbatch 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. - [
steps::Preparer] - decode and classify intoTxsPulled { added, removed }. Pure CPU. - [
steps::Applier] - apply the diff to [state::State] under a single write lock. - [
steps::Prevouts::fill] - fillsprevout: Noneinputs in one pass, using same-cycle in-mempool parents directly and the caller-supplied resolver (default:getrawtransaction) for confirmed parents. - [
snapshot::Rebuilder] - rebuilds the projected-blocksSnapshotfrom 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}(twoRwLocks, written in that order each cycle): the published projection. Readers grab one or the other. The cycle drops itsStateguard 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::tickafter fetch → prepare → apply → prevouts → rebuild. The snapshot is always present (the rebuilder runs every cycle). Comparenext_block_hashacross cycles if you need to detect whether the projection actually changed. - Mempool
- Cheaply cloneable: clones share one live mempool via
Arc. - Mempool
Stats - RbfFor
Tx - RbfNode
- Snapshot
- TxAdded
- TxRemoved