[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.
This commit is contained in:
John Newbery
2020-10-23 22:03:24 +01:00
parent 10aac24145
commit a4d78546b0
11 changed files with 37 additions and 25 deletions

View File

@@ -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;
}