aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2020-10-23 22:03:24 +0100
committerJohn Newbery <john@johnnewbery.com>2021-08-12 10:41:11 +0100
commita4d78546b0858602c60c03fdf8b35ca666ab2e56 (patch)
treec029c3a4ea6b74ff7d9977138d18661ab4181d69 /src/addrman.cpp
parent10aac241455a3270462d49b53732477ed97623e7 (diff)
downloadbitcoin-a4d78546b0858602c60c03fdf8b35ca666ab2e56.tar.xz
[addrman] Make addrman consistency checks a runtime option
Currently addrman consistency checks are a compile time option, and are not enabled in our CI. It's unlikely anyone is running these consistency checks. Make them a runtime option instead, where users can enable addrman consistency checks every n operations (similar to mempool tests). Update the addrman unit tests to do internal consistency checks every 100 operations (checking on every operations causes the test runtime to increase by several seconds). Also assert on a failed addrman consistency check to terminate program execution.
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index c5c6dfbb86..8e2fc67569 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -433,9 +433,12 @@ CAddrInfo CAddrMan::Select_(bool newOnly) const
int CAddrMan::Check_() const
{
-#ifdef DEBUG_ADDRMAN
AssertLockHeld(cs);
+ // Run consistency checks 1 in m_consistency_check_ratio times if enabled
+ if (m_consistency_check_ratio == 0) return 0;
+ if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return 0;
+
std::unordered_set<int> setTried;
std::unordered_map<int, int> mapNew;
@@ -514,7 +517,6 @@ int CAddrMan::Check_() const
if (nKey.IsNull())
return -16;
-#endif // DEBUG_ADDRMAN
return 0;
}