From c02ff3e793d6e781c6060d9d981bf71ae42fc17e Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Tue, 21 Jul 2026 18:32:19 +0200 Subject: [PATCH] p2p: Assume v2transport for addresses from seeds By now, the vast majority of nodes in the network supports BIP324. Even if the optimistic guess would turn out to be wrong for a given node, we would just reconnect with v1. This is better than making v1 connections with peers when both nodes support v2. Github-Pull: #35766 Rebased-From: cf0f2aeae009c98615bffd4dafd74e46f20a0ae6 --- src/net.cpp | 4 ++-- src/protocol.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 5c28efade89..0afef682736 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -205,7 +205,7 @@ static std::vector ConvertSeeds(const std::vector &vSeedsIn) while (!s.empty()) { CService endpoint; s >> endpoint; - CAddress addr{endpoint, SeedsServiceFlags()}; + CAddress addr{endpoint, SeedsAssumedServiceFlags()}; addr.nTime = rng.rand_uniform_delay(Now() - one_week, -one_week); LogDebug(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToStringAddrPort()); vSeedsOut.push_back(addr); @@ -2382,7 +2382,7 @@ void CConnman::ThreadDNSAddressSeed() const auto addresses{LookupHost(host, nMaxIPs, true)}; if (!addresses.empty()) { for (const CNetAddr& ip : addresses) { - CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), requiredServiceBits); + CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), SeedsAssumedServiceFlags()); addr.nTime = rng.rand_uniform_delay(Now() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old vAdd.push_back(addr); found++; diff --git a/src/protocol.h b/src/protocol.h index 8ed90dd3f8e..00d046a02c0 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -353,6 +353,14 @@ std::vector serviceFlagsToStr(uint64_t flags); */ constexpr ServiceFlags SeedsServiceFlags() { return ServiceFlags(NODE_NETWORK | NODE_WITNESS); } +/** + * Service flags we assume for addresses obtained from the DNS seeds and the + * fixed seeds, which don't come with service flags attached. + * BIP324 support can be safely assumed because the vast majority of listening nodes signals NODE_P2P_V2, and if the + * assumption is wrong for a given peer we simply reconnect using v1 transport. + */ +constexpr ServiceFlags SeedsAssumedServiceFlags() { return ServiceFlags(SeedsServiceFlags() | NODE_P2P_V2); } + /** * Checks if a peer with the given service flags may be capable of having a * robust address-storage DB.