From 9bf078f66c8f286e1ab5e34b8eeed7d80290a897 Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Sat, 18 Feb 2023 17:38:58 -0700 Subject: [PATCH] refactor: update Select_ function Extract the logic that decides whether the new or the tried table is going to be searched to the beginning of the function. Co-authored-by: Martin Zumsande --- src/addrman.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index f5ca9a5c343..ec5b0213b3c 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -719,12 +719,21 @@ std::pair AddrManImpl::Select_(bool newOnly) const AssertLockHeld(cs); if (vRandom.empty()) return {}; - if (newOnly && nNew == 0) return {}; + // Decide if we are going to search the new or tried table + bool search_tried; + // Use a 50% chance for choosing between tried and new table entries. if (!newOnly && - (nTried > 0 && (nNew == 0 || insecure_rand.randbool() == 0))) { + (nTried > 0 && + (nNew == 0 || insecure_rand.randbool() == 0))) { + search_tried = true; + } else { + search_tried = false; + } + + if (search_tried) { // use a tried node double fChanceFactor = 1.0; while (1) {