mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-23 22:19:39 +01:00
Merge bitcoin/bitcoin#33878: refactor, docs: Embedded ASMap [2/3]: Refactor asmap internals and add documentation
4fec726c4drefactor: Simplify Interpret asmap function (Fabian Jahr)79e97d45c1doc: Add more extensive docs to asmap implementation (Fabian Jahr)cf4943fdcdrefactor: Use span instead of vector for data in util/asmap (Fabian Jahr)385c34a052refactor: Unify asmap version calculation and naming (Fabian Jahr)fa41fc6a1arefactor: Operate on bytes instead of bits in Asmap code (Fabian Jahr) Pull request description: This is a second slice carved out of #28792. It contains the following changes that are crucial for the embedding of asmap data which is added the following PR in the series (probably this will remain in #28792). The changes are: - Modernizes and simplifies the asmap code by operating on `std::byte` instead of bits - Unifies asmap version calculation and naming (previously it was called version and checksum interchangeably) - Operate on a `span` rather than a vector in the asmap internal to prevent holding the asmap data in memory twice - Add more extensive documentation to the asmap implementation - Unify asmap casing in implemetation function names The first three commits were already part of #28792, the others are new. The documentation commit came out of feedback gathered at the latest CoreDev. The primary input for the documentation was the documentation that already existed in the Python implementation (`contrib/asmap/asmap.py`) but there are several other comments as well. Please note: I have also asked several LLMs to provide suggestions on how to explain pieces of the implementation and better demonstrate how the parts work together. I have copied bits and pieces that I liked but everything has been edited further by me and obviously all mistakes here are my own. ACKs for top commit: hodlinator: re-ACK4fec726c4dsipa: ACK4fec726c4dsedited: Re-ACK4fec726c4dTree-SHA512: 950a591c3fcc9ddb28fcfdc3164ad3fbd325fa5004533c4a8b670fbf8b956060a0daeedd1fc2fced1f761ac49cd992b79cabe12ef46bc60b2559a7a613d0e166
This commit is contained in:
17
src/init.cpp
17
src/init.cpp
@@ -96,6 +96,7 @@
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
@@ -1559,9 +1560,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
ApplyArgsManOptions(args, peerman_opts);
|
||||
|
||||
{
|
||||
|
||||
// Read asmap file if configured
|
||||
std::vector<bool> asmap;
|
||||
// Read asmap file if configured and initialize
|
||||
// Netgroupman with or without it
|
||||
assert(!node.netgroupman);
|
||||
if (args.IsArgSet("-asmap") && !args.IsArgNegated("-asmap")) {
|
||||
fs::path asmap_path = args.GetPathArg("-asmap");
|
||||
if (asmap_path.empty()) {
|
||||
@@ -1575,21 +1576,19 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
InitError(strprintf(_("Could not find asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
|
||||
return false;
|
||||
}
|
||||
asmap = DecodeAsmap(asmap_path);
|
||||
std::vector<std::byte> asmap{DecodeAsmap(asmap_path)};
|
||||
if (asmap.size() == 0) {
|
||||
InitError(strprintf(_("Could not parse asmap file %s"), fs::quoted(fs::PathToString(asmap_path))));
|
||||
return false;
|
||||
}
|
||||
const uint256 asmap_version = (HashWriter{} << asmap).GetHash();
|
||||
const uint256 asmap_version = AsmapVersion(asmap);
|
||||
node.netgroupman = std::make_unique<NetGroupManager>(NetGroupManager::WithLoadedAsmap(std::move(asmap)));
|
||||
LogInfo("Using asmap version %s for IP bucketing", asmap_version.ToString());
|
||||
} else {
|
||||
node.netgroupman = std::make_unique<NetGroupManager>(NetGroupManager::NoAsmap());
|
||||
LogInfo("Using /16 prefix for IP bucketing");
|
||||
}
|
||||
|
||||
// Initialize netgroup manager
|
||||
assert(!node.netgroupman);
|
||||
node.netgroupman = std::make_unique<NetGroupManager>(std::move(asmap));
|
||||
|
||||
// Initialize addrman
|
||||
assert(!node.addrman);
|
||||
uiInterface.InitMessage(_("Loading P2P addresses…"));
|
||||
|
||||
Reference in New Issue
Block a user