Page MenuHomePhabricator

[chronik-client] Support websocket subscriptions to txid
ClosedPublic

Authored by bytesofman on Jun 13 2025, 17:38.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABCb3393d04efb2: [chronik-client] Support websocket subscriptions to txid
Summary

Add support for websocket subscriptions to txid

Note: changes to chronik.ts from running the script npm run build-proto

This is a tricky one to test. Would be nice to have just one new file for testing txid ws subscriptions. However, I'm not able to figure out how to make the txids deterministic in tests that finalize blocks with avalanche. We want to show that we can subscribe to a txid before it is broadcast and see it through its various lifecycle stages.

To do this, we

  • Show we can get a tx finalized notification in websockets.ts
  • Show we can get added and removed from mempool notifications in ws_txid.ts, which is an almost-exact-recreation of mempool_conflicts.ts but refactored for txid subs

We could also duplicate websockets.ts and refactor for txid subs. I think this is a bit overkill for the feature introduced here. The issue is that the existing subs tested in websockets.ts would conflict with txid subs. If we subscribe to a txid and also to a script that receives that txid, we only expect one msg to come in for txid events. So we can't really test "both" subscriptions in the same script / test file.

Test Plan

CI tests

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Failed tests logs:

====== Test expected websocket behavior of chronik-client when subscribing to a websocket: Conflicting block is mined.Test expected websocket behavior of chronik-client when subscribing to a websocket Conflicting block is mined ======
AssertionError: expected { type: 'Tx', …(2) } to deeply equal { type: 'Tx', …(2) }
    at Context.<anonymous> (test/integration/ws_txid.ts:165:40)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

      + expected - actual

       {
         "msgType": "TX_REMOVED_FROM_MEMPOOL"
      -  "txid": "f80dfe71a17292307725ce108aae92dcc30d8096792dc5f5c7053ba02581ed44"
      +  "txid": "163a4c095b117d5523bd7b6fc2c1fa310e33e2ab3a698d0480279cd3bb140814"
         "type": "Tx"
       }

Each failure log is accessible here:
Test expected websocket behavior of chronik-client when subscribing to a websocket: Conflicting block is mined.Test expected websocket behavior of chronik-client when subscribing to a websocket Conflicting block is mined

bytesofman edited the summary of this revision. (Show Details)

update test for non-deterministic order of remove msgs

Not sure if this helps, but one of the issue with tx determinism in the test framework comes from random data being used for padding transactions to 100 bytes.
In D17933 I added a deterministic arg to pad_tx to make it use deterministic data.

pad_tx(tx) -> pad_tx(tx, 100, deterministic=True)

This revision is now accepted and ready to land.Jun 14 2025, 13:26