From 7102d50a477eccca06ea2166a6ae8a9e87cd76e3 Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 22 Apr 2023 15:54:13 -0700 Subject: [PATCH] Try to prevent #266 We seem to have a bug that we don't find a peer when looking for a peer in peers.dat . Instead of doing an assertion and crashing the node, just keep iterating in the loop. The code which computes nId may have an off-by-one error, such that it looks up an incorrect bucket position and doesn't find a valid nId. --- src/addrman.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 60f27347a..535151c2a 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -499,7 +499,12 @@ CAddrInfo CAddrMan::Select_(bool newOnly) MilliSleep(kRetrySleepInterval); } int nId = vvTried[nKBucket][nKBucketPos]; - assert(mapInfo.count(nId) == 1); + // assert(mapInfo.count(nId) == 1); + if(mapInfo.count(nId) != 1) { + fprintf(stderr,"%s: Could not find tried node with nId=%d=vvTried[%d][%d], mapInfo.count(%d)=%d\n", __func__, nId, nKBucket, nKBuckedPos, nId, mapInfo.count(nId) ); + continue; + } + CAddrInfo& info = mapInfo[nId]; if (info.IsReachableNetwork()) { //deprioritize unreachable networks @@ -534,7 +539,12 @@ CAddrInfo CAddrMan::Select_(bool newOnly) MilliSleep(kRetrySleepInterval); } int nId = vvNew[nUBucket][nUBucketPos]; - assert(mapInfo.count(nId) == 1); + + if(mapInfo.count(nId) != 1) { + fprintf(stderr,"%s: Could not find new node with nId=%d=vvNew[%d][%d], mapInfo.count(%d)=%d\n", __func__, nId, nUBucket, nUBuckedPos, nId, mapInfo.count(nId) ); + continue; + } + // assert(mapInfo.count(nId) == 1); CAddrInfo& info = mapInfo[nId]; if (info.IsReachableNetwork()) { //deprioritize unreachable networks