Skip to content

Commit 62e7642

Browse files
committed
Fall back to oneshot for DNS Seeds which don't support filtering.
This allows us to not have to update the chainparams whenever a DNS Seed changes its filtering support, as well fixes a bug introduced in 4440710 where returned nodes will never be attempted.
1 parent 51ae766 commit 62e7642

File tree

3 files changed

+21
-35
lines changed

3 files changed

+21
-35
lines changed

src/chainparams.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ class CMainParams : public CChainParams {
125125
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
126126

127127
// Note that of those with the service bits flag, most only support a subset of possible options
128-
vSeeds.emplace_back("seed.bitcoin.sipa.be", true); // Pieter Wuille, only supports x1, x5, x9, and xd
129-
vSeeds.emplace_back("dnsseed.bluematt.me", true); // Matt Corallo, only supports x9
130-
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org", false); // Luke Dashjr
131-
vSeeds.emplace_back("seed.bitcoinstats.com", true); // Christian Decker, supports x1 - xf
132-
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch", true); // Jonas Schnelli, only supports x1, x5, x9, and xd
133-
vSeeds.emplace_back("seed.btc.petertodd.org", true); // Peter Todd, only supports x1, x5, x9, and xd
128+
vSeeds.emplace_back("seed.bitcoin.sipa.be"); // Pieter Wuille, only supports x1, x5, x9, and xd
129+
vSeeds.emplace_back("dnsseed.bluematt.me"); // Matt Corallo, only supports x9
130+
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
131+
vSeeds.emplace_back("seed.bitcoinstats.com"); // Christian Decker, supports x1 - xf
132+
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch"); // Jonas Schnelli, only supports x1, x5, x9, and xd
133+
vSeeds.emplace_back("seed.btc.petertodd.org"); // Peter Todd, only supports x1, x5, x9, and xd
134134

135135
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
136136
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
@@ -229,10 +229,10 @@ class CTestNetParams : public CChainParams {
229229
vFixedSeeds.clear();
230230
vSeeds.clear();
231231
// nodes with support for servicebits filtering should be at the top
232-
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch", true);
233-
vSeeds.emplace_back("seed.tbtc.petertodd.org", true);
234-
vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl", true);
235-
vSeeds.emplace_back("testnet-seed.bluematt.me", true); // Just a static list of stable node(s), only supports x9
232+
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch");
233+
vSeeds.emplace_back("seed.tbtc.petertodd.org");
234+
vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl");
235+
vSeeds.emplace_back("testnet-seed.bluematt.me"); // Just a static list of stable node(s), only supports x9
236236

237237
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
238238
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);

src/chainparams.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
#include <memory>
1515
#include <vector>
1616

17-
struct CDNSSeedData {
18-
std::string host;
19-
bool supportsServiceBitsFiltering;
20-
CDNSSeedData(const std::string &strHost, bool supportsServiceBitsFilteringIn) : host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
21-
};
22-
2317
struct SeedSpec6 {
2418
uint8_t addr[16];
2519
uint16_t port;
@@ -71,7 +65,8 @@ class CChainParams
7165
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
7266
/** Return the BIP70 network string (main, test or regtest) */
7367
std::string NetworkIDString() const { return strNetworkID; }
74-
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
68+
/** Return the list of hostnames to look up for DNS seeds */
69+
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
7570
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
7671
const std::string& Bech32HRP() const { return bech32_hrp; }
7772
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
@@ -85,7 +80,7 @@ class CChainParams
8580
CMessageHeader::MessageStartChars pchMessageStart;
8681
int nDefaultPort;
8782
uint64_t nPruneAfterHeight;
88-
std::vector<CDNSSeedData> vSeeds;
83+
std::vector<std::string> vSeeds;
8984
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
9085
std::string bech32_hrp;
9186
std::string strNetworkID;

src/net.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,19 +1577,6 @@ void MapPort(bool)
15771577

15781578

15791579

1580-
static std::string GetDNSHost(const CDNSSeedData& data, ServiceFlags* requiredServiceBits)
1581-
{
1582-
//use default host for non-filter-capable seeds or if we use the default service bits (NODE_NETWORK)
1583-
if (!data.supportsServiceBitsFiltering || *requiredServiceBits == NODE_NETWORK) {
1584-
*requiredServiceBits = NODE_NETWORK;
1585-
return data.host;
1586-
}
1587-
1588-
// See chainparams.cpp, most dnsseeds only support one or two possible servicebits hostnames
1589-
return strprintf("x%x.%s", *requiredServiceBits, data.host);
1590-
}
1591-
1592-
15931580
void CConnman::ThreadDNSAddressSeed()
15941581
{
15951582
// goal: only query DNS seeds if address need is acute
@@ -1612,22 +1599,22 @@ void CConnman::ThreadDNSAddressSeed()
16121599
}
16131600
}
16141601

1615-
const std::vector<CDNSSeedData> &vSeeds = Params().DNSSeeds();
1602+
const std::vector<std::string> &vSeeds = Params().DNSSeeds();
16161603
int found = 0;
16171604

16181605
LogPrintf("Loading addresses from DNS seeds (could take a while)\n");
16191606

1620-
for (const CDNSSeedData &seed : vSeeds) {
1607+
for (const std::string &seed : vSeeds) {
16211608
if (interruptNet) {
16221609
return;
16231610
}
16241611
if (HaveNameProxy()) {
1625-
AddOneShot(seed.host);
1612+
AddOneShot(seed);
16261613
} else {
16271614
std::vector<CNetAddr> vIPs;
16281615
std::vector<CAddress> vAdd;
16291616
ServiceFlags requiredServiceBits = GetDesirableServiceFlags(NODE_NONE);
1630-
std::string host = GetDNSHost(seed, &requiredServiceBits);
1617+
std::string host = strprintf("x%x.%s", requiredServiceBits, seed);
16311618
CNetAddr resolveSource;
16321619
if (!resolveSource.SetInternal(host)) {
16331620
continue;
@@ -1643,6 +1630,10 @@ void CConnman::ThreadDNSAddressSeed()
16431630
found++;
16441631
}
16451632
addrman.Add(vAdd, resolveSource);
1633+
} else {
1634+
// We now avoid directly using results from DNS Seeds which do not support service bit filtering,
1635+
// instead using them as a oneshot to get nodes with our desired service bits.
1636+
AddOneShot(seed);
16461637
}
16471638
}
16481639
}

0 commit comments

Comments
 (0)