Page MenuHomePhabricator

[chronik] add macros to extract params from a JSONRPC request
ClosedPublic

Authored by PiRK on Fri, Dec 13, 14:32.

Details

Reviewers
Fabien
tobias_ruck
Group Reviewers
Restricted Project
Maniphest Tasks
Restricted Maniphest Task
Commits
rABC719ef6251e2e: [chronik] add macros to extract params from a JSONRPC request
Summary

The get_param! and get_optional_param! macros will be reused a lot as more methods are added.

Depends on D17314
Ref T3598

Test Plan

ninja check-functional

Event Timeline

PiRK requested review of this revision.Fri, Dec 13, 14:32
chronik/chronik-http/src/electrum.rs
370–373

It would be nice to also include this json type-check in the get_optional_param macro, but I wasn't able to figure out how to do it.

PiRK retitled this revision from [chronik] add templates to extract params from a JSONRPC request to [chronik] add macros to extract params from a JSONRPC request.Fri, Dec 13, 14:40
PiRK edited the summary of this revision. (Show Details)

Failed tests logs:

====== Bitcoin ABC functional tests: chronik_mempool_conflicts.py ======

------- Stdout: -------
2024-12-13T14:53:39.082000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-chronik/test/tmp/test_runner_₿₵_🏃_20241213_144949/chronik_mempool_conflicts_208
2024-12-13T14:53:41.592000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 635, in start_nodes
    node.wait_for_rpc_connection()
  File "/work/test/functional/test_framework/test_node.py", line 353, in wait_for_rpc_connection
    raise FailedToStartError(
test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status 1 during initialization

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 148, in main
    self.setup()
  File "/work/test/functional/test_framework/test_framework.py", line 383, in setup
    self.setup_network()
  File "/work/test/functional/test_framework/test_framework.py", line 490, in setup_network
    self.setup_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 515, in setup_nodes
    self.start_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 638, in start_nodes
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized
2024-12-13T14:53:41.644000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/chronik_mempool_conflicts.py", line 103, in <module>
    ChronikMempoolConflicts().main()
  File "/work/test/functional/test_framework/test_framework.py", line 172, in main
    exit_code = self.shutdown()
                ^^^^^^^^^^^^^^^
  File "/work/test/functional/test_framework/test_framework.py", line 398, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized
====== Bitcoin ABC functional tests: chronik_token_slp_nft1.py ======

------- Stdout: -------
2024-12-13T14:53:42.915000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-chronik/test/tmp/test_runner_₿₵_🏃_20241213_144949/chronik_token_slp_nft1_221
2024-12-13T14:53:45.425000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 635, in start_nodes
    node.wait_for_rpc_connection()
  File "/work/test/functional/test_framework/test_node.py", line 353, in wait_for_rpc_connection
    raise FailedToStartError(
test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status 1 during initialization

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 148, in main
    self.setup()
  File "/work/test/functional/test_framework/test_framework.py", line 383, in setup
    self.setup_network()
  File "/work/test/functional/test_framework/test_framework.py", line 490, in setup_network
    self.setup_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 515, in setup_nodes
    self.start_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 638, in start_nodes
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized
2024-12-13T14:53:45.476000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/chronik_token_slp_nft1.py", line 261, in <module>
    ChronikTokenSlpNft1().main()
  File "/work/test/functional/test_framework/test_framework.py", line 172, in main
    exit_code = self.shutdown()
                ^^^^^^^^^^^^^^^
  File "/work/test/functional/test_framework/test_framework.py", line 398, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized

Each failure log is accessible here:
Bitcoin ABC functional tests: chronik_mempool_conflicts.py
Bitcoin ABC functional tests: chronik_token_slp_nft1.py

PiRK planned changes to this revision.Fri, Dec 13, 19:00

c'est cassé

remove the small intermediate macros that only have one callsite. They just make the logic harder to follow.

Failed tests logs:

====== Bitcoin ABC functional tests: chronik_blocks.py ======

------- Stdout: -------
2024-12-13T20:49:51.031000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-chronik-plugins/test/tmp/test_runner_₿₵_🏃_20241213_204734/chronik_blocks_204
2024-12-13T20:49:51.786000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 635, in start_nodes
    node.wait_for_rpc_connection()
  File "/work/test/functional/test_framework/test_node.py", line 353, in wait_for_rpc_connection
    raise FailedToStartError(
test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status 1 during initialization

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 148, in main
    self.setup()
  File "/work/test/functional/test_framework/test_framework.py", line 383, in setup
    self.setup_network()
  File "/work/test/functional/test_framework/test_framework.py", line 490, in setup_network
    self.setup_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 515, in setup_nodes
    self.start_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 638, in start_nodes
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized
2024-12-13T20:49:51.837000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/chronik_blocks.py", line 101, in <module>
    ChronikBlockRangeTest().main()
  File "/work/test/functional/test_framework/test_framework.py", line 172, in main
    exit_code = self.shutdown()
                ^^^^^^^^^^^^^^^
  File "/work/test/functional/test_framework/test_framework.py", line 398, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized

Each failure log is accessible here:
Bitcoin ABC functional tests: chronik_blocks.py

PiRK planned changes to this revision.Fri, Dec 13, 22:01

There seems to be some kind if intermittent issue introduced by this diff or it's parent. To be investigated.

These issues are likely port collisions

2024-12-13T20:49:51.570827Z [chronik/chronik-lib/src/bridge.rs:181] [<chronik unknown>] Starting Chronik Electrum interface bound to [(127.0.0.1:33252, Tcp)]
2024-12-13T20:49:51.574474Z [chronik/chronik-indexer/src/indexer.rs:1491] [<chronik unknown>] Chronik Electrum failed serving: Address already in use (os error 98)
2024-12-13T20:49:51.574503Z [/work/src/shutdown.cpp:22] [AbortNode] *** ERROR Chronik in ChronikElectrumServer::serve
2024-12-13T20:49:51.574521Z [/work/src/noui.cpp:42] [noui_ThreadSafeMessageBox] Error: Chronik Electrum failed serving: Address already in use (os error 98)

@bot build-chronik build-chronik-plugins

Fabien requested changes to this revision.Mon, Dec 16, 11:06
Fabien added a subscriber: Fabien.

I would love to see a test for these error cases, since blockchain.transaction.get has both a mandatory and an optional arg it fits perfectly

This revision now requires changes to proceed.Mon, Dec 16, 11:06

test all errors responses

PiRK planned changes to this revision.Mon, Dec 16, 12:47
PiRK added inline comments.
chronik/chronik-http/src/electrum.rs
363–365 ↗(On Diff #51614)

i'm going to move this change to the parent diff

Failed tests logs:

====== Bitcoin ABC functional tests: chronik_token_slp_nft1.py ======

------- Stdout: -------
2024-12-16T12:55:23.432000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-chronik/test/tmp/test_runner_₿₵_🏃_20241216_125224/chronik_token_slp_nft1_221
2024-12-16T12:55:25.189000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 635, in start_nodes
    node.wait_for_rpc_connection()
  File "/work/test/functional/test_framework/test_node.py", line 353, in wait_for_rpc_connection
    raise FailedToStartError(
test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status 1 during initialization

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 148, in main
    self.setup()
  File "/work/test/functional/test_framework/test_framework.py", line 383, in setup
    self.setup_network()
  File "/work/test/functional/test_framework/test_framework.py", line 490, in setup_network
    self.setup_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 515, in setup_nodes
    self.start_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 638, in start_nodes
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized
2024-12-16T12:55:25.241000Z TestFramework (INFO): Stopping nodes
[node 0] Cleaning up leftover process
------- Stderr: -------
Traceback (most recent call last):
  File "/work/test/functional/chronik_token_slp_nft1.py", line 261, in <module>
    ChronikTokenSlpNft1().main()
  File "/work/test/functional/test_framework/test_framework.py", line 172, in main
    exit_code = self.shutdown()
                ^^^^^^^^^^^^^^^
  File "/work/test/functional/test_framework/test_framework.py", line 398, in shutdown
    self.stop_nodes()
  File "/work/test/functional/test_framework/test_framework.py", line 653, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/work/test/functional/test_framework/test_node.py", line 515, in stop_node
    self.stop(wait=wait)
    ^^^^^^^^^
  File "/work/test/functional/test_framework/test_node.py", line 283, in __getattr__
    assert self.rpc is not None, self._node_msg("Error: RPC not initialized")
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: [node 0] Error: RPC not initialized

Each failure log is accessible here:
Bitcoin ABC functional tests: chronik_token_slp_nft1.py

This revision is now accepted and ready to land.Mon, Dec 16, 13:54

rebase after reducing the port range in D17314