Skip to content

Commit 4da3f9f

Browse files
committed
[REMOVE] make very bad addrman
this queries 9 DNS at once (instead of default) and removes addr limit.
1 parent e5df82f commit 4da3f9f

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ namespace { // Variables internal to initialization process only
822822
int nMaxConnections;
823823
int nUserMaxConnections;
824824
int nFD;
825-
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
825+
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS | NODE_P2P_V2);
826826
int64_t peer_connect_timeout;
827827
std::set<BlockFilterType> g_enabled_filter_types;
828828

src/net.cpp

+9-29
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const char* const ANCHORS_DATABASE_FILENAME = "anchors.dat";
6363
static constexpr std::chrono::minutes DUMP_PEERS_INTERVAL{15};
6464

6565
/** Number of DNS seeds to query when the number of connections is low. */
66-
static constexpr int DNSSEEDS_TO_QUERY_AT_ONCE = 3;
66+
static constexpr int DNSSEEDS_TO_QUERY_AT_ONCE = 9;
6767

6868
/** How long to delay before querying DNS seeds
6969
*
@@ -2181,6 +2181,7 @@ void CConnman::WakeMessageHandler()
21812181

21822182
void CConnman::ThreadDNSAddressSeed()
21832183
{
2184+
LogPrintf("### INSIDE ThreadDNSAddressSeed");
21842185
constexpr int TARGET_OUTBOUND_CONNECTIONS = 2;
21852186
int outbound_connection_count = 0;
21862187

@@ -2222,8 +2223,10 @@ void CConnman::ThreadDNSAddressSeed()
22222223
seeds_right_now = seeds.size();
22232224
}
22242225

2225-
// Proceed with dnsseeds if seednodes hasn't reached the target or if forcednsseed is set
2226-
if (outbound_connection_count < TARGET_OUTBOUND_CONNECTIONS || seeds_right_now) {
2226+
// max value of i is 2**64 - 1 = (1024)**6 * 16 - 1 = 16*(10**18) - 1
2227+
// 3 * 10 ** 17 mins = 5 * 10 ** 15 hours = 2 * 10 ** 14 days = 584,942,417,355 years (if operation took 1 sec, whaat)
2228+
uint64_t i = 0;
2229+
while(true){
22272230
// goal: only query DNS seed if address need is acute
22282231
// * If we have a reasonable number of peers in addrman, spend
22292232
// some time trying them first. This improves user privacy by
@@ -2242,29 +2245,6 @@ void CConnman::ThreadDNSAddressSeed()
22422245
for (const std::string& seed : seeds) {
22432246
if (seeds_right_now == 0) {
22442247
seeds_right_now += DNSSEEDS_TO_QUERY_AT_ONCE;
2245-
2246-
if (addrman.Size() > 0) {
2247-
LogPrintf("Waiting %d seconds before querying DNS seeds.\n", seeds_wait_time.count());
2248-
std::chrono::seconds to_wait = seeds_wait_time;
2249-
while (to_wait.count() > 0) {
2250-
// if sleeping for the MANY_PEERS interval, wake up
2251-
// early to see if we have enough peers and can stop
2252-
// this thread entirely freeing up its resources
2253-
std::chrono::seconds w = std::min(DNSSEEDS_DELAY_FEW_PEERS, to_wait);
2254-
if (!interruptNet.sleep_for(w)) return;
2255-
to_wait -= w;
2256-
2257-
if (GetFullOutboundConnCount() >= TARGET_OUTBOUND_CONNECTIONS) {
2258-
if (found > 0) {
2259-
LogPrintf("%d addresses found from DNS seeds\n", found);
2260-
LogPrintf("P2P peers available. Finished DNS seeding.\n");
2261-
} else {
2262-
LogPrintf("P2P peers available. Skipped DNS seeding.\n");
2263-
}
2264-
return;
2265-
}
2266-
}
2267-
}
22682248
}
22692249

22702250
if (interruptNet) return;
@@ -2294,7 +2274,7 @@ void CConnman::ThreadDNSAddressSeed()
22942274
// one DNS seed from dominating AddrMan. Note that the number of results from a UDP DNS query is
22952275
// bounded to 33 already, but it is possible for it to use TCP where a larger number of results can be
22962276
// returned.
2297-
unsigned int nMaxIPs = 32;
2277+
unsigned int nMaxIPs = 3200;
22982278
const auto addresses{LookupHost(host, nMaxIPs, true)};
22992279
if (!addresses.empty()) {
23002280
for (const CNetAddr& ip : addresses) {
@@ -2304,6 +2284,8 @@ void CConnman::ThreadDNSAddressSeed()
23042284
found++;
23052285
}
23062286
addrman.Add(vAdd, resolveSource);
2287+
LogPrintf("### %llu: added %d addresses from DNS into addrman\n", i, vAdd.size());
2288+
i++;
23072289
} else {
23082290
// If the seed does not support a subdomain with our desired service bits,
23092291
// we make an ADDR_FETCH connection to the DNS resolved peer address for the
@@ -2314,8 +2296,6 @@ void CConnman::ThreadDNSAddressSeed()
23142296
--seeds_right_now;
23152297
}
23162298
LogPrintf("%d addresses found from DNS seeds\n", found);
2317-
} else {
2318-
LogPrintf("Skipping DNS seeds. Enough peers have been found\n");
23192299
}
23202300
}
23212301

src/net_processing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1795,10 +1795,10 @@ ServiceFlags PeerManagerImpl::GetDesirableServiceFlags(ServiceFlags services) co
17951795
if (services & NODE_NETWORK_LIMITED) {
17961796
// Limited peers are desirable when we are close to the tip.
17971797
if (ApproximateBestBlockDepth() < NODE_NETWORK_LIMITED_ALLOW_CONN_BLOCKS) {
1798-
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
1798+
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS | NODE_P2P_V2);
17991799
}
18001800
}
1801-
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
1801+
return ServiceFlags(NODE_NETWORK | NODE_WITNESS | NODE_P2P_V2);
18021802
}
18031803

18041804
PeerRef PeerManagerImpl::GetPeerRef(NodeId id) const

src/protocol.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ std::vector<std::string> serviceFlagsToStr(uint64_t flags);
316316
* should be updated appropriately to filter for nodes with
317317
* desired service flags (compatible with our new flags).
318318
*/
319-
constexpr ServiceFlags SeedsServiceFlags() { return ServiceFlags(NODE_NETWORK | NODE_WITNESS); }
319+
constexpr ServiceFlags SeedsServiceFlags() { return ServiceFlags(NODE_NETWORK | NODE_WITNESS | NODE_P2P_V2); }
320320

321321
/**
322322
* Checks if a peer with the given service flags may be capable of having a

0 commit comments

Comments
 (0)