mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 22:42:04 +01:00
addrman: Improve performance of Good
This is done by removing an unnecessary loop in Good_() and looping through the new tables in MakeTried() more efficiently, choosing a starting value that allow us to stop early in typical cases. Co-authored-by: John Newbery <john@johnnewbery.com>
This commit is contained in:
parent
2161a05855
commit
eb2e113df1
1 changed files with 9 additions and 17 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <util/check.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -488,11 +489,14 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
// remove the entry from all new buckets
|
// remove the entry from all new buckets
|
||||||
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
|
const int start_bucket{info.GetNewBucket(nKey, m_asmap)};
|
||||||
int pos = info.GetBucketPosition(nKey, true, bucket);
|
for (int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; ++n) {
|
||||||
|
const int bucket{(start_bucket + n) % ADDRMAN_NEW_BUCKET_COUNT};
|
||||||
|
const int pos{info.GetBucketPosition(nKey, true, bucket)};
|
||||||
if (vvNew[bucket][pos] == nId) {
|
if (vvNew[bucket][pos] == nId) {
|
||||||
vvNew[bucket][pos] = -1;
|
vvNew[bucket][pos] = -1;
|
||||||
info.nRefCount--;
|
info.nRefCount--;
|
||||||
|
if (info.nRefCount == 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nNew--;
|
nNew--;
|
||||||
|
@ -564,22 +568,10 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
|
||||||
if (info.fInTried)
|
if (info.fInTried)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// find a bucket it is in now
|
// if it is not in new, something bad happened
|
||||||
int nRnd = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT);
|
if (!Assume(info.nRefCount > 0)) {
|
||||||
int nUBucket = -1;
|
|
||||||
for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
|
|
||||||
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
|
|
||||||
int nBpos = info.GetBucketPosition(nKey, true, nB);
|
|
||||||
if (vvNew[nB][nBpos] == nId) {
|
|
||||||
nUBucket = nB;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no bucket is found, something bad happened;
|
|
||||||
// TODO: maybe re-add the node, but for now, just bail out
|
|
||||||
if (nUBucket == -1)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// which tried bucket to move the entry to
|
// which tried bucket to move the entry to
|
||||||
int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
|
int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
|
||||||
|
|
Loading…
Add table
Reference in a new issue