Skip to content

Commit 8062d92

Browse files
committed
[addrman] Rename asmap version to asmap checksum
Version implies that higher numbers take precendence. This is really a checksum, to check whether the provided asmap is the same as the one used when the peers.dat file was serialized. Also update the comments to explain where/why this is used.
1 parent 009b8e0 commit 8062d92

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/addrman.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ friend class CAddrManTest;
340340
* * for each bucket:
341341
* * number of elements
342342
* * for each element: index
343+
* * asmap checksum
343344
*
344345
* 2**30 is xorred with the number of buckets to make addrman deserializer v0 detect it
345346
* as incompatible. This is necessary because it did not check the version number on
@@ -348,8 +349,8 @@ friend class CAddrManTest;
348349
* Notice that vvTried, mapAddr and vVector are never encoded explicitly;
349350
* they are instead reconstructed from the other information.
350351
*
351-
* vvNew is serialized, but only used if ADDRMAN_UNKNOWN_BUCKET_COUNT didn't change,
352-
* otherwise it is reconstructed as well.
352+
* vvNew is serialized, but only used if ADDRMAN_NEW_BUCKET_COUNT and the asmap checksum
353+
* didn't change, otherwise it is reconstructed as well.
353354
*
354355
* This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
355356
* changes to the ADDRMAN_ parameters without breaking the on-disk structure.
@@ -413,13 +414,13 @@ friend class CAddrManTest;
413414
}
414415
}
415416
}
416-
// Store asmap version after bucket entries so that it
417+
// Store asmap checksum after bucket entries so that it
417418
// can be ignored by older clients for backward compatibility.
418-
uint256 asmap_version;
419+
uint256 asmap_checksum;
419420
if (m_asmap.size() != 0) {
420-
asmap_version = SerializeHash(m_asmap);
421+
asmap_checksum = SerializeHash(m_asmap);
421422
}
422-
s << asmap_version;
423+
s << asmap_checksum;
423424
}
424425

425426
template <typename Stream>
@@ -516,13 +517,13 @@ friend class CAddrManTest;
516517
}
517518
}
518519

519-
uint256 supplied_asmap_version;
520+
uint256 supplied_asmap_checksum;
520521
if (m_asmap.size() != 0) {
521-
supplied_asmap_version = SerializeHash(m_asmap);
522+
supplied_asmap_checksum = SerializeHash(m_asmap);
522523
}
523-
uint256 serialized_asmap_version;
524+
uint256 serialized_asmap_checksum;
524525
if (format >= Format::V2_ASMAP) {
525-
s >> serialized_asmap_version;
526+
s >> serialized_asmap_checksum;
526527
}
527528

528529
for (auto bucket_entry : bucket_entries) {
@@ -531,7 +532,7 @@ friend class CAddrManTest;
531532
CAddrInfo& info = mapInfo[entry_index];
532533
int nUBucketPos = info.GetBucketPosition(nKey, true, bucket);
533534
if (format >= Format::V2_ASMAP && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 &&
534-
info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_version == supplied_asmap_version) {
535+
info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_checksum == supplied_asmap_checksum) {
535536
// Bucketing has not changed, using existing bucket positions for the new table
536537
vvNew[bucket][nUBucketPos] = entry_index;
537538
info.nRefCount++;

0 commit comments

Comments
 (0)