Page MenuHomePhabricator

[chronik-client] [DRAFT] Support in-node chronik
AbandonedPublic

Authored by bytesofman on Nov 8 2023, 21:06.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Summary

Support for in-node instance of chronik with new ChronikClientNode class

A number of factors led me to refactor this library to support two distinct classes, one for working with an NNG chronik server, and one for working with an in-node chronik server.

  1. The proto files proto/chronik.ts and proto/chronik_nng.ts are generated by a script and correspond exactly with proto files of the respective chronik server. It would be messy and thankless to combine these files.
  2. Since the ChronikClient class supports an array of server URLs -- imo the complication of validating each array for a different server type is not worth the expected benefit. Writing an app to use one type of server and then fall back on the other type would be a bad idea.
  3. User (app developer) should be aware of the methods exposed by each chronik server type. The distinct proto files support this. The distinct class definitions also support this, as there are some intricacies in how the chronik-client user must shape requests.

Note: Websocket has been tested with https://chronik.be.cash/xec2 and gets good results there. The websocket from https://chronik-native.fabien.cash is not available, potentially an issue with nginx setup.
Note: The chronik-info endpoint is not currently tested as it is not available on a public server.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
chronik-client-support-version-endpoint
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 25663
Build 50906: Build Diffchronik-client-tests
Build 50905: arc lint + arc unit

Event Timeline

to be rebased on latest master

sample output from websocket subscribed to blocks and a single address:

ws open
msg {
  type: 'Tx',
  msgType: 'AddedToMempool',
  txid: 'ef1b7ec808e1fc287147ec50bf7faa5440e84bc008b77cfbbe4355222b373c6e'
}
msg {
  type: 'Block',
  msgType: 'Connected',
  blockHash: '00000000000000000024ec7b6cc66b9881dde1fe678865ef0bd1212573200e31',
  blockHeight: 817693
}
msg {
  type: 'Tx',
  msgType: 'Confirmed',
  txid: 'ef1b7ec808e1fc287147ec50bf7faa5440e84bc008b77cfbbe4355222b373c6e'
}
msg {
  type: 'Tx',
  msgType: 'Finalized',
  txid: 'ef1b7ec808e1fc287147ec50bf7faa5440e84bc008b77cfbbe4355222b373c6e'
}
msg {
  type: 'Block',
  msgType: 'Finalized',
  blockHash: '00000000000000000024ec7b6cc66b9881dde1fe678865ef0bd1212573200e31',
  blockHeight: 817693
}
msg {
  type: 'Block',
  msgType: 'Connected',
  blockHash: '00000000000000001275d86bc1db7ca84c27ec8e8e00d3d4ff26c37cfab4c191',
  blockHeight: 817694
}
msg {
  type: 'Block',
  msgType: 'Finalized',
  blockHash: '00000000000000001275d86bc1db7ca84c27ec8e8e00d3d4ff26c37cfab4c191',
  blockHeight: 817694
}
msg {
  type: 'Block',
  msgType: 'Connected',
  blockHash: '00000000000000000b16da75478a2af65e9a984864fa328038dc0260488ccee2',
  blockHeight: 817695
}
msg {
  type: 'Block',
  msgType: 'Finalized',
  blockHash: '00000000000000000b16da75478a2af65e9a984864fa328038dc0260488ccee2',
  blockHeight: 817695
}
msg {
  type: 'Block',
  msgType: 'Connected',
  blockHash: '00000000000000000827c8bd306c259c1f79803102346fdfba48fac8e38ca5e8',
  blockHeight: 817696
}
msg {
  type: 'Block',
  msgType: 'Finalized',
  blockHash: '00000000000000000827c8bd306c259c1f79803102346fdfba48fac8e38ca5e8',
  blockHeight: 817696
}
  • need to fix the websocket mgmt in failover proxy
  • better file organization, total nightmare dealing with two "kinda the same except very different in certain ways" classes that interact with these servers ... imo keeping them siloed is the best way to do it, but it's almost worth just having a separate library

Need to self review, look at file names and organization, add failover proxy ws tests for in-node chronik

sharing failoverProxy, support ws iterations for in-node

bytesofman retitled this revision from [chronik-client] Support in-node chronik to [chronik-client] [DRAFT] Support in-node chronik.Nov 17 2023, 19:23

update: draft up for review.

It would be possible to do a more compact approach, for example having only one ChronikClient object that checks the version-info endpoint and then offers different methods depending on nng or in-node server. However,

  1. This requires a good deal of complexity in terms of managing the slightly-similar-but-not-the-same types for shared methods
  2. Also complicates deprecation
  3. app developers should not write an app for either type of chronik instance

The approach here is backwards compatible, with anyone wishing to use an in-node chronik server needing to specifically instantiate the ChronikClientNode object. It's not the minimum amount of code -- but, as we do not anticipate adding new features to NNG, it will be more straightforward to work with ChronikClientNode class until we are ready to deprecate NNG.

Fabien added inline comments.
modules/chronik-client/package.json
10

This could break the workflow for scripts, you should do the opposite

15

nit: keep the naming consistent: test-nng, test-node

modules/chronik-client/src/ChronikClientNNG.ts
3

Is that renaming to proto_nng necessary ? This doesn't add any value as it's in the nng file already

This could be split into several diffs, for example file/var renames could be their own diffs. Same for the @generated mark on the proto ts file. This makes it easier to spot the where the changes are.

This could be split into several diffs, for example file/var renames could be their own diffs. Same for the @generated mark on the proto ts file. This makes it easier to spot the where the changes are.

tentative plan here:

  • Update the proto script in package.json + generate the new proto file D14814
  • Repo organization, proto and src folders, with index.js exporting everything D14823

Rename NNG types that will conflict with ChronikClientNode (even though these types are in separate files, bc they are used by ChronikClient and ChronikClientNode, and both objects are exported, ts will not allow them to have the same name)

  • Add keepAlive method to websocket D14831
  • Add in-node ChronikClientNode class and unit tests D14840
  • README update, include dev section for proto script and usage section for in-node

edit:

  • Make sure ws msg strings are not mixed case, just do lowercase
  • no need to rename nng types, if that file is unchanged, don't change it. Use new type names for in-node
modules/chronik-client/package.json
10

couple actions here

  • imo best to just remove the legacy script here for NNG, as it will not work in the monorepo -- only from a local file system with bitcoinsuite-chronik-client in the right place
  • Add a Dev section to README.md explaining this script and its role in generating protobuf types/methods
modules/chronik-client/src/ChronikClientNNG.ts
3

just an artifact of the script calling the "in-node" one chronik, and not wanting them to be the same name. will make the new one 'chronik-node' and avoid this rename

Rename NNG types that will conflict with ChronikClientNode (even though these types are in separate files, bc they are used by ChronikClient and ChronikClientNode, and both objects are exported, ts will not allow them to have the same name)

Is there no kind of namespace ? Or maybe make it a member of the ChronikClient

Rename NNG types that will conflict with ChronikClientNode (even though these types are in separate files, bc they are used by ChronikClient and ChronikClientNode, and both objects are exported, ts will not allow them to have the same name)

Is there no kind of namespace ? Or maybe make it a member of the ChronikClient

I can just use new type names for the in-node version, which makes sense as they are the new types that are slightly distinct from the old ones. My original thinking was that it would be nice to have cleaner types in the in-node file as NNG will probably be unmaintained, but since NNG is the only version that supports non-eCash chains, it will prob always be maintained in some way.

Fabien requested changes to this revision.Nov 23 2023, 16:53

Clearing my queue, it's getting split into parts

This revision now requires changes to proceed.Nov 23 2023, 16:53

this is being rebuilt in parts