Page MenuHomePhabricator

[chronik-client] Support connection to in-node chronik
AbandonedPublic

Authored by bytesofman on Oct 6 2023, 00:10.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Summary

chronik has slightly different features in node vs the original nng. This diff handles these distinctions:

  • in-node chronik does not provide BlockDetails from the chronik.block call
  • in-node chronik provides isFinal key and numTxs key for tx history
  • in-node chronik provdes isFinal key for utxos
  • in-node chronik returns utxos as an object, rather than an array of one object. For simplicity, force a return of array of one object.
Test Plan

npm test

Diff Detail

Event Timeline

still need to review for completeness, approach. Uses this as a work in progress in some local testing and not really sure what's even here until I review it.

Tail of the build log:

  /blockchain-info
    ✔ gives us the blockchain info (534ms)

  /block/:hash
    ✔ gives us the Genesis block by hash (329ms)
    ✔ gives us the Genesis block by height (426ms)

  /blocks/:start/:end
    ✔ gives us the first few blocks (439ms)

  /tx/:txid
    ✔ results in Not Found
    ✔ results in the right tx (412ms)

  /token/:tokenId is not supported in the node, results in error
    ✔ existing tokenId gives error

  /validate-utxos is not supported in the node, results in error
    ✔ Correct input throws error as method is not supported in in-node chronik

  /script/:type/:payload/history
    ✔ gives us the first page (321ms)
    ✔ gives us an empty page for ?page=1 (306ms)
    ✔ gives us just one tx for ?page_size=1 (320ms)
    ✔ gives us the Genesis tx for ?page=1&page_size=1 (324ms)

  /script/:type/:payload/utxos
    ✔ gives us the UTXOs (324ms)

  /ws
    - gives us a confirmation
    ✔ connects to the ws (319ms)


  17 passing (4s)
  1 pending

------------|---------|----------|---------|---------|----------------------------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                            
------------|---------|----------|---------|---------|----------------------------------------------
All files   |   35.15 |    11.63 |   30.83 |   35.13 |                                              
 chronik.ts |   29.58 |     8.73 |      20 |   29.77 | ...6-3969,3981,3986-3993,3998-4004,4039-4044 
 hex.ts     |   94.73 |       50 |     100 |   93.93 | 47,55                                        
 index.ts   |   64.59 |     46.2 |      80 |   64.87 | ...3,636,654-663,674-683,731-734,754-758,775 
------------|---------|----------|---------|---------|----------------------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='618']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='1758']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='225']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='1934']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='103']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='334']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='610']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='1736']
##teamcity[blockClosed name='Code Coverage Summary']
/work/modules/chronik-client/coverage/lcov-report /work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
/work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
mv: cannot stat 'test_results/chronik-client-junit.xml': No such file or directory
Build chronik-client-tests failed with exit code 1

still needs completeness and sanity check self-review

Tail of the build log:

  /blockchain-info
    ✔ gives us the blockchain info (423ms)

  /block/:hash
    ✔ gives us the Genesis block by hash (317ms)
    ✔ gives us the Genesis block by height (307ms)

  /blocks/:start/:end
    ✔ gives us the first few blocks (321ms)

  /tx/:txid
    ✔ results in Not Found
    ✔ results in the right tx (318ms)

  /token/:tokenId is not supported in the node, results in error
    ✔ existing tokenId gives error

  /validate-utxos is not supported in the node, results in error
    ✔ Correct input throws error as method is not supported in in-node chronik

  /script/:type/:payload/history
    ✔ gives us the first page (314ms)
    ✔ gives us an empty page for ?page=1 (309ms)
    ✔ gives us just one tx for ?page_size=1 (310ms)
    ✔ gives us the Genesis tx for ?page=1&page_size=1 (306ms)

  /script/:type/:payload/utxos
    ✔ gives us the UTXOs (303ms)

  /ws
    - gives us a confirmation
    ✔ connects to the ws (295ms)


  17 passing (4s)
  1 pending

------------|---------|----------|---------|---------|----------------------------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                            
------------|---------|----------|---------|---------|----------------------------------------------
All files   |   35.15 |    11.63 |   30.83 |   35.13 |                                              
 chronik.ts |   29.58 |     8.73 |      20 |   29.77 | ...6-3969,3981,3986-3993,3998-4004,4039-4044 
 hex.ts     |   94.73 |       50 |     100 |   93.93 | 47,55                                        
 index.ts   |   64.59 |     46.2 |      80 |   64.87 | ...3,636,654-663,674-683,731-734,754-758,775 
------------|---------|----------|---------|---------|----------------------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='618']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='1758']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='225']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='1934']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='103']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='334']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='610']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='1736']
##teamcity[blockClosed name='Code Coverage Summary']
/work/modules/chronik-client/coverage/lcov-report /work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
/work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
mv: cannot stat 'test_results/chronik-client-junit.xml': No such file or directory
Build chronik-client-tests failed with exit code 1

websocket connection test patch, add in-node specific test results for in-node tests

Tail of the build log:

    ✔ throws a decode error

  /blockchain-info
    ✔ gives us the blockchain info (516ms)

  /block/:hash
    ✔ gives us the Genesis block by hash (427ms)
    ✔ gives us the Genesis block by height (453ms)

  /blocks/:start/:end
    ✔ gives us the first few blocks (420ms)

  /tx/:txid
    ✔ results in Not Found
    ✔ results in the right tx (355ms)

  /token/:tokenId is not supported in the node, results in error
    ✔ existing tokenId gives error

  /validate-utxos is not supported in the node, results in error
    ✔ Correct input throws error as method is not supported in in-node chronik

  /script/:type/:payload/history
    ✔ gives us the first page (326ms)
    ✔ gives us an empty page for ?page=1 (450ms)
    ✔ gives us just one tx for ?page_size=1 (329ms)
    ✔ gives us the Genesis tx for ?page=1&page_size=1 (316ms)

  /script/:type/:payload/utxos
    ✔ gives us the UTXOs (324ms)

  /ws
    ✔ connects to the ws (311ms)


  17 passing (4s)

------------|---------|----------|---------|---------|----------------------------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                            
------------|---------|----------|---------|---------|----------------------------------------------
All files   |   35.15 |    11.63 |   30.83 |   35.13 |                                              
 chronik.ts |   29.58 |     8.73 |      20 |   29.77 | ...6-3969,3981,3986-3993,3998-4004,4039-4044 
 hex.ts     |   94.73 |       50 |     100 |   93.93 | 47,55                                        
 index.ts   |   64.59 |     46.2 |      80 |   64.87 | ...3,636,654-663,674-683,731-734,754-758,775 
------------|---------|----------|---------|---------|----------------------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='618']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='1758']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='225']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='1934']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='103']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='334']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='610']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='1736']
##teamcity[blockClosed name='Code Coverage Summary']
/work/modules/chronik-client/coverage/lcov-report /work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
/work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests
mv: cannot stat 'test_results/chronik-client-junit.xml': No such file or directory
Build chronik-client-tests failed with exit code 1

ok I know what's going on with the teamcity tests, troubleshooting

improve comments, keep unit tests in one file, move fixtures to generated fixtures file

Unit tests pass now. This version would "work" with in-node chronik however still some improvements needed before this should be published.

  1. Still getting network: BCH from in-node chronik server, need to investigate, see if this is coming from chronik or if the decode method needs to be amended for in-node
  2. Websocket connects, however the existing subscription methods in chronik-client do not work for in-node. Need to be updated to handle both or need separate methods.

do not return 'network' key for in-node chronik

Apply consistent fix to Tx and Utxo type

Still getting network: BCH from in-node chronik server, need to investigate, see if this is coming from chronik or if the decode method needs to be amended for in-node

this is resolved. was an issue bc in-node chronik does not return network (sensibly...since XEC is uh, strongly implied).

Patched so that no network key is returned for in-node chronik. I did not modify the Token interface as this is currently only returned by nng.

Still gotta do the websocket.

Digging into this --- implementing websocket subscriptions is a big change. Will probably require the introduction of a new ChronikClientNode class, or at least a new websocket class, since the existing methods do not support in-node types and the in-node types are distinct enough that shimming them in is impractical ("shimming them in" i.e. how this diff supports the Utxo and Tx type for nng and in-node, since the distinction is only a matter of including a network key or an isFinal key in a response object).

NNG

in-node

Each type is composed of distinct subtypes, which are sometimes composed of their own unique subtypes, e.g. https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/chronik/chronik-proto/proto/chronik.proto#L227j

All of these types need their own class and encode/decode methods in chronik.ts.

So -- this diff should be reviewed here. chronik-client should not be published until the websocket implementation is good, but websocket implementation should be its own diff.

Fabien requested changes to this revision.Oct 12 2023, 19:51
Fabien added a subscriber: Fabien.

I think the general approach is not right.

You are trying to make the client work with both variants by determining at runtime for each call whether it fits one or the other.
This is a dangerous strategy because you are introducing behavioral changes in the NNG version, potentially ignoring bugs that were properly catched before.

You client should determine once for all at creation time if it is expecting nng or in-node, and stick to it. So that if the client is working against a nng version, it doesn't just drop some part of the data if something goes wrong on the backend only because it is the expected behavior for the in-node version.

modules/chronik-client/chronik.ts
982

This is a change in behavior for the nng version as well right ? what happens if network == 0 ?

This revision now requires changes to proceed.Oct 12 2023, 19:51

Need to determine nng or in-node on startup and route to correct methods from there. With the more substantial changes that are required to get this to work with the websocket, consider refactoring the codebase so that nng and in-node methods / types are in their own files.

Also worth considering whether to use D14269 as a baseline since that refactors ~60% of chronik-client