cli: report the port actually dialled, not a stale global
dragonx-cli resolves -rpcport correctly -- CallRPC does
int port = GetArg("-rpcport", BaseParams().RPCPort());
and dials that port. But both connection-failure messages printed
ASSETCHAINS_RPCPORT instead, a separate global defined at the top of
bitcoin-cli.cpp, initialised to the mainnet default 21769, and never assigned
anywhere in the CLI.
So every failure claimed port 21769 regardless of what was asked for:
$ dragonx-cli -rpcport=21799 getblockcount
error: couldn't connect to server at port 21769
That reads as "your -rpcport was ignored", which is a much more alarming and
much more misleading diagnosis than "nothing is listening yet". It cost an hour
of debugging on a node that was simply still loading a 15 GB txindex, and led to
the wrong conclusion that the CLI could be talking to the production daemon when
it was not.
Both sites now print the local `port`. Verified against the previous binary:
new: -rpcport=21799 -> "couldn't connect to server at port 21799"
-rpcport=59999 -> "couldn't connect to server at port 59999"
old: both -> "couldn't connect to server at port 21769"
and the CLI still reaches a live daemon on a non-default port.
ASSETCHAINS_RPCPORT is left defined; it is referenced by other translation units.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FU87LdsJZiZkfq1eXubpeo
This commit is contained in:
@@ -257,14 +257,18 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
|
|||||||
event_base_dispatch(base.get());
|
event_base_dispatch(base.get());
|
||||||
|
|
||||||
if (response.status == 0) {
|
if (response.status == 0) {
|
||||||
|
// Report the port we ACTUALLY dialled. ASSETCHAINS_RPCPORT is a separate global that is
|
||||||
|
// initialised to the mainnet default at the top of this file and never assigned here, so
|
||||||
|
// using it made every failure claim port 21769 no matter what -rpcport was given -- which
|
||||||
|
// reads as "your -rpcport was ignored" and sends you chasing a config bug that isn't there.
|
||||||
throw CConnectionFailed(strprintf("couldn't connect to server at port %d : %s (code %d)\n(make sure server is running and you are connecting to the correct RPC port)",
|
throw CConnectionFailed(strprintf("couldn't connect to server at port %d : %s (code %d)\n(make sure server is running and you are connecting to the correct RPC port)",
|
||||||
ASSETCHAINS_RPCPORT, http_errorstring(response.error), response.error));
|
port, http_errorstring(response.error), response.error));
|
||||||
} else if (response.status == HTTP_UNAUTHORIZED) {
|
} else if (response.status == HTTP_UNAUTHORIZED) {
|
||||||
throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
|
throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
|
||||||
} else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR) {
|
} else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR) {
|
||||||
throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
|
throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
|
||||||
} else if (response.body.empty()) {
|
} else if (response.body.empty()) {
|
||||||
throw std::runtime_error(strprintf("no response from server at port %d", ASSETCHAINS_RPCPORT ));
|
throw std::runtime_error(strprintf("no response from server at port %d", port));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse reply
|
// Parse reply
|
||||||
|
|||||||
Reference in New Issue
Block a user