Skip to content

Commit b4c5fda

Browse files
committed
[addrman] Fix new table bucketing during unserialization
An addrman entry can appear in up to 8 new table buckets. We store this entry->bucket indexing during shutdown so that on restart we can restore the entries to their correct buckets. Commit ec45646 broke the deserialization code so that each entry could only be put in up to one new bucket. Fix that.
1 parent 7acda55 commit b4c5fda

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/addrman.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ friend class CAddrManTest;
500500
nTried -= nLost;
501501

502502
// Store positions in the new table buckets to apply later (if possible).
503-
std::map<int, int> entryToBucket; // Represents which entry belonged to which bucket when serializing
503+
// An entry may appear in up to ADDRMAN_NEW_BUCKETS_PER_ADDRESS buckets,
504+
// so we store all bucket-entry_index pairs to iterate through later.
505+
std::vector<std::pair<int, int>> bucket_entries;
504506

505507
for (int bucket = 0; bucket < nUBuckets; bucket++) {
506508
int nSize = 0;
@@ -509,7 +511,7 @@ friend class CAddrManTest;
509511
int nIndex = 0;
510512
s >> nIndex;
511513
if (nIndex >= 0 && nIndex < nNew) {
512-
entryToBucket[nIndex] = bucket;
514+
bucket_entries.emplace_back(bucket, nIndex);
513515
}
514516
}
515517
}
@@ -523,9 +525,10 @@ friend class CAddrManTest;
523525
s >> serialized_asmap_version;
524526
}
525527

526-
for (int n = 0; n < nNew; n++) {
527-
CAddrInfo &info = mapInfo[n];
528-
int bucket = entryToBucket[n];
528+
for (auto bucket_entry : bucket_entries) {
529+
int bucket{bucket_entry.first};
530+
const int n{bucket_entry.second};
531+
CAddrInfo& info = mapInfo[n];
529532
int nUBucketPos = info.GetBucketPosition(nKey, true, bucket);
530533
if (format >= Format::V2_ASMAP && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 &&
531534
info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_version == supplied_asmap_version) {

0 commit comments

Comments
 (0)