Skip to content

Commit 644be65

Browse files
committed
cli: add -netinfo server version check and error message
1 parent ce57bf6 commit 644be65

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/bitcoin-cli.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ class NetinfoRequestHandler : public BaseRequestHandler
373373
if (!batch[ID_PEERINFO]["error"].isNull()) return batch[ID_PEERINFO];
374374
if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO];
375375

376+
const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]};
377+
if (networkinfo["version"].get_int() < 209900) {
378+
throw std::runtime_error("-netinfo requires bitcoind server to be running v0.21.0 and up");
379+
}
380+
376381
// Count peer connection totals, and if m_verbose is true, store peer data in a vector of structs.
377382
const int64_t time_now{GetSystemTimeInSeconds()};
378383
int ipv4_i{0}, ipv6_i{0}, onion_i{0}, block_relay_i{0}, total_i{0}; // inbound conn counters
@@ -430,7 +435,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
430435
}
431436

432437
// Generate report header.
433-
const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]};
434438
std::string result{strprintf("%s %s%s - %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())};
435439

436440
// Report detailed peer connections list sorted by direction and minimum ping time.

0 commit comments

Comments
 (0)