HomePhabricator

[Chronik-client] - Cycle through backup instances on outage

Description

[Chronik-client] - Cycle through backup instances on outage

Summary:
T3236

As part of mitigating the manual interventions involved in D14096 when the supplied Chronik instance keels over, this diff introduces a new FailoverProxy class exported from failoverProxy.ts which manages both regular and websocket endpoints, as well as the logic to cycle through an array of url/wsUrl endpoints should one become non-responsive.

As part of this refactor:

  • FailoverProxy is instantiated by the ChronikClient constructor, and upon instantiation the FailoverProxy constructor uses appendWsUrls to build an array of type Endpoint[] consisting of url and wsUrls.
  • _post, _get, _callAxios and _connect functions have all been moved into this FailoverProxy class in order to centralize all network handling logic and easily track the state of endpoint iteration.
  • Whilst the array of endpoints is cycled through, the most recent working endpoint is tracked via its index in the array to ensure efficient iteration.
  • All existing and future network related functions gets passed an instance of the same FailoverProxy class to ensure the regular and websocket endpoints are always sync'ed at all times.
  • The main update to the websocket connection logic (connectWs) was to close the websocket upon the onerror call back, which allows the loop to iterate to the next wsUrl.

Test Plan: npm test and observe the initial broken chronik instance and automatic switch over to the next available instance for the blockchaininfo test and then the subsequent tests where all urls are invalid.

Reviewers: bytesofman, #bitcoin_abc, Fabien, tobias_ruck

Reviewed By: bytesofman, #bitcoin_abc, Fabien, tobias_ruck

Subscribers: tobias_ruck, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D14269

Details

Provenance
emackAuthored on Jul 16 2023, 03:53
emackPushed on Nov 4 2023, 11:11
Reviewer
Restricted Project
Differential Revision
D14269: [Chronik-client] - Cycle through backup instances on outage
Parents
rABC1ed79850fc70: [Cashtab] Create targetOutput for a Cashtab Msg tx
Branches
Unknown
Tags
Unknown