Page MenuHomePhabricator

[Chronik] Add script subscription functionality to websocket.rs in bitcoinsuite-chronik-client
ClosedPublic

Authored by hazzarust on May 25 2025, 17:26.

Details

Reviewers
Fabien
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Project
Commits
rABCf53a1bd5b254: [Chronik] Add script subscription functionality to websocket.rs in bitcoinsuite…
Summary

The code adds WebSocket functionality for a Bitcoin blockchain explorer (Chronik), specifically the subscription and unsubscription to scripts:

Creates subscriptions to different script types (P2PKH, P2SH, P2PK, Other) with subscribe_to_script()

Verifies subscription status with assert_eq!(ep.subs.scripts, subscriptions)

Tests unsubscribing with unsubscribe_from_script()

Validates error handling for invalid/non-existent script subscriptions

Receives real-time notifications for transactions affecting subscribed scripts (mempool, confirmed, finalized events)

Test Plan

Please set BUILD_DIR env to export BUILD_DIR="/path/to/build_dir
UNIX: ./contrib/teamcity/build-configurations.py build-bitcoinsuite-chronik-client

Diff Detail

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

Event Timeline

Owners added a reviewer: Restricted Owners Package.May 25 2025, 17:26
hazzarust retitled this revision from [Chronik] Add script subscription functionality to websocket.rs in bitcoinsuite-chroni-client to [Chronik] Add script subscription functionality to websocket.rs in bitcoinsuite-chronik-client.

Removing handler change as not needed in this diff

Fabien added inline comments.
chronik/bitcoinsuite-core/src/address.rs
38 ↗(On Diff #54165)

I don't think any of this needs to be public

modules/bitcoinsuite-chronik-client/tests/websocket.rs
307 ↗(On Diff #54165)

hash is only field that needs to be pub

modules/bitcoinsuite-chronik-client/tests/websocket.rs
194 ↗(On Diff #54166)
Fabien added inline comments.
modules/bitcoinsuite-chronik-client/tests/websocket.rs
963 ↗(On Diff #54168)

Maybe we could check nothing happens within a short timeout, like 1s, but not blocking for that

This revision is now accepted and ready to land.May 26 2025, 09:16

Tail of the build log:

2025-05-28T15:09:40.169000Z TestFramework (INFO): Step 2: Broadcast 1 tx to a p2pk, p2pkh, and p2sh address
2025-05-28T15:09:40.200000Z TestFramework (INFO): Step 3: Mine a block with these txs
2025-05-28T15:09:40.205000Z TestFramework (INFO): Step 4: Finalize the block containing these txs with Avalanche
2025-05-28T15:09:42.506000Z TestFramework (INFO): Step 5: Park the block containing those txs
2025-05-28T15:09:42.510000Z TestFramework (INFO): Step 8: Unpark the block containing those txs
2025-05-28T15:09:42.514000Z TestFramework (INFO): Step 9: Manually invalidate the block containing those txs
2025-05-28T15:09:42.517000Z TestFramework (INFO): Step 10: Reconsider the block containing those txs
2025-05-28T15:09:42.521000Z TestFramework (INFO): Step 11: Broadcast a tx with mixed outputs
2025-05-28T15:09:42.530000Z TestFramework (INFO): Step 12: Mine another block
2025-05-28T15:09:42.534000Z TestFramework (INFO): Step 13: Avalanche rejects the block
2025-05-28T15:09:42.839000Z TestFramework (INFO): Step 14: Avalanche invalidates the block
2025-05-28T15:09:44.926000Z TestFramework (INFO): Step 15: Mine another block
2025-05-28T15:09:44.931000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/setup_scripts/../test_framework/test_framework.py", line 152, in main
    self._run_test_internal()
  File "/work/test/functional/setup_scripts/setup_framework.py", line 51, in _run_test_internal
    cmds = receive_ipc_messages(timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/test/functional/setup_scripts/ipc.py", line 67, in receive_ipc_messages
    if messages[-1].endswith(b"\n"):
       ~~~~~~~~^^^^
IndexError: list index out of range
2025-05-28T15:09:44.982000Z TestFramework (INFO): Stopping nodes
2025-05-28T15:09:45.084000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250528_150928_22181/setup_scripts/chronik-client_websocket_0
2025-05-28T15:09:45.084000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250528_150928_22181/setup_scripts/chronik-client_websocket_0/test_framework.log
2025-05-28T15:09:45.084000Z TestFramework (ERROR): 
2025-05-28T15:09:45.084000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250528_150928_22181/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2025-05-28T15:09:45.084000Z TestFramework (ERROR): 
2025-05-28T15:09:45.084000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-05-28T15:09:45.084000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-05-28T15:09:45.084000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_websocket.py started
setup_scripts/chronik-client_websocket.py failed, Duration: 16 s

stdout:

stderr:


TEST                                      | STATUS    | DURATION

setup_scripts/chronik-client_websocket.py | ✖ Failed  | 16 s

ALL                                       | ✖ Failed  | 16 s (accumulated) 
Runtime: 16 s


thread 'websocket' panicked at /work/modules/bitcoinsuite-chronik-client/src/test_runner.rs:82:9:
Test chronik-client_websocket failed!


failures:
    websocket

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 16.53s

error: test failed, to rerun pass `-p bitcoinsuite-chronik-client --test websocket`
Build build-bitcoinsuite-chronik-client failed with exit code 101

not sure why its failing - working locally