Skip to content

Commit cf0f2ae

Browse files
committed
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.
1 parent d673ca7 commit cf0f2ae

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/net.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
206206
while (!s.empty()) {
207207
CService endpoint;
208208
s >> endpoint;
209-
CAddress addr{endpoint, SeedsServiceFlags()};
209+
CAddress addr{endpoint, SeedsAssumedServiceFlags()};
210210
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - one_week, -one_week);
211211
LogDebug(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToStringAddrPort());
212212
vSeedsOut.push_back(addr);
@@ -2400,7 +2400,7 @@ void CConnman::ThreadDNSAddressSeed()
24002400
const auto addresses{LookupHost(host, nMaxIPs, true)};
24012401
if (!addresses.empty()) {
24022402
for (const CNetAddr& ip : addresses) {
2403-
CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), requiredServiceBits);
2403+
CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), SeedsAssumedServiceFlags());
24042404
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
24052405
vAdd.push_back(addr);
24062406
found++;

‎src/protocol.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ std::vector<std::string> serviceFlagsToStr(uint64_t flags);
365365
*/
366366
constexpr ServiceFlags SeedsServiceFlags() { return ServiceFlags(NODE_NETWORK | NODE_WITNESS); }
367367

368+
/**
369+
* Service flags we assume for addresses obtained from the DNS seeds and the
370+
* fixed seeds, which don't come with service flags attached.
371+
* BIP324 support can be safely assumed because the vast majority of listening nodes signals NODE_P2P_V2, and if the
372+
* assumption is wrong for a given peer we simply reconnect using v1 transport.
373+
*/
374+
constexpr ServiceFlags SeedsAssumedServiceFlags() { return ServiceFlags(SeedsServiceFlags() | NODE_P2P_V2); }
375+
368376
/**
369377
* Checks if a peer with the given service flags may be capable of having a
370378
* robust address-storage DB.

0 commit comments

Comments
 (0)