diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-08-18 09:17:06 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-09-21 10:07:48 +0200 |
commit | fa298971e6890715e2b0b93f2a7f445d32d6622f (patch) | |
tree | ff3f0226efbeaead1a766aa5f134b3eaf76a1cb6 /src | |
parent | fae5c633dc05a045aaac370b383e4799cb0e0590 (diff) | |
download | bitcoin-fa298971e6890715e2b0b93f2a7f445d32d6622f.tar.xz |
Refactor: Turn the internal addrman check helper into a forced check
Diffstat (limited to 'src')
-rw-r--r-- | src/addrman.cpp | 12 | ||||
-rw-r--r-- | src/addrman.h | 7 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index e3f370134f..a6f38075d8 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -747,21 +747,21 @@ void CAddrMan::Check() const { AssertLockHeld(cs); - const int err = Check_(); + // Run consistency checks 1 in m_consistency_check_ratio times if enabled + if (m_consistency_check_ratio == 0) return; + if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return; + + const int err{ForceCheckAddrman()}; if (err) { LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err); assert(false); } } -int CAddrMan::Check_() const +int CAddrMan::ForceCheckAddrman() const { 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; - LogPrint(BCLog::ADDRMAN, "Addrman checks started: new %i, tried %i, total %u\n", nNew, nTried, vRandom.size()); std::unordered_set<int> setTried; diff --git a/src/addrman.h b/src/addrman.h index ca291d60ab..7dd8528bef 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -391,11 +391,12 @@ private: //! Return a random to-be-evicted tried table address. CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs); - //! Consistency check + //! 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. Returns an error code or zero. - int 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); /** * Return all or many randomly selected addresses, optionally by network. |