Skip to content

Commit a70768d

Browse files
committed
Merge bitcoin/bitcoin#22501: netinfo: display addr_{processed, rate_limited, relay_enabled} and relaytxes data
218862a Display peers in -netinfo that we don't relay addresses to (Jon Atack) 3834e23 Display peers in -netinfo that request we not relay transactions (Jon Atack) 0a9ee3a Simplify a few conditionals in -netinfo (Jon Atack) 5eeea8e Add addr_processed and addr_rate_limited stats to -netinfo (Jon Atack) Pull request description: Update CLI -netinfo to display the getpeerinfo `addr_processed`, `addr_rate_limited`, `addr_relay_enabled` and `relaytxes` data with auto-adjusting column widths. ``` $ ./src/bitcoin-cli -netinfo help txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes "*" - the peer requested we not relay transactions to it (relaytxes is false) addrp Total number of addresses processed, excluding those dropped due to rate limiting "." - we do not relay addresses to this peer (addr_relay_enabled is false) addrl Total number of addresses dropped due to rate limiting ``` ![Screenshot from 2021-08-22 14-31-40](https://user-images.githubusercontent.com/2415484/130355514-f6fd4f21-79d6-463b-9791-de01ebef20b1.png) ACKs for top commit: 0xB10C: Code review and tested ACK 218862a Zero-1729: re-tACK 218862a vasild: ACK 218862a jarolrod: tACK 218862a Tree-SHA512: bb9da4bdd71859b234f6e4c2c46257a57ef0d0e0b363d2b8fded128bcaa28132f64a0a4651c622e1de1e3b7c05c7587a4369e9e79799895884fda9745c63409d
2 parents b997dd2 + 218862a commit a70768d

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/bitcoin-cli.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
386386
bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; }
387387
bool m_is_asmap_on{false};
388388
size_t m_max_addr_length{0};
389-
size_t m_max_age_length{3};
389+
size_t m_max_addr_processed_length{5};
390+
size_t m_max_addr_rate_limited_length{6};
391+
size_t m_max_age_length{5};
390392
size_t m_max_id_length{2};
391393
struct Peer {
392394
std::string addr;
@@ -396,13 +398,16 @@ class NetinfoRequestHandler : public BaseRequestHandler
396398
std::string age;
397399
double min_ping;
398400
double ping;
401+
int64_t addr_processed;
402+
int64_t addr_rate_limited;
399403
int64_t last_blck;
400404
int64_t last_recv;
401405
int64_t last_send;
402406
int64_t last_trxn;
403407
int id;
404408
int mapped_as;
405409
int version;
410+
bool is_addr_relay_enabled;
406411
bool is_bip152_hb_from;
407412
bool is_bip152_hb_to;
408413
bool is_block_relay;
@@ -483,6 +488,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
483488
const int peer_id{peer["id"].get_int()};
484489
const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()};
485490
const int version{peer["version"].get_int()};
491+
const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].get_int64()};
492+
const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].get_int64()};
486493
const int64_t conn_time{peer["conntime"].get_int64()};
487494
const int64_t last_blck{peer["last_block"].get_int64()};
488495
const int64_t last_recv{peer["lastrecv"].get_int64()};
@@ -493,10 +500,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
493500
const std::string addr{peer["addr"].get_str()};
494501
const std::string age{conn_time == 0 ? "" : ToString((m_time_now - conn_time) / 60)};
495502
const std::string sub_version{peer["subver"].get_str()};
503+
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
496504
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
497505
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
498-
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});
506+
m_peers.push_back({addr, sub_version, conn_type, network, age, min_ping, ping, addr_processed, addr_rate_limited, last_blck, last_recv, last_send, last_trxn, peer_id, mapped_as, version, is_addr_relay_enabled, is_bip152_hb_from, is_bip152_hb_to, is_block_relay, is_outbound});
499507
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
508+
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
509+
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
500510
m_max_age_length = std::max(age.length(), m_max_age_length);
501511
m_max_id_length = std::max(ToString(peer_id).length(), m_max_id_length);
502512
m_is_asmap_on |= (mapped_as != 0);
@@ -509,34 +519,41 @@ class NetinfoRequestHandler : public BaseRequestHandler
509519
// Report detailed peer connections list sorted by direction and minimum ping time.
510520
if (DetailsRequested() && !m_peers.empty()) {
511521
std::sort(m_peers.begin(), m_peers.end());
512-
result += strprintf("<-> type net mping ping send recv txn blk hb %*s ", m_max_age_length, "age");
522+
result += strprintf("<-> type net mping ping send recv txn blk hb %*s%*s%*s ",
523+
m_max_addr_processed_length, "addrp",
524+
m_max_addr_rate_limited_length, "addrl",
525+
m_max_age_length, "age");
513526
if (m_is_asmap_on) result += " asmap ";
514527
result += strprintf("%*s %-*s%s\n", m_max_id_length, "id", IsAddressSelected() ? m_max_addr_length : 0, IsAddressSelected() ? "address" : "", IsVersionSelected() ? "version" : "");
515528
for (const Peer& peer : m_peers) {
516529
std::string version{ToString(peer.version) + peer.sub_version};
517530
result += strprintf(
518-
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*i %*s %-*s%s\n",
531+
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n",
519532
peer.is_outbound ? "out" : "in",
520533
ConnectionTypeForNetinfo(peer.conn_type),
521534
peer.network,
522535
PingTimeToString(peer.min_ping),
523536
PingTimeToString(peer.ping),
524-
peer.last_send == 0 ? "" : ToString(m_time_now - peer.last_send),
525-
peer.last_recv == 0 ? "" : ToString(m_time_now - peer.last_recv),
526-
peer.last_trxn == 0 ? "" : ToString((m_time_now - peer.last_trxn) / 60),
527-
peer.last_blck == 0 ? "" : ToString((m_time_now - peer.last_blck) / 60),
537+
peer.last_send ? ToString(m_time_now - peer.last_send) : "",
538+
peer.last_recv ? ToString(m_time_now - peer.last_recv) : "",
539+
peer.last_trxn ? ToString((m_time_now - peer.last_trxn) / 60) : peer.is_block_relay ? "*" : "",
540+
peer.last_blck ? ToString((m_time_now - peer.last_blck) / 60) : "",
528541
strprintf("%s%s", peer.is_bip152_hb_to ? "." : " ", peer.is_bip152_hb_from ? "*" : " "),
542+
m_max_addr_processed_length, // variable spacing
543+
peer.addr_processed ? ToString(peer.addr_processed) : peer.is_addr_relay_enabled ? "" : ".",
544+
m_max_addr_rate_limited_length, // variable spacing
545+
peer.addr_rate_limited ? ToString(peer.addr_rate_limited) : "",
529546
m_max_age_length, // variable spacing
530547
peer.age,
531548
m_is_asmap_on ? 7 : 0, // variable spacing
532-
m_is_asmap_on && peer.mapped_as != 0 ? ToString(peer.mapped_as) : "",
549+
m_is_asmap_on && peer.mapped_as ? ToString(peer.mapped_as) : "",
533550
m_max_id_length, // variable spacing
534551
peer.id,
535552
IsAddressSelected() ? m_max_addr_length : 0, // variable spacing
536553
IsAddressSelected() ? peer.addr : "",
537554
IsVersionSelected() && version != "0" ? version : "");
538555
}
539-
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
556+
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
540557
}
541558

542559
// Report peer connection totals by type.
@@ -610,10 +627,14 @@ class NetinfoRequestHandler : public BaseRequestHandler
610627
" send Time since last message sent to the peer, in seconds\n"
611628
" recv Time since last message received from the peer, in seconds\n"
612629
" txn Time since last novel transaction received from the peer and accepted into our mempool, in minutes\n"
630+
" \"*\" - the peer requested we not relay transactions to it (relaytxes is false)\n"
613631
" blk Time since last novel block passing initial validity checks received from the peer, in minutes\n"
614632
" hb High-bandwidth BIP152 compact block relay\n"
615633
" \".\" (to) - we selected the peer as a high-bandwidth peer\n"
616634
" \"*\" (from) - the peer selected us as a high-bandwidth peer\n"
635+
" addrp Total number of addresses processed, excluding those dropped due to rate limiting\n"
636+
" \".\" - we do not relay addresses to this peer (addr_relay_enabled is false)\n"
637+
" addrl Total number of addresses dropped due to rate limiting\n"
617638
" age Duration of connection to the peer, in minutes\n"
618639
" asmap Mapped AS (Autonomous System) number in the BGP route to the peer, used for diversifying\n"
619640
" peer selection (only displayed if the -asmap config option is set)\n"

0 commit comments

Comments
 (0)