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: cf0f2aeae0
This commit is contained in:
Martin Zumsande
2026-07-21 18:32:19 +02:00
committed by fanquake
parent 0ae49ea16a
commit 43f0653abc
2 changed files with 10 additions and 2 deletions

View File

@@ -211,7 +211,7 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
while (!s.eof()) {
CService endpoint;
s >> endpoint;
CAddress addr{endpoint, SeedsServiceFlags()};
CAddress addr{endpoint, SeedsAssumedServiceFlags()};
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - one_week, -one_week);
LogDebug(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToStringAddrPort());
vSeedsOut.push_back(addr);
@@ -2363,7 +2363,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<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
vAdd.push_back(addr);
found++;

View File

@@ -353,6 +353,14 @@ std::vector<std::string> 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.