aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2020-12-03 11:00:08 +0000
committerJohn Newbery <john@johnnewbery.com>2021-01-18 13:23:16 +0000
commit8062d928ce5c495c1b6ecd18e4b30c12da822d90 (patch)
tree7fedda3656451ae36c7c3d6722594c8201025fb7 /src/addrman.h
parent009b8e0fdf3bfb11668edacced5d8b70726d5d0e (diff)
downloadbitcoin-8062d928ce5c495c1b6ecd18e4b30c12da822d90.tar.xz
[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.
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 4cd4106ff4..75e9f36b86 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -340,6 +340,7 @@ public:
* * for each bucket:
* * number of elements
* * for each element: index
+ * * asmap checksum
*
* 2**30 is xorred with the number of buckets to make addrman deserializer v0 detect it
* as incompatible. This is necessary because it did not check the version number on
@@ -348,8 +349,8 @@ public:
* Notice that vvTried, mapAddr and vVector are never encoded explicitly;
* they are instead reconstructed from the other information.
*
- * vvNew is serialized, but only used if ADDRMAN_UNKNOWN_BUCKET_COUNT didn't change,
- * otherwise it is reconstructed as well.
+ * vvNew is serialized, but only used if ADDRMAN_NEW_BUCKET_COUNT and the asmap checksum
+ * didn't change, otherwise it is reconstructed as well.
*
* This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
* changes to the ADDRMAN_ parameters without breaking the on-disk structure.
@@ -413,13 +414,13 @@ public:
}
}
}
- // Store asmap version after bucket entries so that it
+ // Store asmap checksum after bucket entries so that it
// can be ignored by older clients for backward compatibility.
- uint256 asmap_version;
+ uint256 asmap_checksum;
if (m_asmap.size() != 0) {
- asmap_version = SerializeHash(m_asmap);
+ asmap_checksum = SerializeHash(m_asmap);
}
- s << asmap_version;
+ s << asmap_checksum;
}
template <typename Stream>
@@ -516,13 +517,13 @@ public:
}
}
- uint256 supplied_asmap_version;
+ uint256 supplied_asmap_checksum;
if (m_asmap.size() != 0) {
- supplied_asmap_version = SerializeHash(m_asmap);
+ supplied_asmap_checksum = SerializeHash(m_asmap);
}
- uint256 serialized_asmap_version;
+ uint256 serialized_asmap_checksum;
if (format >= Format::V2_ASMAP) {
- s >> serialized_asmap_version;
+ s >> serialized_asmap_checksum;
}
for (auto bucket_entry : bucket_entries) {
@@ -531,7 +532,7 @@ public:
CAddrInfo& info = mapInfo[entry_index];
int nUBucketPos = info.GetBucketPosition(nKey, true, bucket);
if (format >= Format::V2_ASMAP && nUBuckets == ADDRMAN_NEW_BUCKET_COUNT && vvNew[bucket][nUBucketPos] == -1 &&
- info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_version == supplied_asmap_version) {
+ info.nRefCount < ADDRMAN_NEW_BUCKETS_PER_ADDRESS && serialized_asmap_checksum == supplied_asmap_checksum) {
// Bucketing has not changed, using existing bucket positions for the new table
vvNew[bucket][nUBucketPos] = entry_index;
info.nRefCount++;