Skip to content

Commit 6e89de5

Browse files
committed
Merge #11512: Use GetDesireableServiceFlags in seeds, dnsseeds, fixing static seed adding
2b839ab Update chainparams comment for more info on service bits per dnsseed (Matt Corallo) 62e7642 Fall back to oneshot for DNS Seeds which don't support filtering. (Matt Corallo) 51ae766 Use GetDesireableServiceFlags in static seeds, document this. (Matt Corallo) fb6f6b1 bluematt's testnet-seed now supports x9 (and is just a static list) (Matt Corallo) Pull request description: 4440710 broke inserting entries into addrman from dnsseeds which did not support service bits, as well as static seeds. Static seeds were already being filtered by UA for 0.13.1+ (ie NODE_WITNESS), so simply changing the default service bits to include NODE_WITNESS (and updating docs appropriately) is sufficient. For DNS Seeds, not supporting NODE_WITNESS is no longer useful, so instead use non-filtering seeds as oneshot hosts irrespective of named proxy. I've set my testnet-seed to also support x9, though because it is simply a static host, it may be useful to leave the support off so that it is used as a oneshot to get addresses from a live node instead. I'm fine with either. Tree-SHA512: 3f17d4d2b0b84d876981c962d2b44cb0c8f95f52c56a48c6b35fd882f6d7a40805f320ec452985a1c0b34aebddb1922709156c3ceccd1b9f8363fd7cb537d21d
2 parents 8470e64 + 2b839ab commit 6e89de5

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

contrib/seeds/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Utility to generate the seeds.txt list that is compiled into the client
44
(see [src/chainparamsseeds.h](/src/chainparamsseeds.h) and other utilities in [contrib/seeds](/contrib/seeds)).
55

66
Be sure to update `PATTERN_AGENT` in `makeseeds.py` to include the current version,
7-
and remove old versions as necessary.
7+
and remove old versions as necessary (at a minimum when GetDesireableServiceFlags
8+
changes its default return value, as those are the services which seeds are added
9+
to addrman with).
810

911
The seeds compiled into the release are created from sipa's DNS seed data, like this:
1012

src/chainparams.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ class CMainParams : public CChainParams {
124124
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
125125
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
126126

127-
// 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
127+
// Note that of those which support the service bits prefix, most only support a subset of
128+
// possible options.
129+
// This is fine at runtime as we'll fall back to using them as a oneshot if they dont support the
130+
// service bits we want, but we should get them updated to support all service bits wanted by any
131+
// release ASAP to avoid it where possible.
132+
vSeeds.emplace_back("seed.bitcoin.sipa.be"); // Pieter Wuille, only supports x1, x5, x9, and xd
133+
vSeeds.emplace_back("dnsseed.bluematt.me"); // Matt Corallo, only supports x9
134+
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
135+
vSeeds.emplace_back("seed.bitcoinstats.com"); // Christian Decker, supports x1 - xf
136+
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch"); // Jonas Schnelli, only supports x1, x5, x9, and xd
137+
vSeeds.emplace_back("seed.btc.petertodd.org"); // Peter Todd, only supports x1, x5, x9, and xd
134138

135139
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
136140
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
@@ -229,10 +233,10 @@ class CTestNetParams : public CChainParams {
229233
vFixedSeeds.clear();
230234
vSeeds.clear();
231235
// 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", false);
236+
vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch");
237+
vSeeds.emplace_back("seed.tbtc.petertodd.org");
238+
vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl");
239+
vSeeds.emplace_back("testnet-seed.bluematt.me"); // Just a static list of stable node(s), only supports x9
236240

237241
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
238242
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: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn
136136
for (const auto& seed_in : vSeedsIn) {
137137
struct in6_addr ip;
138138
memcpy(&ip, seed_in.addr, sizeof(ip));
139-
CAddress addr(CService(ip, seed_in.port), NODE_NETWORK);
139+
CAddress addr(CService(ip, seed_in.port), GetDesirableServiceFlags(NODE_NONE));
140140
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
141141
vSeedsOut.push_back(addr);
142142
}
@@ -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
}

src/protocol.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ enum ServiceFlags : uint64_t {
291291
* unless they set NODE_NETWORK_LIMITED and we are out of IBD, in which
292292
* case NODE_NETWORK_LIMITED suffices).
293293
*
294-
* Thus, generally, avoid calling with peerServices == NODE_NONE.
294+
* Thus, generally, avoid calling with peerServices == NODE_NONE, unless
295+
* state-specific flags must absolutely be avoided. When called with
296+
* peerServices == NODE_NONE, the returned desirable service flags are
297+
* guaranteed to not change dependant on state - ie they are suitable for
298+
* use when describing peers which we know to be desirable, but for which
299+
* we do not have a confirmed set of service flags.
300+
*
301+
* If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py
302+
* should be updated appropriately to filter for the same nodes.
295303
*/
296304
static ServiceFlags GetDesirableServiceFlags(ServiceFlags services) {
297305
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);

0 commit comments

Comments
 (0)