mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-28 00:16:04 +01:00
refactor: Use span instead of vector for data in util/asmap
This prevents holding the asmap data in memory twice. The version hash changes due to spans being serialized without their size-prefix (unlike vectors).
This commit is contained in:
16
src/init.cpp
16
src/init.cpp
@@ -1560,9 +1560,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
ApplyArgsManOptions(args, peerman_opts);
|
||||
|
||||
{
|
||||
|
||||
// Read asmap file if configured
|
||||
std::vector<std::byte> 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()) {
|
||||
@@ -1576,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 = AsmapVersion(asmap);;
|
||||
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