From 1009f931f2228ca1f026e689038d24cc9f4d940e Mon Sep 17 00:00:00 2001 From: Duke Date: Sun, 1 Dec 2024 20:05:34 -0500 Subject: [PATCH 1/5] Remove duplicate scheduling of peers.dat --- src/net.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index f6893a54e..c9615a863 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2378,9 +2378,6 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) scheduler.scheduleEvery(&DumpZindexStats, DUMP_ZINDEX_INTERVAL); } - // Dump network addresses - scheduler.scheduleEvery(&DumpAddresses, DUMP_ADDRESSES_INTERVAL); - scheduler.scheduleEvery(&CheckIfWeShouldStop, CHECK_PLZ_STOP_INTERVAL); } From cceb61c371648693d35eb9c7f33ec30dab16b40a Mon Sep 17 00:00:00 2001 From: Duke Date: Mon, 2 Dec 2024 11:11:40 -0500 Subject: [PATCH 2/5] Initial implementation of asmap health check --- src/net.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index c9615a863..a87b41cb6 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -50,6 +50,11 @@ extern int32_t HUSH_TESTNODE; // Satoshi originally used 10 seconds(!), did they know something Peter Wuille didn't? #define DUMP_ADDRESSES_INTERVAL 300 +// Run asmap health check every 24hr by default +#define ASMAP_HEALTHCHECK_INTERVAL 24*60*60 +// Uncomment to Use a 60s interval for debugging +//#define ASMAP_HEALTHCHECK_INTERVAL 60 + // This is every 2 blocks, on avg, on HUSH3 #define DUMP_ZINDEX_INTERVAL 150 @@ -1648,6 +1653,26 @@ int64_t PoissonNextSend(int64_t now, int average_interval_seconds) return now + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5); } +void ASMapHealthCheck() { + std::set clearnet_asns{}; + int unmapped_count{0}; + LOCK(cs_vNodes); + + // TODO: skip onion/i2p nodes as they have no ASN + for (const auto& pnode : vNodes) { + uint32_t asn = pnode->addr.GetMappedAS(addrman.m_asmap); + if (asn == 0) { + ++unmapped_count; + continue; + } + clearnet_asns.insert(asn); + } + + LogPrintf("ASMap Health Check: %i clearnet peers are mapped to %i ASNs with %i peers being unmapped\n", vNodes.size(), clearnet_asns.size(), unmapped_count); +} + + + void ThreadOpenConnections() { // Connect to specific addresses @@ -1753,7 +1778,7 @@ void ThreadOpenConnections() int64_t nNow = GetTime(); int nTries = 0; - LogPrint("net", "Resolving addrman collisions\n"); + LogPrint("net", "Resolving addrman collisions\n"); addrman.ResolveCollisions(); while (true) { @@ -1823,6 +1848,8 @@ void ThreadOpenConnections() OpenNetworkConnection(addrConnect,/*failures,*/ &grant, NULL, false, fFeeler); } } + // Do a health check now that we hopefully have peers + ASMapHealthCheck(); } void ThreadOpenAddedConnections() @@ -2378,7 +2405,11 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) scheduler.scheduleEvery(&DumpZindexStats, DUMP_ZINDEX_INTERVAL); } + // Look for ~/.hush/AC_NAME/plz_stop scheduler.scheduleEvery(&CheckIfWeShouldStop, CHECK_PLZ_STOP_INTERVAL); + + // Schedule ASMap Health check to run regularly + scheduler.scheduleEvery(&ASMapHealthCheck, ASMAP_HEALTHCHECK_INTERVAL); } bool StopNode() From ecf98cbce17cb7202a066f49b7381902183f7353 Mon Sep 17 00:00:00 2001 From: Duke Date: Tue, 3 Dec 2024 11:28:11 -0500 Subject: [PATCH 3/5] Schedule asmap health check to run once 5 mins after node starts --- src/net.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index a87b41cb6..05f66d246 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1848,8 +1848,6 @@ void ThreadOpenConnections() OpenNetworkConnection(addrConnect,/*failures,*/ &grant, NULL, false, fFeeler); } } - // Do a health check now that we hopefully have peers - ASMapHealthCheck(); } void ThreadOpenAddedConnections() @@ -2410,6 +2408,9 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler) // Schedule ASMap Health check to run regularly scheduler.scheduleEvery(&ASMapHealthCheck, ASMAP_HEALTHCHECK_INTERVAL); + + // and schedule it to run once in 5 mins when we hopefully have peers connected + scheduler.scheduleFromNow(&ASMapHealthCheck, 300); } bool StopNode() From 179fc6d6c0c7180bf73d192bdcaf65a4f0c0bab3 Mon Sep 17 00:00:00 2001 From: Duke Date: Tue, 3 Dec 2024 11:53:30 -0500 Subject: [PATCH 4/5] Skip networks which do not have ASNs --- src/net.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 05f66d246..c7f6ab38a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1658,9 +1658,13 @@ void ASMapHealthCheck() { int unmapped_count{0}; LOCK(cs_vNodes); - // TODO: skip onion/i2p nodes as they have no ASN for (const auto& pnode : vNodes) { - uint32_t asn = pnode->addr.GetMappedAS(addrman.m_asmap); + auto address = pnode->addr; + if(address.IsTor() || address.IsI2P() || address.IsCJDNS()) { + // These networks do not have ASNs, skip them + continue; + } + uint32_t asn = address.GetMappedAS(addrman.m_asmap); if (asn == 0) { ++unmapped_count; continue; From 15f889d9f8c558fe231e1dab90bbb64ca9fb7192 Mon Sep 17 00:00:00 2001 From: Duke Date: Tue, 3 Dec 2024 11:55:43 -0500 Subject: [PATCH 5/5] Cleanup --- src/net.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c7f6ab38a..168f2b169 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -52,8 +52,6 @@ extern int32_t HUSH_TESTNODE; // Run asmap health check every 24hr by default #define ASMAP_HEALTHCHECK_INTERVAL 24*60*60 -// Uncomment to Use a 60s interval for debugging -//#define ASMAP_HEALTHCHECK_INTERVAL 60 // This is every 2 blocks, on avg, on HUSH3 #define DUMP_ZINDEX_INTERVAL 150