mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-08 19:01:08 +02:00
[init] Read/decode asmap before constructing addrman
Commit 181a1207 introduced an initialization order bug: CAddrMan's m_asmap must be set before deserializing peers.dat. Restore that ordering. review hint: use `git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space`
This commit is contained in:
parent
eb09c26724
commit
50fd77045e
58
src/init.cpp
58
src/init.cpp
@ -1171,10 +1171,39 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
fDiscover = args.GetBoolArg("-discover", true);
|
fDiscover = args.GetBoolArg("-discover", true);
|
||||||
const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
|
const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
|
||||||
|
|
||||||
|
{
|
||||||
|
// Initialize addrman
|
||||||
assert(!node.addrman);
|
assert(!node.addrman);
|
||||||
|
|
||||||
|
// Read asmap file if configured
|
||||||
|
std::vector<bool> asmap;
|
||||||
|
if (args.IsArgSet("-asmap")) {
|
||||||
|
fs::path asmap_path = fs::path(args.GetArg("-asmap", ""));
|
||||||
|
if (asmap_path.empty()) {
|
||||||
|
asmap_path = DEFAULT_ASMAP_FILENAME;
|
||||||
|
}
|
||||||
|
if (!asmap_path.is_absolute()) {
|
||||||
|
asmap_path = gArgs.GetDataDirNet() / asmap_path;
|
||||||
|
}
|
||||||
|
if (!fs::exists(asmap_path)) {
|
||||||
|
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
asmap = CAddrMan::DecodeAsmap(asmap_path);
|
||||||
|
if (asmap.size() == 0) {
|
||||||
|
InitError(strprintf(_("Could not parse asmap file %s"), asmap_path));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const uint256 asmap_version = SerializeHash(asmap);
|
||||||
|
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
|
||||||
|
} else {
|
||||||
|
LogPrintf("Using /16 prefix for IP bucketing\n");
|
||||||
|
}
|
||||||
|
|
||||||
auto check_addrman = std::clamp<int32_t>(args.GetArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
|
auto check_addrman = std::clamp<int32_t>(args.GetArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
|
||||||
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false, /* consistency_check_ratio */ check_addrman);
|
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false, /* consistency_check_ratio */ check_addrman);
|
||||||
{
|
node.addrman->m_asmap = asmap;
|
||||||
|
|
||||||
// Load addresses from peers.dat
|
// Load addresses from peers.dat
|
||||||
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
|
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
|
||||||
int64_t nStart = GetTimeMillis();
|
int64_t nStart = GetTimeMillis();
|
||||||
@ -1184,10 +1213,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
} else {
|
} else {
|
||||||
// Addrman can be in an inconsistent state after failure, reset it
|
// Addrman can be in an inconsistent state after failure, reset it
|
||||||
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false, /* consistency_check_ratio */ check_addrman);
|
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false, /* consistency_check_ratio */ check_addrman);
|
||||||
|
node.addrman->m_asmap = asmap;
|
||||||
LogPrintf("Recreating peers.dat\n");
|
LogPrintf("Recreating peers.dat\n");
|
||||||
adb.Write(*node.addrman);
|
adb.Write(*node.addrman);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!node.banman);
|
assert(!node.banman);
|
||||||
node.banman = std::make_unique<BanMan>(gArgs.GetDataDirNet() / "banlist", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
node.banman = std::make_unique<BanMan>(gArgs.GetDataDirNet() / "banlist", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
||||||
assert(!node.connman);
|
assert(!node.connman);
|
||||||
@ -1292,31 +1323,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
return InitError(ResolveErrMsg("externalip", strAddr));
|
return InitError(ResolveErrMsg("externalip", strAddr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read asmap file if configured
|
|
||||||
if (args.IsArgSet("-asmap")) {
|
|
||||||
fs::path asmap_path = fs::path(args.GetArg("-asmap", ""));
|
|
||||||
if (asmap_path.empty()) {
|
|
||||||
asmap_path = DEFAULT_ASMAP_FILENAME;
|
|
||||||
}
|
|
||||||
if (!asmap_path.is_absolute()) {
|
|
||||||
asmap_path = gArgs.GetDataDirNet() / asmap_path;
|
|
||||||
}
|
|
||||||
if (!fs::exists(asmap_path)) {
|
|
||||||
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
|
|
||||||
if (asmap.size() == 0) {
|
|
||||||
InitError(strprintf(_("Could not parse asmap file %s"), asmap_path));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const uint256 asmap_version = SerializeHash(asmap);
|
|
||||||
node.connman->SetAsmap(std::move(asmap));
|
|
||||||
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
|
|
||||||
} else {
|
|
||||||
LogPrintf("Using /16 prefix for IP bucketing\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLE_ZMQ
|
#if ENABLE_ZMQ
|
||||||
g_zmq_notification_interface = CZMQNotificationInterface::Create();
|
g_zmq_notification_interface = CZMQNotificationInterface::Create();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user