Skip to content

Commit b829894

Browse files
committed
Merge #20764: cli -netinfo peer connections dashboard updates 🎄 ✨
747cb5b netinfo: display only outbound block relay counts (Jon Atack) 76d198a netinfo: add i2p network (Jon Atack) 9d6aeca netinfo: add bip152 high-bandwidth to/from fields (Jon Atack) 5de7a6c netinfo: display manual peers count (Jon Atack) d3cca3b netinfo: update to use peer connection types (Jon Atack) 62bf5b7 netinfo: add ConnectionTypeForNetinfo member helper function (Jon Atack) Pull request description: Merry Bitcoin Christmas! Ho ho ho 🎄 ✨ This PR updates `-netinfo` to: - use the getpeerinfo `connection_type` field (and no longer use getpeerinfo `relaytxes` for block-relay detection) - display manual peers count, if any, in the outbound row - display the block relay counts in the outbound row only - display high-bandwidth BIP152 compact block relay peers (`hb` column, to `.` and from `*`) - add support for displaying I2P network peers, if any are present Testing and review welcome! How to test: - to run the full live dashboard (on Linux): `$ watch --interval 1 --no-title ./src/bitcoin-cli -netinfo 4` - to run the full dashboard: ``$ ./src/bitcoin-cli -netinfo 4`` - to see the help: `$ ./src/bitcoin-cli -netinfo help` - to see the help summary: `$ ./src/bitcoin-cli -help | grep -A4 netinfo` ACKs for top commit: laanwj: re-ACK 747cb5b michaelfolkson: ACK 747cb5b jonasschnelli: Tested ACK 747cb5b - works nicely. Great that this PR only changes bitcoin-cli. Tree-SHA512: 48fe23dddf3005a039190fcbc84167cd25b0a63489617fe14ea5db9a641a829b46b6e8dc7924aab6577d82a13909d157e82f715bd2ed3a8a15071957c35c19f3
2 parents a6b1bf6 + 747cb5b commit b829894

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

‎src/bitcoin-cli.cpp

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,12 @@ class NetinfoRequestHandler : public BaseRequestHandler
300300
{
301301
private:
302302
static constexpr int8_t UNKNOWN_NETWORK{-1};
303-
static constexpr uint8_t m_networks_size{3};
304-
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion"}};
305-
std::array<std::array<uint16_t, m_networks_size + 2>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total/block-relay)
303+
static constexpr int8_t NET_I2P{3}; // pos of "i2p" in m_networks
304+
static constexpr uint8_t m_networks_size{4};
305+
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion", "i2p"}};
306+
std::array<std::array<uint16_t, m_networks_size + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
307+
uint8_t m_block_relay_peers_count{0};
308+
uint8_t m_manual_peers_count{0};
306309
int8_t NetworkStringToId(const std::string& str) const
307310
{
308311
for (uint8_t i = 0; i < m_networks_size; ++i) {
@@ -316,12 +319,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
316319
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }
317320
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
318321
bool m_is_asmap_on{false};
322+
bool m_is_i2p_on{false};
319323
size_t m_max_addr_length{0};
320-
size_t m_max_age_length{4};
324+
size_t m_max_age_length{3};
321325
size_t m_max_id_length{2};
322326
struct Peer {
323327
std::string addr;
324328
std::string sub_version;
329+
std::string conn_type;
325330
std::string network;
326331
std::string age;
327332
double min_ping;
@@ -333,6 +338,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
333338
int id;
334339
int mapped_as;
335340
int version;
341+
bool is_bip152_hb_from;
342+
bool is_bip152_hb_to;
336343
bool is_block_relay;
337344
bool is_outbound;
338345
bool operator<(const Peer& rhs) const { return std::tie(is_outbound, min_ping) < std::tie(rhs.is_outbound, rhs.min_ping); }
@@ -351,6 +358,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
351358
const double milliseconds{round(1000 * seconds)};
352359
return milliseconds > 999999 ? "-" : ToString(milliseconds);
353360
}
361+
std::string ConnectionTypeForNetinfo(const std::string& conn_type) const
362+
{
363+
if (conn_type == "outbound-full-relay") return "full";
364+
if (conn_type == "block-relay-only") return "block";
365+
if (conn_type == "manual" || conn_type == "feeler") return conn_type;
366+
if (conn_type == "addr-fetch") return "addr";
367+
return "";
368+
}
354369
const UniValue NetinfoHelp()
355370
{
356371
return std::string{
@@ -379,21 +394,27 @@ class NetinfoRequestHandler : public BaseRequestHandler
379394
" type Type of peer connection\n"
380395
" \"full\" - full relay, the default\n"
381396
" \"block\" - block relay; like full relay but does not relay transactions or addresses\n"
397+
" \"manual\" - peer we manually added using RPC addnode or the -addnode/-connect config options\n"
398+
" \"feeler\" - short-lived connection for testing addresses\n"
399+
" \"addr\" - address fetch; short-lived connection for requesting addresses\n"
382400
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", or \"cjdns\")\n"
383401
" mping Minimum observed ping time, in milliseconds (ms)\n"
384402
" ping Last observed ping time, in milliseconds (ms)\n"
385403
" send Time since last message sent to the peer, in seconds\n"
386404
" recv Time since last message received from the peer, in seconds\n"
387405
" txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n"
388406
" blk Time since last novel block passing initial validity checks received from the peer, in minutes\n"
407+
" hb High-bandwidth BIP152 compact block relay\n"
408+
" \".\" (to) - we selected the peer as a high-bandwidth peer\n"
409+
" \"*\" (from) - the peer selected us as a high-bandwidth peer\n"
389410
" age Duration of connection to the peer, in minutes\n"
390411
" asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n"
391412
" peer selection (only displayed if the -asmap config option is set)\n"
392413
" id Peer index, in increasing order of peer connections since node startup\n"
393414
" address IP address and port of the peer\n"
394415
" version Peer version and subversion concatenated, e.g. \"70016/Satoshi:21.0.0/\"\n\n"
395416
"* The connection counts table displays the number of peers by direction, network, and the totals\n"
396-
" for each, as well as a column for block relay peers.\n\n"
417+
" for each, as well as two special outbound columns for block relay peers and manual peers.\n\n"
397418
"* The local addresses table lists each local address broadcast by the node, the port, and the score.\n\n"
398419
"Examples:\n\n"
399420
"Connection counts and local addresses only\n"
@@ -450,16 +471,16 @@ class NetinfoRequestHandler : public BaseRequestHandler
450471
const std::string network{peer["network"].get_str()};
451472
const int8_t network_id{NetworkStringToId(network)};
452473
if (network_id == UNKNOWN_NETWORK) continue;
474+
m_is_i2p_on |= (network_id == NET_I2P);
453475
const bool is_outbound{!peer["inbound"].get_bool()};
454476
const bool is_block_relay{!peer["relaytxes"].get_bool()};
477+
const std::string conn_type{peer["connection_type"].get_str()};
455478
++m_counts.at(is_outbound).at(network_id); // in/out by network
456479
++m_counts.at(is_outbound).at(m_networks_size); // in/out overall
457480
++m_counts.at(2).at(network_id); // total by network
458481
++m_counts.at(2).at(m_networks_size); // total overall
459-
if (is_block_relay) {
460-
++m_counts.at(is_outbound).at(m_networks_size + 1); // in/out block-relay
461-
++m_counts.at(2).at(m_networks_size + 1); // total block-relay
462-
}
482+
if (conn_type == "block-relay-only") ++m_block_relay_peers_count;
483+
if (conn_type == "manual") ++m_manual_peers_count;
463484
if (DetailsRequested()) {
464485
// Push data for this peer to the peers vector.
465486
const int peer_id{peer["id"].get_int()};
@@ -475,7 +496,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
475496
const std::string addr{peer["addr"].get_str()};
476497
const std::string age{conn_time == 0 ? "" : ToString((m_time_now - conn_time) / 60)};
477498
const std::string sub_version{peer["subver"].get_str()};
478-
m_peers.push_back({addr, sub_version, network, age, min_ping, ping, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_block_relay, is_outbound});
499+
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
500+
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
501+
m_peers.push_back({addr, sub_version, conn_type, network, age, min_ping, ping, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_bip152_hb_from, is_bip152_hb_to, is_block_relay, is_outbound});
479502
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
480503
m_max_age_length = std::max(age.length(), m_max_age_length);
481504
m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length);
@@ -489,22 +512,23 @@ class NetinfoRequestHandler : public BaseRequestHandler
489512
// Report detailed peer connections list sorted by direction and minimum ping time.
490513
if (DetailsRequested() && !m_peers.empty()) {
491514
std::sort(m_peers.begin(), m_peers.end());
492-
result += strprintf("<-> relay net mping ping send recv txn blk %*s ", m_max_age_length, "age");
515+
result += strprintf("<-> type net mping ping send recv txn blk hb %*s ", m_max_age_length, "age");
493516
if (m_is_asmap_on) result += " asmap ";
494517
result += strprintf("%*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : "");
495518
for (const Peer& peer : m_peers) {
496519
std::string version{ToString(peer.version) + peer.sub_version};
497520
result += strprintf(
498-
"%3s %5s %5s%7s%7s%5s%5s%5s%5s %*s%*i %*s %-*s%s\n",
521+
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*i %*s %-*s%s\n",
499522
peer.is_outbound ? "out" : "in",
500-
peer.is_block_relay ? "block" : "full",
523+
ConnectionTypeForNetinfo(peer.conn_type),
501524
peer.network,
502525
PingTimeToString(peer.min_ping),
503526
PingTimeToString(peer.ping),
504527
peer.last_send == 0 ? "" : ToString(m_time_now - peer.last_send),
505528
peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv),
506529
peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60),
507530
peer.last_blck == 0 ? "" : ToString((m_time_now - peer.last_blck) / 60),
531+
strprintf("%s%s", peer.is_bip152_hb_to ? "." : " ", peer.is_bip152_hb_from ? "*" : " "),
508532
m_max_age_length, // variable spacing
509533
peer.age,
510534
m_is_asmap_on ? 7 : 0, // variable spacing
@@ -515,18 +539,27 @@ class NetinfoRequestHandler : public BaseRequestHandler
515539
IsAddressSelected() ? peer.addr : "",
516540
IsVersionSelected() && version != "0" ? version : "");
517541
}
518-
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
542+
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
519543
}
520544

521545
// Report peer connection totals by type.
522-
result += " ipv4 ipv6 onion total block-relay\n";
546+
result += " ipv4 ipv6 onion";
547+
if (m_is_i2p_on) result += " i2p";
548+
result += " total block";
549+
if (m_manual_peers_count) result += " manual";
523550
const std::array<std::string, 3> rows{{"in", "out", "total"}};
524-
for (uint8_t i = 0; i < m_networks_size; ++i) {
525-
result += strprintf("%-5s %5i %5i %5i %5i %5i\n", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
551+
for (uint8_t i = 0; i < 3; ++i) {
552+
result += strprintf("\n%-5s %5i %5i %5i", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2)); // ipv4/ipv6/onion peers counts
553+
if (m_is_i2p_on) result += strprintf(" %5i", m_counts.at(i).at(3)); // i2p peers count
554+
result += strprintf(" %5i", m_counts.at(i).at(m_networks_size)); // total peers count
555+
if (i == 1) { // the outbound row has two extra columns for block relay and manual peer counts
556+
result += strprintf(" %5i", m_block_relay_peers_count);
557+
if (m_manual_peers_count) result += strprintf(" %5i", m_manual_peers_count);
558+
}
526559
}
527560

528561
// Report local addresses, ports, and scores.
529-
result += "\nLocal addresses";
562+
result += "\n\nLocal addresses";
530563
const std::vector<UniValue>& local_addrs{networkinfo["localaddresses"].getValues()};
531564
if (local_addrs.empty()) {
532565
result += ": n/a\n";

0 commit comments

Comments
 (0)