Skip to content

Commit 9bf078f

Browse files
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 <[email protected]>
1 parent a245429 commit 9bf078f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/addrman.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,21 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
719719
AssertLockHeld(cs);
720720

721721
if (vRandom.empty()) return {};
722-
723722
if (newOnly && nNew == 0) return {};
724723

724+
// Decide if we are going to search the new or tried table
725+
bool search_tried;
726+
725727
// Use a 50% chance for choosing between tried and new table entries.
726728
if (!newOnly &&
727-
(nTried > 0 && (nNew == 0 || insecure_rand.randbool() == 0))) {
729+
(nTried > 0 &&
730+
(nNew == 0 || insecure_rand.randbool() == 0))) {
731+
search_tried = true;
732+
} else {
733+
search_tried = false;
734+
}
735+
736+
if (search_tried) {
728737
// use a tried node
729738
double fChanceFactor = 1.0;
730739
while (1) {

0 commit comments

Comments
 (0)