Skip to content

Commit 22b44fc

Browse files
committed
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.
1 parent ec65bed commit 22b44fc

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/addrman.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <addrman_impl.h>
88

99
#include <hash.h>
10+
#include <logging.h>
11+
#include <logging/timer.h>
1012
#include <netaddress.h>
1113
#include <protocol.h>
1214
#include <random.h>
@@ -393,7 +395,7 @@ void AddrManImpl::Unserialize(Stream& s_)
393395
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
394396
}
395397

396-
const int check_code{ForceCheckAddrman()};
398+
const int check_code{CheckAddrman()};
397399
if (check_code != 0) {
398400
throw std::ios_base::failure(strprintf(
399401
"Corrupt data. Consistency check failed with code %s",
@@ -923,18 +925,19 @@ void AddrManImpl::Check() const
923925
if (m_consistency_check_ratio == 0) return;
924926
if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
925927

926-
const int err{ForceCheckAddrman()};
928+
const int err{CheckAddrman()};
927929
if (err) {
928930
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
929931
assert(false);
930932
}
931933
}
932934

933-
int AddrManImpl::ForceCheckAddrman() const
935+
int AddrManImpl::CheckAddrman() const
934936
{
935937
AssertLockHeld(cs);
936938

937-
LogPrint(BCLog::ADDRMAN, "Addrman checks started: new %i, tried %i, total %u\n", nNew, nTried, vRandom.size());
939+
LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(
940+
strprintf("new %i, tried %i, total %u", nNew, nTried, vRandom.size()), BCLog::ADDRMAN);
938941

939942
std::unordered_set<int> setTried;
940943
std::unordered_map<int, int> mapNew;
@@ -1014,7 +1017,6 @@ int AddrManImpl::ForceCheckAddrman() const
10141017
if (nKey.IsNull())
10151018
return -16;
10161019

1017-
LogPrint(BCLog::ADDRMAN, "Addrman checks completed successfully\n");
10181020
return 0;
10191021
}
10201022

src/addrman_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_ADDRMAN_IMPL_H
77

88
#include <logging.h>
9+
#include <logging/timer.h>
910
#include <netaddress.h>
1011
#include <protocol.h>
1112
#include <serialize.h>
@@ -260,12 +261,13 @@ class AddrManImpl
260261

261262
std::pair<CAddress, int64_t> SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
262263

263-
//! Consistency check, taking into account m_consistency_check_ratio. Will std::abort if an inconsistency is detected.
264+
//! Consistency check, taking into account m_consistency_check_ratio.
265+
//! Will std::abort if an inconsistency is detected.
264266
void Check() const EXCLUSIVE_LOCKS_REQUIRED(cs);
265267

266268
//! Perform consistency check, regardless of m_consistency_check_ratio.
267269
//! @returns an error code or zero.
268-
int ForceCheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs);
270+
int CheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs);
269271
};
270272

271273
#endif // BITCOIN_ADDRMAN_IMPL_H

test/functional/feature_asmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def test_asmap_interaction_with_addrman_containing_entries(self):
8989
self.restart_node(0, ["-asmap", "-checkaddrman=1"])
9090
with self.node.assert_debug_log(
9191
expected_msgs=[
92-
"Addrman checks started: new 1, tried 1, total 2",
93-
"Addrman checks completed successfully",
92+
"CheckAddrman: new 1, tried 1, total 2 started",
93+
"CheckAddrman: completed",
9494
]
9595
):
9696
self.node.getnodeaddresses() # getnodeaddresses re-runs the addrman checks

test/functional/rpc_net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_addpeeraddress(self):
260260

261261
self.log.debug("Test that adding a valid address to the tried table succeeds")
262262
assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True})
263-
with node.assert_debug_log(expected_msgs=["Addrman checks started: new 0, tried 1, total 1"]):
263+
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 0, tried 1, total 1 started"]):
264264
addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks
265265
assert_equal(len(addrs), 1)
266266
assert_equal(addrs[0]["address"], "1.2.3.4")
@@ -273,7 +273,7 @@ def test_addpeeraddress(self):
273273

274274
self.log.debug("Test that adding a second address, this time to the new table, succeeds")
275275
assert_equal(node.addpeeraddress(address="2.0.0.0", port=8333), {"success": True})
276-
with node.assert_debug_log(expected_msgs=["Addrman checks started: new 1, tried 1, total 2"]):
276+
with node.assert_debug_log(expected_msgs=["CheckAddrman: new 1, tried 1, total 2 started"]):
277277
addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks
278278
assert_equal(len(addrs), 2)
279279

0 commit comments

Comments
 (0)