mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
p2p: improve checkaddrman logging with duration in milliseconds
and update the function name to CheckAddrman (drop "Force") for nicer log output as it is prefixed to each of these log messages: 2021-09-21T18:42:50Z [opencon] CheckAddrman: new 64864, tried 1690, total 66554 started 2021-09-21T18:42:50Z [opencon] CheckAddrman: completed (76.21ms) The existing Doxygen documentation on the function already makes clear that it is unaffected by m_consistency_check_ratio.
This commit is contained in:
parent
ec65bed00e
commit
22b44fc696
@ -7,6 +7,8 @@
|
||||
#include <addrman_impl.h>
|
||||
|
||||
#include <hash.h>
|
||||
#include <logging.h>
|
||||
#include <logging/timer.h>
|
||||
#include <netaddress.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
@ -393,7 +395,7 @@ void AddrManImpl::Unserialize(Stream& s_)
|
||||
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
|
||||
}
|
||||
|
||||
const int check_code{ForceCheckAddrman()};
|
||||
const int check_code{CheckAddrman()};
|
||||
if (check_code != 0) {
|
||||
throw std::ios_base::failure(strprintf(
|
||||
"Corrupt data. Consistency check failed with code %s",
|
||||
@ -923,18 +925,19 @@ void AddrManImpl::Check() const
|
||||
if (m_consistency_check_ratio == 0) return;
|
||||
if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
|
||||
|
||||
const int err{ForceCheckAddrman()};
|
||||
const int err{CheckAddrman()};
|
||||
if (err) {
|
||||
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
int AddrManImpl::ForceCheckAddrman() const
|
||||
int AddrManImpl::CheckAddrman() const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
LogPrint(BCLog::ADDRMAN, "Addrman checks started: new %i, tried %i, total %u\n", nNew, nTried, vRandom.size());
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(
|
||||
strprintf("new %i, tried %i, total %u", nNew, nTried, vRandom.size()), BCLog::ADDRMAN);
|
||||
|
||||
std::unordered_set<int> setTried;
|
||||
std::unordered_map<int, int> mapNew;
|
||||
@ -1014,7 +1017,6 @@ int AddrManImpl::ForceCheckAddrman() const
|
||||
if (nKey.IsNull())
|
||||
return -16;
|
||||
|
||||
LogPrint(BCLog::ADDRMAN, "Addrman checks completed successfully\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define BITCOIN_ADDRMAN_IMPL_H
|
||||
|
||||
#include <logging.h>
|
||||
#include <logging/timer.h>
|
||||
#include <netaddress.h>
|
||||
#include <protocol.h>
|
||||
#include <serialize.h>
|
||||
@ -260,12 +261,13 @@ private:
|
||||
|
||||
std::pair<CAddress, int64_t> SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
//! Consistency check, taking into account m_consistency_check_ratio. Will std::abort if an inconsistency is detected.
|
||||
//! Consistency check, taking into account m_consistency_check_ratio.
|
||||
//! Will std::abort if an inconsistency is detected.
|
||||
void Check() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
//! Perform consistency check, regardless of m_consistency_check_ratio.
|
||||
//! @returns an error code or zero.
|
||||
int ForceCheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
int CheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
};
|
||||
|
||||
#endif // BITCOIN_ADDRMAN_IMPL_H
|
||||
|
@ -89,8 +89,8 @@ class AsmapTest(BitcoinTestFramework):
|
||||
self.restart_node(0, ["-asmap", "-checkaddrman=1"])
|
||||
with self.node.assert_debug_log(
|
||||
expected_msgs=[
|
||||
"Addrman checks started: new 1, tried 1, total 2",
|
||||
"Addrman checks completed successfully",
|
||||
"CheckAddrman: new 1, tried 1, total 2 started",
|
||||
"CheckAddrman: completed",
|
||||
]
|
||||
):
|
||||
self.node.getnodeaddresses() # getnodeaddresses re-runs the addrman checks
|
||||
|
@ -260,7 +260,7 @@ class NetTest(BitcoinTestFramework):
|
||||
|
||||
self.log.debug("Test that adding a valid address to the tried table succeeds")
|
||||
assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True})
|
||||
with node.assert_debug_log(expected_msgs=["Addrman checks started: new 0, tried 1, total 1"]):
|
||||
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 0, tried 1, total 1 started"]):
|
||||
addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks
|
||||
assert_equal(len(addrs), 1)
|
||||
assert_equal(addrs[0]["address"], "1.2.3.4")
|
||||
@ -273,7 +273,7 @@ class NetTest(BitcoinTestFramework):
|
||||
|
||||
self.log.debug("Test that adding a second address, this time to the new table, succeeds")
|
||||
assert_equal(node.addpeeraddress(address="2.0.0.0", port=8333), {"success": True})
|
||||
with node.assert_debug_log(expected_msgs=["Addrman checks started: new 1, tried 1, total 2"]):
|
||||
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 1, tried 1, total 2 started"]):
|
||||
addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks
|
||||
assert_equal(len(addrs), 2)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user