aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
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.h
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.h')
-rw-r--r--src/addrman.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 2c6ffbe523..3ee8c3ee09 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -26,6 +26,9 @@
#include <unordered_map>
#include <vector>
+/** Default for -checkaddrman */
+static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS{0};
+
/**
* Extended statistics about a CAddress
*/
@@ -124,8 +127,8 @@ public:
* attempt was unsuccessful.
* * Bucket selection is based on cryptographic hashing, using a randomly-generated 256-bit key, which should not
* be observable by adversaries.
- * * Several indexes are kept for high performance. Defining DEBUG_ADDRMAN will introduce frequent (and expensive)
- * consistency checks for the entire data structure.
+ * * Several indexes are kept for high performance. Setting m_consistency_check_ratio with the -checkaddrman
+ * configuration option will introduce (expensive) consistency checks for the entire data structure.
*/
//! total number of buckets for tried addresses
@@ -493,8 +496,9 @@ public:
mapAddr.clear();
}
- explicit CAddrMan(bool deterministic)
- : insecure_rand{deterministic}
+ explicit CAddrMan(bool deterministic, int32_t consistency_check_ratio)
+ : insecure_rand{deterministic},
+ m_consistency_check_ratio{consistency_check_ratio}
{
Clear();
if (deterministic) nKey = uint256{1};
@@ -700,6 +704,9 @@ private:
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
std::set<int> m_tried_collisions;
+ /** Perform consistency checks every m_consistency_check_ratio operations (if non-zero). */
+ const int32_t m_consistency_check_ratio;
+
//! Find an entry.
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -737,13 +744,14 @@ private:
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
//! Consistency check
- void Check() const
- EXCLUSIVE_LOCKS_REQUIRED(cs)
+ void Check() const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
AssertLockHeld(cs);
+
const int err = Check_();
if (err) {
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
+ assert(false);
}
}