Skip to content

Commit fa29897

Browse files
author
MarcoFalke
committed
Refactor: Turn the internal addrman check helper into a forced check
1 parent fae5c63 commit fa29897

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/addrman.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,21 +747,21 @@ void CAddrMan::Check() const
747747
{
748748
AssertLockHeld(cs);
749749

750-
const int err = Check_();
750+
// Run consistency checks 1 in m_consistency_check_ratio times if enabled
751+
if (m_consistency_check_ratio == 0) return;
752+
if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
753+
754+
const int err{ForceCheckAddrman()};
751755
if (err) {
752756
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
753757
assert(false);
754758
}
755759
}
756760

757-
int CAddrMan::Check_() const
761+
int CAddrMan::ForceCheckAddrman() const
758762
{
759763
AssertLockHeld(cs);
760764

761-
// Run consistency checks 1 in m_consistency_check_ratio times if enabled
762-
if (m_consistency_check_ratio == 0) return 0;
763-
if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return 0;
764-
765765
LogPrint(BCLog::ADDRMAN, "Addrman checks started: new %i, tried %i, total %u\n", nNew, nTried, vRandom.size());
766766

767767
std::unordered_set<int> setTried;

src/addrman.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,12 @@ class CAddrMan
391391
//! Return a random to-be-evicted tried table address.
392392
CAddrInfo SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs);
393393

394-
//! Consistency check
394+
//! Consistency check, taking into account m_consistency_check_ratio. Will std::abort if an inconsistency is detected.
395395
void Check() const EXCLUSIVE_LOCKS_REQUIRED(cs);
396396

397-
//! Perform consistency check. Returns an error code or zero.
398-
int Check_() const EXCLUSIVE_LOCKS_REQUIRED(cs);
397+
//! Perform consistency check, regardless of m_consistency_check_ratio.
398+
//! @returns an error code or zero.
399+
int ForceCheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs);
399400

400401
/**
401402
* Return all or many randomly selected addresses, optionally by network.

0 commit comments

Comments
 (0)