Skip to content

Commit 44037a2

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25176: Fix frequent -netinfo JSON errors from missing getpeerinfo#relaytxes
a17c5e9 Rename NetinfoRequestHandler::is_block_relay data member to is_tx_relay (Jon Atack) f0bb7db Fix frequent -netinfo JSON errors from null getpeerinfo#relaytxes (Jon Atack) Pull request description: CLI -netinfo frequently returns "error: JSON value is not a boolean as expected" since the merge of #21160, which moved fRelayTxes (renamed to m_relay_txs in that pull) from CNodeStats to CNodeStateStats. This change made getpeerinfo "relaytxes" an optional field that can return UniValue IsNull(). It is the only optional field consumed by -netinfo where the latter didn't already handle that case. See also bitcoin/bitcoin#24691. Also rename the NetinfoRequestHandler::is_block_relay data member to is_tx_relay and inverse its boolean logic. The naming is out of date and incorrect, as lack of request of tx relay does not imply block relay, and a preference for tx relay doesn't imply that block relay isn't happening. Thanks to Marco Falke and Martin Zumsande for their feedback on this. (I may look at reducing the number of optional node stats fields via refactoring at the net processing level, but ongoing refactoring there may make that slow or complicated and this is a one-line fix that works now.) ACKs for top commit: mzumsande: Code review ACK a17c5e9 Tree-SHA512: dc54ce80b78122874a6794555f99e5b328a1574b52bb3e7f974c699c2b759a60ea0807a6483c5bc0414a950d853c0eeeb13dcc1b790d3917c6ee4c9c99fe159f
2 parents fbb90c4 + a17c5e9 commit 44037a2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/bitcoin-cli.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
412412
bool is_addr_relay_enabled;
413413
bool is_bip152_hb_from;
414414
bool is_bip152_hb_to;
415-
bool is_block_relay;
416415
bool is_outbound;
416+
bool is_tx_relay;
417417
bool operator<(const Peer& rhs) const { return std::tie(is_outbound, min_ping) < std::tie(rhs.is_outbound, rhs.min_ping); }
418418
};
419419
std::vector<Peer> m_peers;
@@ -477,7 +477,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
477477
const int8_t network_id{NetworkStringToId(network)};
478478
if (network_id == UNKNOWN_NETWORK) continue;
479479
const bool is_outbound{!peer["inbound"].get_bool()};
480-
const bool is_block_relay{!peer["relaytxes"].get_bool()};
480+
const bool is_tx_relay{peer["relaytxes"].isNull() ? true : peer["relaytxes"].get_bool()};
481481
const std::string conn_type{peer["connection_type"].get_str()};
482482
++m_counts.at(is_outbound).at(network_id); // in/out by network
483483
++m_counts.at(is_outbound).at(NETWORKS.size()); // in/out overall
@@ -505,7 +505,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
505505
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
506506
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
507507
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
508-
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});
508+
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_outbound, is_tx_relay});
509509
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
510510
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
511511
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
@@ -538,7 +538,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
538538
PingTimeToString(peer.ping),
539539
peer.last_send ? ToString(time_now - peer.last_send) : "",
540540
peer.last_recv ? ToString(time_now - peer.last_recv) : "",
541-
peer.last_trxn ? ToString((time_now - peer.last_trxn) / 60) : peer.is_block_relay ? "*" : "",
541+
peer.last_trxn ? ToString((time_now - peer.last_trxn) / 60) : peer.is_tx_relay ? "" : "*",
542542
peer.last_blck ? ToString((time_now - peer.last_blck) / 60) : "",
543543
strprintf("%s%s", peer.is_bip152_hb_to ? "." : " ", peer.is_bip152_hb_from ? "*" : " "),
544544
m_max_addr_processed_length, // variable spacing

0 commit comments

Comments
 (0)