Skip to content

Commit 063a8b8

Browse files
committed
Merge bitcoin/bitcoin#29058: net, cli: use v2transport for manual/addrfetch connections, add to -netinfo
fb5bfed cli: add transport protcol column to -netinfo (Martin Zumsande) 9eed22e net: attempt v2 transport for addrfetch connections if we support it (Martin Zumsande) 770c031 net: attempt v2 transport for manual connections if we support it (Martin Zumsande) Pull request description: Some preparations before enabling `-v2transport` as the default: * Use v2 for `-connect`, `-addnode` config arg and `-seednode` if `-v2transport` is enabled. Our peer may or may not support v2, but I don't think an extra option is necessary for any of these (we have that for the `addnode` rpc), because we have the reconnection mechanism that will try again with `v1` if our peer doesn't support `v2`. * Add a column for the transport protocol to `-netinfo`. I added it next to the `net` column because I thought it looked nice there, but if people prefer it somewhere else I'm happy to move it. ![Screenshot from 2023-12-11 17-51-22](https://github.com/bitcoin/bitcoin/assets/48763452/b4f5dfcb-16be-4d8f-9303-9d342123deec) ACKs for top commit: sipa: utACK fb5bfed achow101: ACK fb5bfed stratospher: tested ACK fb5bfed. addrfetch + manual connections aren't frequent and it would be useful to have this for transition to v2 one day. theStack: ACK fb5bfed kristapsk: ACK fb5bfed Tree-SHA512: c4575ad11b99613870b342acae369fa08f877ac79e6e04eb62e94ad7a92d528e289183c0963c78aa779ba11cb91e2a6fad7c8b0d813126c46c3e5b54bd962c26
2 parents 5a121bc + fb5bfed commit 063a8b8

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
406406
std::string conn_type;
407407
std::string network;
408408
std::string age;
409+
std::string transport_protocol_type;
409410
double min_ping;
410411
double ping;
411412
int64_t addr_processed;
@@ -517,10 +518,11 @@ class NetinfoRequestHandler : public BaseRequestHandler
517518
const std::string addr{peer["addr"].get_str()};
518519
const std::string age{conn_time == 0 ? "" : ToString((time_now - conn_time) / 60)};
519520
const std::string sub_version{peer["subver"].get_str()};
521+
const std::string transport{peer["transport_protocol_type"].get_str()};
520522
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
521523
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
522524
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
523-
m_peers.push_back({addr, sub_version, conn_type, NETWORK_SHORT_NAMES[network_id], 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});
525+
m_peers.push_back({addr, sub_version, conn_type, NETWORK_SHORT_NAMES[network_id], age, transport, 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});
524526
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
525527
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
526528
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
@@ -536,7 +538,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
536538
// Report detailed peer connections list sorted by direction and minimum ping time.
537539
if (DetailsRequested() && !m_peers.empty()) {
538540
std::sort(m_peers.begin(), m_peers.end());
539-
result += strprintf("<-> type net mping ping send recv txn blk hb %*s%*s%*s ",
541+
result += strprintf("<-> type net tp mping ping send recv txn blk hb %*s%*s%*s ",
540542
m_max_addr_processed_length, "addrp",
541543
m_max_addr_rate_limited_length, "addrl",
542544
m_max_age_length, "age");
@@ -545,10 +547,11 @@ class NetinfoRequestHandler : public BaseRequestHandler
545547
for (const Peer& peer : m_peers) {
546548
std::string version{ToString(peer.version) + peer.sub_version};
547549
result += strprintf(
548-
"%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n",
550+
"%3s %6s %5s %2s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n",
549551
peer.is_outbound ? "out" : "in",
550552
ConnectionTypeForNetinfo(peer.conn_type),
551553
peer.network,
554+
peer.transport_protocol_type == "detecting" ? "*" : peer.transport_protocol_type,
552555
PingTimeToString(peer.min_ping),
553556
PingTimeToString(peer.ping),
554557
peer.last_send ? ToString(time_now - peer.last_send) : "",
@@ -570,7 +573,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
570573
IsAddressSelected() ? peer.addr : "",
571574
IsVersionSelected() && version != "0" ? version : "");
572575
}
573-
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
576+
result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
574577
}
575578

576579
// Report peer connection totals by type.
@@ -658,6 +661,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
658661
" \"feeler\" - short-lived connection for testing addresses\n"
659662
" \"addr\" - address fetch; short-lived connection for requesting addresses\n"
660663
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", \"cjdns\", or \"npr\" (not publicly routable))\n"
664+
" tp Transport protocol used for the connection (\"v1\", \"v2\" or \"*\" if detecting)\n"
661665
" mping Minimum observed ping time, in milliseconds (ms)\n"
662666
" ping Last observed ping time, in milliseconds (ms)\n"
663667
" send Time since last message sent to the peer, in seconds\n"

src/net.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,10 +2316,13 @@ void CConnman::ProcessAddrFetch()
23162316
strDest = m_addr_fetches.front();
23172317
m_addr_fetches.pop_front();
23182318
}
2319+
// Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
2320+
// peer doesn't support it or immediately disconnects us for another reason.
2321+
const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
23192322
CAddress addr;
23202323
CSemaphoreGrant grant(*semOutbound, /*fTry=*/true);
23212324
if (grant) {
2322-
OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, /*use_v2transport=*/false);
2325+
OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport);
23232326
}
23242327
}
23252328

@@ -2417,12 +2420,15 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
24172420
// Connect to specific addresses
24182421
if (!connect.empty())
24192422
{
2423+
// Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
2424+
// peer doesn't support it or immediately disconnects us for another reason.
2425+
const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
24202426
for (int64_t nLoop = 0;; nLoop++)
24212427
{
24222428
for (const std::string& strAddr : connect)
24232429
{
24242430
CAddress addr(CService(), NODE_NONE);
2425-
OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/false);
2431+
OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport);
24262432
for (int i = 0; i < 10 && i < nLoop; i++)
24272433
{
24282434
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
@@ -2431,6 +2437,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
24312437
}
24322438
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
24332439
return;
2440+
PerformReconnections();
24342441
}
24352442
}
24362443

@@ -2840,11 +2847,11 @@ void CConnman::ThreadOpenAddedConnections()
28402847
if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
28412848
grant = CSemaphoreGrant(*semAddnode, /*fTry=*/true);
28422849
}
2850+
// See if any reconnections are desired.
2851+
PerformReconnections();
28432852
// Retry every 60 seconds if a connection was attempted, otherwise two seconds
28442853
if (!interruptNet.sleep_for(std::chrono::seconds(tried ? 60 : 2)))
28452854
return;
2846-
// See if any reconnections are desired.
2847-
PerformReconnections();
28482855
}
28492856
}
28502857

src/net.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,11 @@ class CConnman
10841084
vWhitelistedRange = connOptions.vWhitelistedRange;
10851085
{
10861086
LOCK(m_added_nodes_mutex);
1087-
1087+
// Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
1088+
// peer doesn't support it or immediately disconnects us for another reason.
1089+
const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
10881090
for (const std::string& added_node : connOptions.m_added_nodes) {
1089-
// -addnode cli arg does not currently have a way to signal BIP324 support
1090-
m_added_node_params.push_back({added_node, false});
1091+
m_added_node_params.push_back({added_node, use_v2transport});
10911092
}
10921093
}
10931094
m_onion_binds = connOptions.onion_binds;

0 commit comments

Comments
 (0)