mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
net: Add continuous ASMap health check logging
This commit is contained in:
parent
28d7e55dff
commit
3ea54e5db7
19
src/net.cpp
19
src/net.cpp
@ -3305,6 +3305,12 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
||||
// Dump network addresses
|
||||
scheduler.scheduleEvery([this] { DumpAddresses(); }, DUMP_PEERS_INTERVAL);
|
||||
|
||||
// Run the ASMap Health check once and then schedule it to run every 24h.
|
||||
if (m_netgroupman.UsingASMap()) {
|
||||
ASMapHealthCheck();
|
||||
scheduler.scheduleEvery([this] { ASMapHealthCheck(); }, ASMAP_HEALTH_CHECK_INTERVAL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3853,6 +3859,19 @@ void CConnman::PerformReconnections()
|
||||
}
|
||||
}
|
||||
|
||||
void CConnman::ASMapHealthCheck()
|
||||
{
|
||||
const std::vector<CAddress> v4_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV4, /*filtered=*/ false)};
|
||||
const std::vector<CAddress> v6_addrs{GetAddresses(/*max_addresses=*/ 0, /*max_pct=*/ 0, Network::NET_IPV6, /*filtered=*/ false)};
|
||||
std::vector<CNetAddr> clearnet_addrs;
|
||||
clearnet_addrs.reserve(v4_addrs.size() + v6_addrs.size());
|
||||
std::transform(v4_addrs.begin(), v4_addrs.end(), std::back_inserter(clearnet_addrs),
|
||||
[](const CAddress& addr) { return static_cast<CNetAddr>(addr); });
|
||||
std::transform(v6_addrs.begin(), v6_addrs.end(), std::back_inserter(clearnet_addrs),
|
||||
[](const CAddress& addr) { return static_cast<CNetAddr>(addr); });
|
||||
m_netgroupman.ASMapHealthCheck(clearnet_addrs);
|
||||
}
|
||||
|
||||
// Dump binary message to file, with timestamp.
|
||||
static void CaptureMessageToFile(const CAddress& addr,
|
||||
const std::string& msg_type,
|
||||
|
@ -87,6 +87,8 @@ static const bool DEFAULT_BLOCKSONLY = false;
|
||||
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
|
||||
/** Number of file descriptors required for message capture **/
|
||||
static const int NUM_FDS_MESSAGE_CAPTURE = 1;
|
||||
/** Interval for ASMap Health Check **/
|
||||
static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24};
|
||||
|
||||
static constexpr bool DEFAULT_FORCEDNSSEED{false};
|
||||
static constexpr bool DEFAULT_DNSSEED{true};
|
||||
@ -1138,6 +1140,7 @@ public:
|
||||
void SetNetworkActive(bool active);
|
||||
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant&& grant_outbound, const char* strDest, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
||||
bool CheckIncomingNonce(uint64_t nonce);
|
||||
void ASMapHealthCheck();
|
||||
|
||||
// alias for thread safety annotations only, not defined
|
||||
RecursiveMutex& GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <netgroup.h>
|
||||
|
||||
#include <hash.h>
|
||||
#include <logging.h>
|
||||
#include <util/asmap.h>
|
||||
|
||||
uint256 NetGroupManager::GetAsmapChecksum() const
|
||||
@ -109,3 +110,23 @@ uint32_t NetGroupManager::GetMappedAS(const CNetAddr& address) const
|
||||
uint32_t mapped_as = Interpret(m_asmap, ip_bits);
|
||||
return mapped_as;
|
||||
}
|
||||
|
||||
void NetGroupManager::ASMapHealthCheck(const std::vector<CNetAddr>& clearnet_addrs) const {
|
||||
std::set<uint32_t> clearnet_asns{};
|
||||
int unmapped_count{0};
|
||||
|
||||
for (const auto& addr : clearnet_addrs) {
|
||||
uint32_t asn = GetMappedAS(addr);
|
||||
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", clearnet_addrs.size(), clearnet_asns.size(), unmapped_count);
|
||||
}
|
||||
|
||||
bool NetGroupManager::UsingASMap() const {
|
||||
return m_asmap.size() > 0;
|
||||
}
|
||||
|
@ -41,6 +41,16 @@ public:
|
||||
*/
|
||||
uint32_t GetMappedAS(const CNetAddr& address) const;
|
||||
|
||||
/**
|
||||
* Analyze and log current health of ASMap based buckets.
|
||||
*/
|
||||
void ASMapHealthCheck(const std::vector<CNetAddr>& clearnet_addrs) const;
|
||||
|
||||
/**
|
||||
* Indicates whether ASMap is being used for clearnet bucketing.
|
||||
*/
|
||||
bool UsingASMap() const;
|
||||
|
||||
private:
|
||||
/** Compressed IP->ASN mapping, loaded from a file when a node starts.
|
||||
*
|
||||
|
@ -111,6 +111,14 @@ class AsmapTest(BitcoinTestFramework):
|
||||
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
|
||||
os.remove(self.default_asmap)
|
||||
|
||||
def test_asmap_health_check(self):
|
||||
self.log.info('Test bitcoind -asmap logs ASMap Health Check with basic stats')
|
||||
shutil.copyfile(self.asmap_raw, self.default_asmap)
|
||||
msg = "ASMap Health Check: 2 clearnet peers are mapped to 1 ASNs with 0 peers being unmapped"
|
||||
with self.node.assert_debug_log(expected_msgs=[msg]):
|
||||
self.start_node(0, extra_args=['-asmap'])
|
||||
os.remove(self.default_asmap)
|
||||
|
||||
def run_test(self):
|
||||
self.node = self.nodes[0]
|
||||
self.datadir = self.node.chain_path
|
||||
@ -124,6 +132,7 @@ class AsmapTest(BitcoinTestFramework):
|
||||
self.test_asmap_interaction_with_addrman_containing_entries()
|
||||
self.test_default_asmap_with_missing_file()
|
||||
self.test_empty_asmap()
|
||||
self.test_asmap_health_check()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user