mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
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:
committed by
fanquake
parent
3a43bb54f5
commit
28234bd827
@@ -204,7 +204,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);
|
||||
@@ -2365,7 +2365,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++;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user