feat: add isIndexed/waitForIndexed #472
Open
ltardivo wants to merge 2 commits into
Open
Conversation
This change adds isIndexed and waitForIndexed to Computer and RestClient so callers can poll until the indexer has committed Output rows for a txId (or revision) instead of relying on fixed sleep delays. A corresponding GET /tx/:txId/indexed route was added to the node. The mempool hot path was restructured: insertAndUpdateMod now performs a short Phase-1 transaction (insertSpendGraph) that commits outputs + inputs immediately, making the UTXO set and indexed status visible to getUTXOs, queries, and waitForIndexed as quickly as possible. Mod propagation (parent lookup + descendant updates) moves to a separate, idempotent Phase-2 step that can safely retry or run after ZMQ re-delivery. All affected tests across lib-secret, node-secret, and swap2 were updated to use the new helpers (or simply remove now-unnecessary sleeps). The result eliminates the main source of timing flakiness, gives callers explicit control over read-after-write consistency, and keeps the critical indexer path short while preserving atomicity guarantees for reorg and recovery paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For reliable post-write sync across the stack, instead of sprinkling
await sleep(…)calls after everybroadcast,new,transfer, or state-changing operation, you can now usecomputer.waitForIndexed(revOrTxId)to wait until the indexer has committed the Output rows. The result is dramatically fewer flaky tests, faster CI, and predictable behavior under load or on regtest. We also refactored the hot mempool path in the indexer for quicker UTXO visibility while keeping everything eventually consistent and idempotent.Lib
New public API on
Computer(andRestClient)GET /tx/:txId/indexedendpoint powers the feature (see Node section).Migration tip
Replace patterns like this:
with:
Node
GET /v1/:chain/:network/tx/:txId/indexedreturns indexer readiness.OutputActionrefactored for a faster hot path:insertSpendGraph): short transaction that commits Output + Input rows immediately → UTXOs andindexedstatus become visible right away.propagateMods): separate, idempotent transaction for mod inheritance (safe to retry after ZMQ re-delivery).Contracts, Components & Tests (Public + Private)
Hundreds of
sleepcalls removed or replaced across:confirmChainTiphelper, now justfaucet+waitForIndexed)SmartObjectFunctionnow useswaitForIndexed)Tests are now faster, more deterministic, and no longer depend on magic timing values.