Repository navigation
Description
This issue tracks the work items identified in a full review of lib.rs and test_emitter.rs on master (de7a89f), separated into 3 broad categories: 1) Internal fixes, 2) API + Documentation, 3) Test coverage.
1. Quirks (needs investigation)
-
mempool_atconsistency loop
The inner loop in mempool_at calls 5 RPCs per iteration and retries immediately with no sleep, no ceiling on retries, and the HashSet<Txid> allocation is repeated on every failed iteration. It doesn't remove a race condition that exists between the time of getting the raw mempool and the time the full transactions are retrieved from the node.
-
let mutdeclarations before the loop
This pattern is legal but unusual Rust. The loop is really "retry until consistent snapshot"— an fn fetch_consistent_mempool_snapshot() that returns a named struct would be cleaner.
-
AgreementPointNotFoundarm creates an unprotected infinite loop
poll responds to AgreementPointNotFound by resetting to genesis and looping. If genesis is somehow inaccessible or the node has a persistent inconsistency, this spins forever. Although it's a pathological case, the recommendation would be to return a hard error after a bounded number of consecutive failures.
-
connected_to()returns itself when checkpoint has no parent
The fallback None => self.checkpoint.block_id() (returns itself) is unreachable via the emitter in practice, since every emitted checkpoint gets pushed onto the last cp. For correctness, should use (block_height - 1, block.header.prev_blockhash) directly which is consistent with the intended block-by-block behavior.
2. API Design + Documentation
- Documentation for
mempoolrefers to first-seen unix timestamps
MempoolEvent::update originally documented the timestamp as a "first-seen unix timestamp". For transactions in mempool_snapshot, the current sync_time is used on every poll — not the time the tx was first observed.
- Confusing
start_heightsemantics
start_height was intended as a birthday/scan-start height: "don't emit blocks before this height." PR #2167 exposed a bug where, after a reorg that drops the agreement point below start_height, the emitter skips directly to start_height rather than re-emitting the invalidated heights. The proposed fix modifies start_height internally at runtime to the agreement height, circumventing the stated purpose of the parameter and making the behavior difficult to explain.
Two options:
-
Remove
start_heightentirely. The birthday/scan-start is encoded directly inlast_cp: callers build a checkpoint containing the birthday height. The emitter scans from there naturally. -
Add an alternate constructor that does not take
start_heightand relies solely onlast_cpfor the start height, keeping the existing constructor for backward compatibility.
-
mempool_atdoc should carry the canonical eviction guard explanation
mempool_at contains the actual at_tip check and eviction logic, but its doc just says "no-std version of mempool". The eviction-guard semantics (withheld until emitter reaches tip, rationale) belong on mempool_at, with mempool() cross-referencing it.
-
NO_EXPECTED_MEMPOOL_TXSconstant adds friction, not clarity
The constant is a typed alias for core::iter::empty() hardcoded to T = Arc<Transaction>. This causes type-inference friction when callers pass Transaction directly.
-
BlockEvent<B>generic is vestigial
BlockEvent<B> exists solely to support the private poll<C, V, F> closure abstraction. next_block is the only public consumer and always returns BlockEvent<Block>.
-
poll/poll_onceare undocumented
These are the algorithmic heart of the emitter. Working branch adds state-machine docs explaining entry invariants, what each PollResponse variant means, and the reorg-detection flow.
-
CheckPoint should be generalized for any data type Make
bdk_bitcoind_rpcemitters support any checkpoint data type #2105 -
Move away from outdated
bitcoincore_rpc::ClientRefactor: update bdk-bitcoind-rpc to use bdk-bitcoind-client #2119
3. Test Coverage
- Stale
mempool_avoids_re_emissiondoc comment
The test mempool_avoids_re_emission has a doc comment that says "mempool txs should not be re-emitted" but its own assertions loop twice and assert that the same txids appear on both calls. Should be renamed to something like mempool_update_is_full_snapshot and the doc rewritten to describe what it actually tests: "every call to mempool() returns all currently-known unconfirmed transactions, including ones returned on previous calls."
- Stale
test_into_tx_graphdoc comment
The comment references EmittedUpdate::into_tx_graph_update — a deleted API. The test body is fine. Comment should be rewritten to describe what the test actually covers. Additionally addr_1 and addr_2 are generated and tracked but never funded, adding noise without coverage.
- Stale open design question as TODO in test doc
ensure_block_emitted_after_reorg_is_at_reorg_height contains TODO: If the reorg height is lower than the fallback height... — this is not a test concern, it is a design question. Should be removed from the test and tracked as a separate issue.
- Behind-tip eviction guard is untested
test_expect_tx_evicted tests eviction only when already at tip. The complementary scenario — evict a tx while the emitter is still behind tip, assert evicted is empty in that window, advance to tip, then assert the eviction is reported — is untested.
-
expected_mempool_txseviction path is not end-to-end tested
The unit test test_expected_mempool_txids_accumulate_and_remove verifies accumulation and removal on confirmation, but there is no test that: (1) passes a known-unconfirmed tx to Emitter::new via expected_mempool_txs, (2) evicts that tx from the node's mempool, and (3) asserts it appears in MempoolEvent::evicted. Edit: Covered by test_expect_tx_evicted.
- Missing test coverage for
start_height
No test verifies the fundamental birthday guarantee: an emitter with last_cp at height N must not emit any block at or below N.
-
Missing test coverage for
BlockEvent::connected_to() -
mempool_atis never called in integration tests
mempool_at is never called in integration tests to verify that each mempool tx carries the custom sync_time passed into the API.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
ValuedMammal commentedon Apr 15, 2026
@evanlinjin I'd like to work on this.
evanlinjin commentedon Apr 16, 2026
Some corrections:
Section 1 (Bugs/Correctness)
mempool_atbackoff/retry cap — This is not a bug.mempool_atis a low-level building block. Backoff and retry policy is the caller's responsibility — different callers have different requirements (polling interval, max retries, error handling strategy). Baking a specific retry policy into the API would be opinionated and inflexible.let mutbefore the loop — This is a style preference, not a correctness issue.AgreementPointNotFoundinfinite loop — If genesis is inaccessible from your local bitcoind, the node itself is broken. This is not a realistic failure mode.None of these are bugs.
Section 2 (API Design)
start_heightsemantics — I agree this is worth improving. I thinkstart_heightshould be optional and set via a builder pattern, defaulting to 0.The documentation items are fair observations and PRs for those would be welcome, but they're minor improvements, not signs of API instability.
[-][bitcoind_rpc] Plans to stabilize the Emitter API?[/-][+][bitcoind_rpc] Emitter API cleanup: start_height, docs and test gaps[/+]