refactor: Unify asmap version calculation and naming

Calculate the asmap version only in one place: A dedicated function in util/asmap.

The version was also referred to as asmap checksum in several places. To avoid confusion call it asmap version everywhere.
This commit is contained in:
Fabian Jahr
2025-04-22 23:44:06 +02:00
parent fa41fc6a1a
commit 385c34a052
6 changed files with 27 additions and 15 deletions

View File

@@ -5,9 +5,11 @@
#include <util/asmap.h>
#include <clientversion.h>
#include <hash.h>
#include <logging.h>
#include <serialize.h>
#include <streams.h>
#include <uint256.h>
#include <util/fs.h>
#include <algorithm>
@@ -223,3 +225,12 @@ std::vector<std::byte> DecodeAsmap(fs::path path)
return buffer;
}
uint256 AsmapVersion(const std::vector<std::byte>& data)
{
if (data.empty()) return {};
HashWriter asmap_hasher;
asmap_hasher << data;
return asmap_hasher.GetHash();
}

View File

@@ -5,6 +5,7 @@
#ifndef BITCOIN_UTIL_ASMAP_H
#define BITCOIN_UTIL_ASMAP_H
#include <uint256.h>
#include <util/fs.h>
#include <cstddef>
@@ -17,5 +18,7 @@ bool SanityCheckASMap(const std::vector<std::byte>& asmap, int bits);
/** Read asmap from provided binary file */
std::vector<std::byte> DecodeAsmap(fs::path path);
/** Calculate the asmap version, a checksum identifying the asmap being used. */
uint256 AsmapVersion(const std::vector<std::byte>& data);
#endif // BITCOIN_UTIL_ASMAP_H