From 1bc8da83a3e2b4cac74edb181fa66cabe16a10db Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Thu, 17 Oct 2024 13:01:54 +0000 Subject: [PATCH 1/5] Remove hop-by-hop header --- counterparty-core/counterpartycore/lib/api/api_server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/counterparty-core/counterpartycore/lib/api/api_server.py b/counterparty-core/counterpartycore/lib/api/api_server.py index 8eb4e3434..7cdc16223 100644 --- a/counterparty-core/counterpartycore/lib/api/api_server.py +++ b/counterparty-core/counterpartycore/lib/api/api_server.py @@ -319,7 +319,9 @@ def handle_route(**kwargs): message += f" - Response {result.status_code}" message += f" - {int((time.time() - start_time) * 1000)}ms" logger.debug(message) - return result.content, result.status_code, result.headers.items() + headers = dict(result.headers) + del headers["Connection"] # remove "hop-by-hop" headers + return result.content, result.status_code, headers # clean up and return the result if result is None: From 97545144bff5baaa4bff0a1855d9cc7a7dba90ce Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Thu, 17 Oct 2024 13:13:09 +0000 Subject: [PATCH 2/5] 127.0.0.1 instead localhost --- counterparty-core/counterpartycore/cli.py | 4 ++-- counterparty-core/counterpartycore/server.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/counterparty-core/counterpartycore/cli.py b/counterparty-core/counterpartycore/cli.py index 51b1a98ff..f98399bc1 100755 --- a/counterparty-core/counterpartycore/cli.py +++ b/counterparty-core/counterpartycore/cli.py @@ -154,7 +154,7 @@ def float_range_checker(arg): [ ("--rpc-host",), { - "default": "localhost", + "default": "127.0.0.1", "help": "the IP of the interface to bind to for providing JSON-RPC API access (0.0.0.0 for all interfaces)", }, ], @@ -191,7 +191,7 @@ def float_range_checker(arg): [ ("--api-host",), { - "default": "localhost", + "default": "127.0.0.1", "help": "the IP of the interface to bind to for providing API access (0.0.0.0 for all interfaces)", }, ], diff --git a/counterparty-core/counterpartycore/server.py b/counterparty-core/counterpartycore/server.py index ac1c6ced6..47d7ab8e1 100755 --- a/counterparty-core/counterpartycore/server.py +++ b/counterparty-core/counterpartycore/server.py @@ -355,7 +355,7 @@ def initialise_config( if rpc_host: config.RPC_HOST = rpc_host else: - config.RPC_HOST = "localhost" + config.RPC_HOST = "127.0.0.1" # The web root directory for API calls, eg. localhost:14000/rpc/ config.RPC_WEBROOT = "/rpc/" @@ -415,7 +415,7 @@ def initialise_config( if api_host: config.API_HOST = api_host else: - config.API_HOST = "localhost" + config.API_HOST = "127.0.0.1" # Server API port if api_port: From db854c283259e125650f3bdbc32e965e81ec04da Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Thu, 17 Oct 2024 13:19:11 +0000 Subject: [PATCH 3/5] use waitress for tests --- counterparty-core/counterpartycore/test/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/counterparty-core/counterpartycore/test/conftest.py b/counterparty-core/counterpartycore/test/conftest.py index 91d678120..ec0de0b89 100644 --- a/counterparty-core/counterpartycore/test/conftest.py +++ b/counterparty-core/counterpartycore/test/conftest.py @@ -315,7 +315,7 @@ def api_server_v2(request, cp_server): "zmq_publisher_port": None, "db_connection_pool_size": None, "json_logs": False, - "wsgi_server": "werkzeug", + "wsgi_server": "waitress", "gunicorn_workers": 2, } server_config = ( From 0724ca34e84dccbf6ec7ceefaa3c1517ece8cc60 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Thu, 17 Oct 2024 13:59:21 +0000 Subject: [PATCH 4/5] check API v1 on regtest --- .../test/regtest/testscenarios.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/counterparty-core/counterpartycore/test/regtest/testscenarios.py b/counterparty-core/counterpartycore/test/regtest/testscenarios.py index 70abbd6f6..c29b11725 100644 --- a/counterparty-core/counterpartycore/test/regtest/testscenarios.py +++ b/counterparty-core/counterpartycore/test/regtest/testscenarios.py @@ -237,6 +237,50 @@ def run_item(node, item, context): return context +def rpc_call(command, params=None): + if params is None: + params = [] + curl_client = sh.curl.bake( + "-X", + "POST", + "http://localhost:24000/v1/", + "-H", + "Content-Type: application/json; charset=UTF-8", + "-H", + "Accept: application/json, text/javascript", + "--data-binary", + ) + query = { + "method": command, + "params": params, + "jsonrpc": "2.0", + "id": 0, + } + result = json.loads(curl_client(json.dumps(query)).strip()) + return result + + +def check_api_v1(node): + running_info = rpc_call("get_running_info") + + if not running_info["result"]["server_ready"]: + raise Exception("Server not ready") + if not running_info["result"]["db_caught_up"]: + raise Exception("DB not caught up") + + tx = rpc_call( + "create_send", + { + "source": node.addresses[0], + "destination": node.addresses[1], + "asset": "XCP", + "quantity": 1, + }, + ) + # check that the hex transaction is generated + int(tx["result"], 16) + + def run_scenarios(serve=False, wsgi_server="gunicorn"): try: regtest_node_thread = RegtestNodeThread(wsgi_server=wsgi_server) @@ -247,6 +291,8 @@ def run_scenarios(serve=False, wsgi_server="gunicorn"): context = {} + check_api_v1(regtest_node_thread.node) + # run all scenarios for item in SCENARIOS: context = run_item(regtest_node_thread.node, item, context) From 6104fe32d02d95d53bf1f43ed879a1536aa8ad32 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Thu, 17 Oct 2024 14:05:33 +0000 Subject: [PATCH 5/5] Add release notes --- release-notes/release-notes-v10.4.7.md | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 release-notes/release-notes-v10.4.7.md diff --git a/release-notes/release-notes-v10.4.7.md b/release-notes/release-notes-v10.4.7.md new file mode 100644 index 000000000..bba6ea270 --- /dev/null +++ b/release-notes/release-notes-v10.4.7.md @@ -0,0 +1,29 @@ +# Release Notes - Counterparty Core v10.4.7 (2024-10-17) + +This is a Hotfix release to fix API v1 with Waitress. + +# Upgrading + +# ChangeLog + +## Bugfixes + +- Fix API v1 with Waitress (remove hop-by-hop headers) + +## Codebase + +- Check API v1 in regtest test suite + +## API + +- Use `120.0.0.1` instead `localhost` as default for `API_HOST` and `RPC_HOST` (to force IPv4) + +## CLI + + + +# Credits + +* Ouziel Slama +* Warren Puffett +* Adam Krellenstein