aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-01-09 12:11:47 -0500
committerAva Chow <github@achow101.com>2024-01-09 12:46:52 -0500
commit063a8b83875997068b3eb506b5f30f2691d18052 (patch)
tree9757d0ca1d2d0cd2142183ee0c06da3667f9980e
parent5a121bcdeed2904d94c9489d352d39d22d52fc7c (diff)
parentfb5bfed26a564014b83ccfc96ff00b630930fc61 (diff)
Merge bitcoin/bitcoin#29058: net, cli: use v2transport for manual/addrfetch connections, add to -netinfo
fb5bfed26a564014b83ccfc96ff00b630930fc61 cli: add transport protcol column to -netinfo (Martin Zumsande) 9eed22e870e650cadf5f65650917da21836d2bb0 net: attempt v2 transport for addrfetch connections if we support it (Martin Zumsande) 770c0311ef5e35444efe4fd26f7bb5782624cf2c 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 fb5bfed26a564014b83ccfc96ff00b630930fc61 achow101: ACK fb5bfed26a564014b83ccfc96ff00b630930fc61 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 fb5bfed26a564014b83ccfc96ff00b630930fc61 kristapsk: ACK fb5bfed26a564014b83ccfc96ff00b630930fc61 Tree-SHA512: c4575ad11b99613870b342acae369fa08f877ac79e6e04eb62e94ad7a92d528e289183c0963c78aa779ba11cb91e2a6fad7c8b0d813126c46c3e5b54bd962c26
-rw-r--r--src/bitcoin-cli.cpp12
-rw-r--r--src/net.cpp15
-rw-r--r--src/net.h7
3 files changed, 23 insertions, 11 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 45db7a9a66..03af80de75 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -406,6 +406,7 @@ private:
std::string conn_type;
std::string network;
std::string age;
+ std::string transport_protocol_type;
double min_ping;
double ping;
int64_t addr_processed;
@@ -517,10 +518,11 @@ public:
const std::string addr{peer["addr"].get_str()};
const std::string age{conn_time == 0 ? "" : ToString((time_now - conn_time) / 60)};
const std::string sub_version{peer["subver"].get_str()};
+ const std::string transport{peer["transport_protocol_type"].get_str()};
const bool is_addr_relay_enabled{peer["addr_relay_enabled"].isNull() ? false : peer["addr_relay_enabled"].get_bool()};
const bool is_bip152_hb_from{peer["bip152_hb_from"].get_bool()};
const bool is_bip152_hb_to{peer["bip152_hb_to"].get_bool()};
- 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});
+ 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});
m_max_addr_length = std::max(addr.length() + 1, m_max_addr_length);
m_max_addr_processed_length = std::max(ToString(addr_processed).length(), m_max_addr_processed_length);
m_max_addr_rate_limited_length = std::max(ToString(addr_rate_limited).length(), m_max_addr_rate_limited_length);
@@ -536,7 +538,7 @@ public:
// Report detailed peer connections list sorted by direction and minimum ping time.
if (DetailsRequested() && !m_peers.empty()) {
std::sort(m_peers.begin(), m_peers.end());
- result += strprintf("<-> type net mping ping send recv txn blk hb %*s%*s%*s ",
+ result += strprintf("<-> type net tp mping ping send recv txn blk hb %*s%*s%*s ",
m_max_addr_processed_length, "addrp",
m_max_addr_rate_limited_length, "addrl",
m_max_age_length, "age");
@@ -545,10 +547,11 @@ public:
for (const Peer& peer : m_peers) {
std::string version{ToString(peer.version) + peer.sub_version};
result += strprintf(
- "%3s %6s %5s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n",
+ "%3s %6s %5s %2s%7s%7s%5s%5s%5s%5s %2s %*s%*s%*s%*i %*s %-*s%s\n",
peer.is_outbound ? "out" : "in",
ConnectionTypeForNetinfo(peer.conn_type),
peer.network,
+ peer.transport_protocol_type == "detecting" ? "*" : peer.transport_protocol_type,
PingTimeToString(peer.min_ping),
PingTimeToString(peer.ping),
peer.last_send ? ToString(time_now - peer.last_send) : "",
@@ -570,7 +573,7 @@ public:
IsAddressSelected() ? peer.addr : "",
IsVersionSelected() && version != "0" ? version : "");
}
- result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
+ result += strprintf(" ms ms sec sec min min %*s\n\n", m_max_age_length, "min");
}
// Report peer connection totals by type.
@@ -658,6 +661,7 @@ public:
" \"feeler\" - short-lived connection for testing addresses\n"
" \"addr\" - address fetch; short-lived connection for requesting addresses\n"
" net Network the peer connected through (\"ipv4\", \"ipv6\", \"onion\", \"i2p\", \"cjdns\", or \"npr\" (not publicly routable))\n"
+ " tp Transport protocol used for the connection (\"v1\", \"v2\" or \"*\" if detecting)\n"
" mping Minimum observed ping time, in milliseconds (ms)\n"
" ping Last observed ping time, in milliseconds (ms)\n"
" send Time since last message sent to the peer, in seconds\n"
diff --git a/src/net.cpp b/src/net.cpp
index 41f5323d91..0cc794c2c3 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2316,10 +2316,13 @@ void CConnman::ProcessAddrFetch()
strDest = m_addr_fetches.front();
m_addr_fetches.pop_front();
}
+ // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
+ // peer doesn't support it or immediately disconnects us for another reason.
+ const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
CAddress addr;
CSemaphoreGrant grant(*semOutbound, /*fTry=*/true);
if (grant) {
- OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, /*use_v2transport=*/false);
+ OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport);
}
}
@@ -2417,12 +2420,15 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
// Connect to specific addresses
if (!connect.empty())
{
+ // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
+ // peer doesn't support it or immediately disconnects us for another reason.
+ const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
for (int64_t nLoop = 0;; nLoop++)
{
for (const std::string& strAddr : connect)
{
CAddress addr(CService(), NODE_NONE);
- OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/false);
+ OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport);
for (int i = 0; i < 10 && i < nLoop; i++)
{
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
@@ -2431,6 +2437,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
}
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
return;
+ PerformReconnections();
}
}
@@ -2840,11 +2847,11 @@ void CConnman::ThreadOpenAddedConnections()
if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return;
grant = CSemaphoreGrant(*semAddnode, /*fTry=*/true);
}
+ // See if any reconnections are desired.
+ PerformReconnections();
// Retry every 60 seconds if a connection was attempted, otherwise two seconds
if (!interruptNet.sleep_for(std::chrono::seconds(tried ? 60 : 2)))
return;
- // See if any reconnections are desired.
- PerformReconnections();
}
}
diff --git a/src/net.h b/src/net.h
index 547e032ba6..6b9386e511 100644
--- a/src/net.h
+++ b/src/net.h
@@ -1084,10 +1084,11 @@ public:
vWhitelistedRange = connOptions.vWhitelistedRange;
{
LOCK(m_added_nodes_mutex);
-
+ // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
+ // peer doesn't support it or immediately disconnects us for another reason.
+ const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
for (const std::string& added_node : connOptions.m_added_nodes) {
- // -addnode cli arg does not currently have a way to signal BIP324 support
- m_added_node_params.push_back({added_node, false});
+ m_added_node_params.push_back({added_node, use_v2transport});
}
}
m_onion_binds = connOptions.onion_binds;