Page MenuHomePhabricator

[Chronik] Add `-chronikcors`
ClosedPublic

Authored by tobias_ruck on Apr 29 2024, 17:24.

Details

Reviewers
Fabien
PiRK
Group Reviewers
Restricted Project
Commits
rABC9ca3785dbd58: [Chronik] Add `-chronikcors`
Summary

Currently, if someone wants to use Chronik from a browser, they have to add an intermediary reverse proxy like NGINX (see here).

This adds the hidden -chronikcors flag, which allows users to connect to their instance directly (e.g. on localhost) without having to run a reverse proxy adding the CORS headers.

One example of this would be an app dev that wants to run a regtest instance locally and connect their webapp to that local regtest instance to try it out. Currently, this would throw CORS errors in all browsers with no mechanism to disable it in the browser, and devs would have to add a proxy locally to add those headers.

The option is hidden because we don't want users to enable it without care, as Chronik is intended to be run behind a reverse proxy (to e.g. add HTTPS or enforce rate limits).

Test Plan

./test/functional/test_runner.py chronik_cors.py

Diff Detail

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

Event Timeline

Tail of the build log:

  File "/work/test/functional/setup_scripts/../test_framework/test_framework.py", line 147, in main
    self._run_test_internal()
  File "/work/test/functional/setup_scripts/setup_framework.py", line 52, in _run_test_internal
    raise TimeoutError(f"No IPC message after {timeout}s, exiting")
TimeoutError: No IPC message after 10s, exiting
2024-04-29T17:55:52.394000Z TestFramework (INFO): Stopping nodes
2024-04-29T17:55:52.950000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_175539/setup_scripts/chronik-client_block_and_blocks_0
2024-04-29T17:55:52.950000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_175539/setup_scripts/chronik-client_block_and_blocks_0/test_framework.log
2024-04-29T17:55:52.951000Z TestFramework (ERROR): 
2024-04-29T17:55:52.951000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_175539/setup_scripts/chronik-client_block_and_blocks_0' to consolidate all logs
2024-04-29T17:55:52.951000Z TestFramework (ERROR): 
2024-04-29T17:55:52.952000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2024-04-29T17:55:52.952000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2024-04-29T17:55:52.952000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_block_and_blocks.py started
setup_scripts/chronik-client_block_and_blocks.py failed, Duration: 13 s

stdout:

stderr:


TEST                                             | STATUS    | DURATION

setup_scripts/chronik-client_block_and_blocks.py | โœ– Failed  | 13 s

ALL                                              | โœ– Failed  | 13 s (accumulated) 
Runtime: 13 s

Test runner for chronik-client_block_and_blocks completed with code 1
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |    5.25 |     0.63 |    1.49 |    5.22 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |    4.81 |     0.68 |    1.86 |    4.82 |                                   
  chronik.ts           |    5.44 |     0.84 |    1.81 |    5.42 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |    4.33 |     0.55 |     1.9 |    4.36 | ...,4882-4921,4929-5033,5037-5042 
 chronik-client/src    |    7.58 |        0 |       0 |    7.38 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 33-163,178-222,290-692            
  ChronikClientNode.ts |    6.34 |        0 |       0 |    6.34 | 33-183,198-276,289-361,428-1004   
  failoverProxy.ts     |    5.71 |        0 |       0 |    5.88 | 34-317                            
  hex.ts               |   31.57 |        0 |       0 |   33.33 | 33-37,41-45,49-62,66-68           
  validation.ts        |      15 |        0 |       0 |   10.52 | 12-47                             
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='215']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='4095']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='28']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='4422']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='11']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='737']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='212']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='4056']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1

Failed tests logs:

====== Get blocktxs, txs, and history for SLP NFT1 token txs: "before each" hook for "Gets an SLP NFT1 child genesis tx from the mempool".Get blocktxs, txs, and history for SLP NFT1 token txs "before each" hook for "Gets an SLP NFT1 child genesis tx from the mempool" ======
Error: Timeout of 60000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/work/modules/chronik-client/test/integration/token_slp_nft1.ts)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7)

Each failure log is accessible here:
Get blocktxs, txs, and history for SLP NFT1 token txs: "before each" hook for "Gets an SLP NFT1 child genesis tx from the mempool".Get blocktxs, txs, and history for SLP NFT1 token txs "before each" hook for "Gets an SLP NFT1 child genesis tx from the mempool"

Tail of the build log:

  File "/work/test/functional/setup_scripts/../test_framework/test_framework.py", line 147, in main
    self._run_test_internal()
  File "/work/test/functional/setup_scripts/setup_framework.py", line 52, in _run_test_internal
    raise TimeoutError(f"No IPC message after {timeout}s, exiting")
TimeoutError: No IPC message after 10s, exiting
2024-04-29T18:43:10.419000Z TestFramework (INFO): Stopping nodes
2024-04-29T18:43:10.974000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_184257/setup_scripts/chronik-client_block_and_blocks_0
2024-04-29T18:43:10.975000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_184257/setup_scripts/chronik-client_block_and_blocks_0/test_framework.log
2024-04-29T18:43:10.975000Z TestFramework (ERROR): 
2024-04-29T18:43:10.975000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_184257/setup_scripts/chronik-client_block_and_blocks_0' to consolidate all logs
2024-04-29T18:43:10.975000Z TestFramework (ERROR): 
2024-04-29T18:43:10.975000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2024-04-29T18:43:10.975000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2024-04-29T18:43:10.975000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_block_and_blocks.py started
setup_scripts/chronik-client_block_and_blocks.py failed, Duration: 13 s

stdout:

stderr:


TEST                                             | STATUS    | DURATION

setup_scripts/chronik-client_block_and_blocks.py | โœ– Failed  | 13 s

ALL                                              | โœ– Failed  | 13 s (accumulated) 
Runtime: 13 s

Test runner for chronik-client_block_and_blocks completed with code 1
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |    5.25 |     0.63 |    1.49 |    5.22 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |    4.81 |     0.68 |    1.86 |    4.82 |                                   
  chronik.ts           |    5.44 |     0.84 |    1.81 |    5.42 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |    4.33 |     0.55 |     1.9 |    4.36 | ...,4882-4921,4929-5033,5037-5042 
 chronik-client/src    |    7.58 |        0 |       0 |    7.38 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 33-163,178-222,290-692            
  ChronikClientNode.ts |    6.34 |        0 |       0 |    6.34 | 33-183,198-276,289-361,428-1004   
  failoverProxy.ts     |    5.71 |        0 |       0 |    5.88 | 34-317                            
  hex.ts               |   31.57 |        0 |       0 |   33.33 | 33-37,41-45,49-62,66-68           
  validation.ts        |      15 |        0 |       0 |   10.52 | 12-47                             
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='215']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='4095']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='28']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='4422']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='11']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='737']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='212']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='4056']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1

Tail of the build log:

  File "/work/test/functional/setup_scripts/../test_framework/util.py", line 297, in wait_until_helper
    raise AssertionError(
AssertionError: Predicate ''''
            self.wait_until(lambda: is_finalblock(next_blockhash))
''' not true after 60.0 seconds
2024-04-29T21:00:42.797000Z TestFramework (INFO): Stopping nodes
2024-04-29T21:00:43.353000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_205930/setup_scripts/chronik-client_websocket_0
2024-04-29T21:00:43.353000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_205930/setup_scripts/chronik-client_websocket_0/test_framework.log
2024-04-29T21:00:43.353000Z TestFramework (ERROR): 
2024-04-29T21:00:43.354000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/chronik-client-integration-tests/test/tmp/test_runner_โ‚ฟโ‚ต_๐Ÿƒ_20240429_205930/setup_scripts/chronik-client_websocket_0' to consolidate all logs
2024-04-29T21:00:43.354000Z TestFramework (ERROR): 
2024-04-29T21:00:43.354000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2024-04-29T21:00:43.354000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2024-04-29T21:00:43.355000Z TestFramework (ERROR): 
Running Unit Tests for Test Framework Modules
setup_scripts/chronik-client_websocket.py started
setup_scripts/chronik-client_websocket.py failed, Duration: 73 s

stdout:

stderr:


TEST                                      | STATUS    | DURATION

setup_scripts/chronik-client_websocket.py | โœ– Failed  | 73 s

ALL                                       | โœ– Failed  | 73 s (accumulated) 
Runtime: 73 s

Test runner for chronik-client_websocket completed with code 1
-----------------------|---------|----------|---------|---------|-----------------------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                 
-----------------------|---------|----------|---------|---------|-----------------------------------
All files              |   27.47 |    10.47 |   23.06 |   27.49 |                                   
 chronik-client        |     100 |      100 |     100 |     100 |                                   
  index.ts             |     100 |      100 |     100 |     100 |                                   
 chronik-client/proto  |   21.54 |     7.98 |   13.72 |   21.69 |                                   
  chronik.ts           |     6.1 |        1 |    2.54 |    6.09 | ...,3978-3985,3990-4027,4031-4036 
  chronikNode.ts       |   33.15 |    13.34 |   23.49 |    33.4 | ...,4882-4921,4929-5002,5037-5042 
 chronik-client/src    |    63.1 |    42.72 |   60.54 |   62.74 |                                   
  ChronikClient.ts     |    4.24 |        0 |       0 |    4.29 | 33-163,178-222,290-692            
  ChronikClientNode.ts |   90.07 |    70.89 |   95.71 |   90.07 | ...52,876,888,898,923,935,941,947 
  failoverProxy.ts     |   76.19 |    59.09 |   66.66 |   75.49 | ...61-264,267,275-285,294,303,307 
  hex.ts               |   89.47 |       75 |      75 |   87.87 | 58,66-68                          
  validation.ts        |      90 |    84.61 |     100 |   89.47 | 31,37                             
-----------------------|---------|----------|---------|---------|-----------------------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='1125']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='4095']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='463']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='4422']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='170']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='737']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='1115']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='4056']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/chronik-client-integration-tests-junit.xml': No such file or directory
Build chronik-client-integration-tests failed with exit code 1
This revision is now accepted and ready to land.Apr 30 2024, 08:33
Fabien requested changes to this revision.Apr 30 2024, 08:34

This is something that needs to be considered by the user, I'm not sure adding an option for the niche use case of a dev on localhost (which can already figure this out easily) is a good idea.

This revision now requires changes to proceed.Apr 30 2024, 08:34
This revision is now accepted and ready to land.Apr 30 2024, 15:21
This revision was automatically updated to reflect the committed changes.