Skip to content

Commit 22fa911

Browse files
committed
Add -netinfo level 5 for dev/testing, move addr stats to it
The idea is for detail level 5 to display data that is more suited to development and testing purposes than to everyday node operators.
1 parent 3934384 commit 22fa911

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/bitcoin-cli.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void SetupCliArgs(ArgsManager& argsman)
6363
argsman.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC getnewaddress followed by RPC generatetoaddress. Optional positional integer arguments are number of blocks to generate (default: %s) and maximum iterations to try (default: %s), equivalent to RPC generatetoaddress nblocks and maxtries arguments. Example: bitcoin-cli -generate 4 1000", DEFAULT_NBLOCKS, DEFAULT_MAX_TRIES), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6464
argsman.AddArg("-addrinfo", "Get the number of addresses known to the node, per network and total.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6565
argsman.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
66-
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 4 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
66+
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 5 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6767

6868
SetupChainParamsBaseOptions(argsman);
6969
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -357,7 +357,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
357357
class NetinfoRequestHandler : public BaseRequestHandler
358358
{
359359
private:
360-
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
360+
static constexpr uint8_t MAX_DETAIL_LEVEL{5};
361361
static constexpr std::array m_networks{"ipv4", "ipv6", "onion", "i2p"};
362362
std::array<std::array<uint16_t, m_networks.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
363363
uint8_t m_block_relay_peers_count{0};
@@ -370,9 +370,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
370370
return UNKNOWN_NETWORK;
371371
}
372372
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
373-
bool DetailsRequested() const { return m_details_level > 0 && m_details_level < 5; }
374-
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
375-
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
373+
bool DetailsRequested() const { return m_details_level != 0; }
374+
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level >= 4; }
375+
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level >= 4; }
376+
bool IsAddrStatsSelected() const { return m_details_level >= 5; }
376377
bool m_is_asmap_on{false};
377378
size_t m_max_addr_length{0};
378379
size_t m_max_addr_processed_length{6};
@@ -507,7 +508,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
507508
if (DetailsRequested() && !m_peers.empty()) {
508509
std::sort(m_peers.begin(), m_peers.end());
509510
result += strprintf("<-> type net mping ping send recv txn blk hb %*s", m_max_age_length, "age");
510-
result += strprintf("%*s%*s", m_max_addr_rate_limited_length, "addrl", m_max_addr_processed_length, "addrp");
511+
if (IsAddrStatsSelected()) result += strprintf("%*s%*s", m_max_addr_rate_limited_length, "addrl", m_max_addr_processed_length, "addrp");
511512
if (m_is_asmap_on) result += " asmap";
512513
result += strprintf(" %*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : "");
513514
for (const Peer& peer : m_peers) {
@@ -526,10 +527,10 @@ class NetinfoRequestHandler : public BaseRequestHandler
526527
strprintf("%s%s", peer.is_bip152_hb_to ? "." : " ", peer.is_bip152_hb_from ? "*" : " "),
527528
m_max_age_length, // variable spacing
528529
peer.age,
529-
m_max_addr_rate_limited_length, // variable spacing
530-
peer.addr_rate_limited ? ToString(peer.addr_rate_limited) : "",
531-
m_max_addr_processed_length, // variable spacing
532-
peer.addr_processed ? ToString(peer.addr_processed) : "",
530+
IsAddrStatsSelected() ? m_max_addr_rate_limited_length : 0, // variable spacing
531+
IsAddrStatsSelected() && peer.addr_rate_limited ? ToString(peer.addr_rate_limited) : "",
532+
IsAddrStatsSelected() ? m_max_addr_processed_length : 0, // variable spacing
533+
IsAddrStatsSelected() && peer.addr_processed ? ToString(peer.addr_processed) : "",
533534
m_is_asmap_on ? 7 : 0, // variable spacing
534535
m_is_asmap_on && peer.mapped_as != 0 ? ToString(peer.mapped_as) : "",
535536
m_max_id_length, // variable spacing
@@ -592,6 +593,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
592593
" 2 - Like 1 but with an address column\n"
593594
" 3 - Like 1 but with a version column\n"
594595
" 4 - Like 1 but with both address and version columns\n"
596+
" 5 - Like 4 but with additional data for development and testing purposes\n"
595597
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
596598
"Result:\n\n"
597599
+ strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", MAX_DETAIL_LEVEL) +

0 commit comments

Comments
 (0)