Skip to content

Commit

Permalink
Merge pull request #2386 from CounterpartyXCP/develop
Browse files Browse the repository at this point in the history
v10.4.7
  • Loading branch information
adamkrellenstein authored Oct 17, 2024
2 parents 1d90c24 + 01c920f commit 24602fd
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
},
],
Expand Down Expand Up @@ -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)",
},
],
Expand Down
9 changes: 7 additions & 2 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -401,6 +403,8 @@ def run_api_server(args, interruped_value, server_ready_value):
logger.info("Starting API Server...")
app = init_flask_app()

wsgi_server = None

try:
# Init the HTTP Server.
wsgi_server = wsgi.WSGIApplication(app, args=args)
Expand All @@ -415,7 +419,8 @@ def run_api_server(args, interruped_value, server_ready_value):
logger.trace("Shutting down API Server...")
watcher.stop()
watcher.join()
wsgi_server.stop()
if wsgi_server is not None:
wsgi_server.stop()
APIDBConnectionPool().close()


Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
46 changes: 46 additions & 0 deletions counterparty-core/counterpartycore/test/regtest/testscenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions release-notes/release-notes-v10.4.7.md
Original file line number Diff line number Diff line change
@@ -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 `127.0.0.1` instead `localhost` as default for `API_HOST` and `RPC_HOST` (to force IPv4)

## CLI



# Credits

* Ouziel Slama
* Warren Puffett
* Adam Krellenstein

0 comments on commit 24602fd

Please sign in to comment.