Repository navigation
Implement WaitForTx RPC method - #1351
carbolymer wants to merge 3 commits into
Conversation
f7a44d1 to
8e3bb0d
Compare
3021b1f to
f941cb5
Compare
f941cb5 to
decead2
Compare
567ebae to
af949db
Compare
7b22103 to
a4c73f2
Compare
a4c73f2 to
8d092ed
Compare
8d092ed to
d5e519f
Compare
d5e519f to
3be64ea
Compare
3be64ea to
5895421
Compare
4347a36 to
051e7ed
Compare
0874d6e to
b0d97de
Compare
b0d97de to
c1dee61
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Idle-timeout enforcement, empty-request handling before kernel initialization, and public mempool API migration documentation need correction.
3 open issues
What changed in this PR
Implements WaitForTx, completing the UTxO RPC submit service’s supported methods.
Changes:
- Adds transaction-stage streaming with request limits, idle timeout, and unit tests.
- Generalizes chain followers and switches mempool watching to ticket cursors.
- Registers the handler and tracing, updates support documentation, and adds changelog fragments.
| File | Description |
|---|---|
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/WatchMempoolStream.hs |
Adapts snapshot fixtures and removal tests. |
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/WaitForTxStream.hs |
Tests streaming state transitions and helpers. |
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/FollowTipStream.hs |
Updates follower fixtures. |
cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess/Internal/Follower.hs |
Extracts and generalizes chain followers. |
cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess.hs |
Adds node reads and ticket-based mempool waits. |
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/WaitForTx.hs |
Implements transaction-stage streaming. |
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Sync.hs |
Updates the follower payload type. |
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Mempool.hs |
Uses ticket cursors for watching. |
cardano-rpc/src/Cardano/Rpc/Server/Internal/Tracing.hs |
Adds the wait-method trace span. |
cardano-rpc/src/Cardano/Rpc/Server.hs |
Registers WaitForTx. |
cardano-rpc/README.md |
Marks WaitForTx supported. |
cardano-rpc/cardano-rpc.cabal |
Registers implementation and test modules. |
.changes/20260921_cardano_rpc_wait_for_tx.yml |
Documents the feature and limits. |
.changes/20260921_cardano_rpc_chain_follower_payload.yml |
Documents follower API breaks. |
Review effort: Balanced
| Just state' -> | ||
| waitLoop nodeKernelAccess follower state' tip $ nextIdleDeadline sentAt deadline responses |
There was a problem hiding this comment.
Fixed in aad56e1. After the deadline the loop still takes one change that is already waiting, but if handling it sends nothing, the stream ends with DEADLINE_EXCEEDED. A change that sends a response restarts the deadline as before. A new property covers the expired-and-silent, expired-with-response and not-expired cases.
eaa897a to
3834c3f
Compare
ChainFollower and ChainChange take the payload type, so a caller reads only the block components it uses, and ChainFollower gains a non-blocking tryNextChange. NodeKernelAccess gains STM reads of the chain tip point, the mempool snapshot and the current era.
WatchMempool now waits for a transaction newer than the last seen ticket, found in O(log n) with snapshotTxsAfter, instead of comparing every ticket number on each mempool change. Removals and slot changes no longer wake it, as they never produced a message.
3834c3f to
bb26b5a
Compare
| Just state' -> | ||
| waitLoop nodeKernelAccess follower state' tip $ nextIdleDeadline sentAt deadline responses |
There was a problem hiding this comment.
Fixed in aad56e1. After the deadline the loop still takes one change that is already waiting, but if handling it sends nothing, the stream ends with DEADLINE_EXCEEDED. A change that sends a response restarts the deadline as before. A new property covers the expired-and-silent, expired-with-response and not-expired cases.


Context
Adds the
WaitForTxmethod of the UTxO RPC submit service, the last unsupported method in that service. Thecardano-rpcREADME table now marks it as supported. This change also generalisesChainChangeandChainFollowerover their per-block payload:withFollowerretains raw block bytes and the parsed block, whilewithBlockFollowerprovides only the parsed block. Callers that name the old unparameterised types must add the payload type.The client sends a list of transaction ids. The server reports
STAGE_MEMPOOLwhen it observes a requested transaction in the mempool, andSTAGE_CONFIRMEDwhen it appears in a block applied after the stream opens. It reports anotherSTAGE_MEMPOOLafter an observed removal and re-entry. The stream closes when every requested transaction is confirmed.It uses node kernel access, with no N2C connection. A chain follower is positioned at the current tip when the stream opens. The handler waits for chain-tip and pending-transaction mempool-membership changes through STM, then drains the follower when the tip moves. A
TraceRpcWaitForTxSpanevent wraps the call. TheWatchMempoolloop wakes only when a new transaction enters the mempool; removals and slot-only changes do not wake it. This breaksMempoolWatchSnapshot(onlymempoolWatchTxsAfterremains),nextMempoolWatchSnapshotand thewatchMempoolStreamcallback, which now take the last seenTicketNo.Known limits:
DEADLINE_EXCEEDED. A change that is ready after the deadline is still handled; if it sends nothing, the stream ends. Reopening does not recover past confirmations, so clients should openWaitForTxbefore or while they submit.STAGE_MEMPOOLif the handler observes the removal before the re-entry. A removal and re-entry between membership snapshots can be missed.FollowTipcovers that case.INVALID_ARGUMENT. Duplicate ids count once, but they count toward the 500-reference limit.Related:
How to trust this PR
The core logic is in
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/WaitForTx.hs.stepWaitForTxis the pure state machine: it takes a state and event, so its behaviour can be tested without a live node.waitForTxMethodconnects it to node kernel access and a chain follower. The remaining changes register the method, add its tracing constructor, and list the new modules in the cabal file.The unit tests in
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/WaitForTxStream.hsfeedstepWaitForTxscripted events. They cover:To run them, use the
cardano-rpc-testsuite ofcardano-rpc.The end-to-end tests run against a real testnet and live in cardano-node. They check that a transaction submitted after the stream opens reaches
STAGE_CONFIRMED, and that a malformed id givesINVALID_ARGUMENT. They are in the commit "Add WatchMempool and WaitForTx RPC E2E tests" on the branchmgalazyn/feature/rpc-mempool-support, which is the draft PR above. That PR also adds the tracer entries that the new span needs on the node side.Checklist
.changes/