Page MenuHomePhabricator

[Chronik] Implement FailoverProxy structure when interacting with Chronik in rust
ClosedPublic

Authored by hazzarust on Jul 3 2025, 13:52.

Details

Reviewers
Fabien
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Project
Commits
rABCdcea91fd9fd8: [Chronik] Implement FailoverProxy structure when interacting with Chronik in…
Summary

This diff adds failover.rs into bitcoinsuite-chronik-client. This file contains logic so that when we create a ChronikClient struct, it only contains one field: failover. This failover stores our client, our endpoints and working index. This allows us to keep track of multiple different endpoints that are accessible, so that in the future we can cycle to them upon downtime of one endpoint. The working index keeps track of which endpoint we are currently connected to. By having separate functions for FailoverProxy and ChronikClient, we are able to seperate the logic between the two, so that the FailoverProxy can focus on failover recovery, whereas the ChronikClient can focus on client functionality.

The cycling of endpoints upon endpoint failure will be added in a future diff.

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
run cargo test -- --nocapture in bitcoin-abc/modules/bitcoinsuite-chronik-client/tests

Event Timeline

Owners added a reviewer: Restricted Owners Package.Jul 3 2025, 13:52

Tail of the build log:

2025-07-03T14:11:57.839000Z TestFramework (INFO): Step 3: Mine a block with these txs
2025-07-03T14:11:57.943000Z TestFramework (INFO): Step 4: Finalize the block containing these txs with Avalanche
2025-07-03T14:12:00.104000Z TestFramework (INFO): Step 5: Park the block containing those txs
2025-07-03T14:12:00.108000Z TestFramework (INFO): Step 8: Unpark the block containing those txs
2025-07-03T14:12:00.114000Z TestFramework (INFO): Step 9: Manually invalidate the block containing those txs
2025-07-03T14:12:00.118000Z TestFramework (INFO): Step 10: Reconsider the block containing those txs
2025-07-03T14:12:00.124000Z TestFramework (INFO): Step 11: Broadcast a tx with mixed outputs
2025-07-03T14:12:00.133000Z TestFramework (INFO): Step 12: Mine another block
2025-07-03T14:12:00.237000Z TestFramework (INFO): Step 13: Avalanche rejects the block
2025-07-03T14:12:00.555000Z TestFramework (INFO): Step 14: Avalanche invalidates the block
2025-07-03T14:12:02.090000Z TestFramework (INFO): Step 15: Mine another block
2025-07-03T14:12:02.095000Z 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-07-03T14:12:02.146000Z TestFramework (INFO): Stopping nodes
2025-07-03T14:12:02.248000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_141147_29919/setup_scripts/chronik-client_websocket_0
2025-07-03T14:12:02.248000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_141147_29919/setup_scripts/chronik-client_websocket_0/test_framework.log
2025-07-03T14:12:02.249000Z TestFramework (ERROR): 
2025-07-03T14:12:02.249000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_141147_29919/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2025-07-03T14:12:02.249000Z TestFramework (ERROR): 
2025-07-03T14:12:02.249000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-07-03T14:12:02.249000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-07-03T14:12:02.250000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_websocket.py started
setup_scripts/chronik-client_websocket.py failed, Duration: 14 s

stdout:

stderr:


TEST                                      | STATUS    | DURATION

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

ALL                                       | ✖ Failed  | 14 s (accumulated) 
Runtime: 14 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 14.49s

error: test failed, to rerun pass `-p bitcoinsuite-chronik-client --test websocket`
Build build-bitcoinsuite-chronik-client failed with exit code 101
Fabien requested changes to this revision.Jul 3 2025, 15:44
Fabien added a subscriber: Fabien.

back to your queue

This revision now requires changes to proceed.Jul 3 2025, 15:44

Runs locally on CI, trying again.

Tail of the build log:

2025-07-03T16:42:37.189000Z TestFramework (INFO): Step 3: Mine a block with these txs
2025-07-03T16:42:37.194000Z TestFramework (INFO): Step 4: Finalize the block containing these txs with Avalanche
2025-07-03T16:42:39.734000Z TestFramework (INFO): Step 5: Park the block containing those txs
2025-07-03T16:42:39.738000Z TestFramework (INFO): Step 8: Unpark the block containing those txs
2025-07-03T16:42:39.742000Z TestFramework (INFO): Step 9: Manually invalidate the block containing those txs
2025-07-03T16:42:39.745000Z TestFramework (INFO): Step 10: Reconsider the block containing those txs
2025-07-03T16:42:39.748000Z TestFramework (INFO): Step 11: Broadcast a tx with mixed outputs
2025-07-03T16:42:39.756000Z TestFramework (INFO): Step 12: Mine another block
2025-07-03T16:42:39.760000Z TestFramework (INFO): Step 13: Avalanche rejects the block
2025-07-03T16:42:40.084000Z TestFramework (INFO): Step 14: Avalanche invalidates the block
2025-07-03T16:42:42.177000Z TestFramework (INFO): Step 15: Mine another block
2025-07-03T16:42:42.183000Z 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-07-03T16:42:42.235000Z TestFramework (INFO): Stopping nodes
2025-07-03T16:42:42.338000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_164226_52289/setup_scripts/chronik-client_websocket_0
2025-07-03T16:42:42.338000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_164226_52289/setup_scripts/chronik-client_websocket_0/test_framework.log
2025-07-03T16:42:42.338000Z TestFramework (ERROR): 
2025-07-03T16:42:42.338000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250703_164226_52289/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2025-07-03T16:42:42.339000Z TestFramework (ERROR): 
2025-07-03T16:42:42.339000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-07-03T16:42:42.339000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-07-03T16:42:42.339000Z 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.41s

error: test failed, to rerun pass `-p bitcoinsuite-chronik-client --test websocket`
Build build-bitcoinsuite-chronik-client failed with exit code 101
Fabien requested changes to this revision.Jul 4 2025, 07:13

Still not rebased properly and still failing. Stop wasting my time

This revision now requires changes to proceed.Jul 4 2025, 07:13

Tail of the build log:

2025-07-04T08:05:07.507000Z TestFramework (INFO): Step 3: Mine a block with these txs
2025-07-04T08:05:07.512000Z TestFramework (INFO): Step 4: Finalize the block containing these txs with Avalanche
2025-07-04T08:05:10.065000Z TestFramework (INFO): Step 5: Park the block containing those txs
2025-07-04T08:05:10.069000Z TestFramework (INFO): Step 8: Unpark the block containing those txs
2025-07-04T08:05:10.072000Z TestFramework (INFO): Step 9: Manually invalidate the block containing those txs
2025-07-04T08:05:10.075000Z TestFramework (INFO): Step 10: Reconsider the block containing those txs
2025-07-04T08:05:10.078000Z TestFramework (INFO): Step 11: Broadcast a tx with mixed outputs
2025-07-04T08:05:10.086000Z TestFramework (INFO): Step 12: Mine another block
2025-07-04T08:05:10.090000Z TestFramework (INFO): Step 13: Avalanche rejects the block
2025-07-04T08:05:10.426000Z TestFramework (INFO): Step 14: Avalanche invalidates the block
2025-07-04T08:05:12.607000Z TestFramework (INFO): Step 15: Mine another block
2025-07-04T08:05:12.612000Z 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-07-04T08:05:12.664000Z TestFramework (INFO): Stopping nodes
2025-07-04T08:05:12.767000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_080456_53525/setup_scripts/chronik-client_websocket_0
2025-07-04T08:05:12.767000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_080456_53525/setup_scripts/chronik-client_websocket_0/test_framework.log
2025-07-04T08:05:12.767000Z TestFramework (ERROR): 
2025-07-04T08:05:12.768000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_080456_53525/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2025-07-04T08:05:12.768000Z TestFramework (ERROR): 
2025-07-04T08:05:12.768000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-07-04T08:05:12.768000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-07-04T08:05:12.769000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_websocket.py started
setup_scripts/chronik-client_websocket.py failed, Duration: 17 s

stdout:

stderr:


TEST                                      | STATUS    | DURATION

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

ALL                                       | ✖ Failed  | 17 s (accumulated) 
Runtime: 17 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.74s

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

Tail of the build log:

2025-07-04T08:26:22.381000Z TestFramework (INFO): Step 3: Mine a block with these txs
2025-07-04T08:26:22.385000Z TestFramework (INFO): Step 4: Finalize the block containing these txs with Avalanche
2025-07-04T08:26:24.828000Z TestFramework (INFO): Step 5: Park the block containing those txs
2025-07-04T08:26:24.832000Z TestFramework (INFO): Step 8: Unpark the block containing those txs
2025-07-04T08:26:24.836000Z TestFramework (INFO): Step 9: Manually invalidate the block containing those txs
2025-07-04T08:26:24.839000Z TestFramework (INFO): Step 10: Reconsider the block containing those txs
2025-07-04T08:26:24.843000Z TestFramework (INFO): Step 11: Broadcast a tx with mixed outputs
2025-07-04T08:26:24.851000Z TestFramework (INFO): Step 12: Mine another block
2025-07-04T08:26:24.855000Z TestFramework (INFO): Step 13: Avalanche rejects the block
2025-07-04T08:26:25.220000Z TestFramework (INFO): Step 14: Avalanche invalidates the block
2025-07-04T08:26:27.287000Z TestFramework (INFO): Step 15: Mine another block
2025-07-04T08:26:27.292000Z 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-07-04T08:26:27.343000Z TestFramework (INFO): Stopping nodes
2025-07-04T08:26:27.446000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_082611_10096/setup_scripts/chronik-client_websocket_0
2025-07-04T08:26:27.447000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_082611_10096/setup_scripts/chronik-client_websocket_0/test_framework.log
2025-07-04T08:26:27.447000Z TestFramework (ERROR): 
2025-07-04T08:26:27.447000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-bitcoinsuite-chronik-client/test/tmp/test_runner_₿₵_🏃_20250704_082611_10096/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2025-07-04T08:26:27.447000Z TestFramework (ERROR): 
2025-07-04T08:26:27.448000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-07-04T08:26:27.448000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-07-04T08:26:27.448000Z 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.31s

error: test failed, to rerun pass `-p bitcoinsuite-chronik-client --test websocket`
Build build-bitcoinsuite-chronik-client failed with exit code 101
hazzarust retitled this revision from [Chronik] Add failover.rs to bitcoinsuite-chronik-client to [Chronik] Implement FailoverProxy structure when interacting with Chronik in rust .Jul 10 2025, 12:00
hazzarust edited the summary of this revision. (Show Details)
Fabien requested changes to this revision.Jul 11 2025, 11:10
Fabien added inline comments.
modules/bitcoinsuite-chronik-client/src/failover.rs
34

That's not tested

96

That's not tested

This revision now requires changes to proceed.Jul 11 2025, 11:10
hazzarust retitled this revision from [Chronik] Implement FailoverProxy structure when interacting with Chronik in rust to [Chronik] Implement FailoverProxy structure when interacting with Chronik in rust.

Added tests for new_emtpy_url_array and invalid_schema when appending ws urls

Will failover include reconnecting, switching endpoints when onclose timeout and resubscriptions?

Will failover include reconnecting, switching endpoints when onclose timeout and resubscriptions?

Yes, this will happen in the next diff.

This revision is now accepted and ready to land.Jul 15 2025, 07:54