|
11 | 11 | #include <netaddress.h>
|
12 | 12 | #include <serialize.h>
|
13 | 13 | #include <streams.h>
|
| 14 | +#include <util/check.h> |
14 | 15 |
|
15 | 16 | #include <cmath>
|
16 | 17 | #include <optional>
|
@@ -488,11 +489,14 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
|
488 | 489 | AssertLockHeld(cs);
|
489 | 490 |
|
490 | 491 | // remove the entry from all new buckets
|
491 |
| - for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) { |
492 |
| - int pos = info.GetBucketPosition(nKey, true, bucket); |
| 492 | + const int start_bucket{info.GetNewBucket(nKey, m_asmap)}; |
| 493 | + for (int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; ++n) { |
| 494 | + const int bucket{(start_bucket + n) % ADDRMAN_NEW_BUCKET_COUNT}; |
| 495 | + const int pos{info.GetBucketPosition(nKey, true, bucket)}; |
493 | 496 | if (vvNew[bucket][pos] == nId) {
|
494 | 497 | vvNew[bucket][pos] = -1;
|
495 | 498 | info.nRefCount--;
|
| 499 | + if (info.nRefCount == 0) break; |
496 | 500 | }
|
497 | 501 | }
|
498 | 502 | nNew--;
|
@@ -564,22 +568,10 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
|
564 | 568 | if (info.fInTried)
|
565 | 569 | return;
|
566 | 570 |
|
567 |
| - // find a bucket it is in now |
568 |
| - int nRnd = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT); |
569 |
| - int nUBucket = -1; |
570 |
| - for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) { |
571 |
| - int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT; |
572 |
| - int nBpos = info.GetBucketPosition(nKey, true, nB); |
573 |
| - if (vvNew[nB][nBpos] == nId) { |
574 |
| - nUBucket = nB; |
575 |
| - break; |
576 |
| - } |
577 |
| - } |
578 |
| - |
579 |
| - // if no bucket is found, something bad happened; |
580 |
| - // TODO: maybe re-add the node, but for now, just bail out |
581 |
| - if (nUBucket == -1) |
| 571 | + // if it is not in new, something bad happened |
| 572 | + if (!Assume(info.nRefCount > 0)) { |
582 | 573 | return;
|
| 574 | + } |
583 | 575 |
|
584 | 576 | // which tried bucket to move the entry to
|
585 | 577 | int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
|
|
0 commit comments