@@ -1171,10 +1171,39 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1171
1171
fDiscover = args.GetBoolArg (" -discover" , true );
1172
1172
const bool ignores_incoming_txs{args.GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY)};
1173
1173
1174
- assert (!node.addrman );
1175
- auto check_addrman = std::clamp<int32_t >(args.GetArg (" -checkaddrman" , DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0 , 1000000 );
1176
- node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false , /* consistency_check_ratio */ check_addrman);
1177
1174
{
1175
+ // Initialize addrman
1176
+ assert (!node.addrman );
1177
+
1178
+ // Read asmap file if configured
1179
+ std::vector<bool > asmap;
1180
+ if (args.IsArgSet (" -asmap" )) {
1181
+ fs::path asmap_path = fs::path (args.GetArg (" -asmap" , " " ));
1182
+ if (asmap_path.empty ()) {
1183
+ asmap_path = DEFAULT_ASMAP_FILENAME;
1184
+ }
1185
+ if (!asmap_path.is_absolute ()) {
1186
+ asmap_path = gArgs .GetDataDirNet () / asmap_path;
1187
+ }
1188
+ if (!fs::exists (asmap_path)) {
1189
+ InitError (strprintf (_ (" Could not find asmap file %s" ), asmap_path));
1190
+ return false ;
1191
+ }
1192
+ asmap = CAddrMan::DecodeAsmap (asmap_path);
1193
+ if (asmap.size () == 0 ) {
1194
+ InitError (strprintf (_ (" Could not parse asmap file %s" ), asmap_path));
1195
+ return false ;
1196
+ }
1197
+ const uint256 asmap_version = SerializeHash (asmap);
1198
+ LogPrintf (" Using asmap version %s for IP bucketing\n " , asmap_version.ToString ());
1199
+ } else {
1200
+ LogPrintf (" Using /16 prefix for IP bucketing\n " );
1201
+ }
1202
+
1203
+ auto check_addrman = std::clamp<int32_t >(args.GetArg (" -checkaddrman" , DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0 , 1000000 );
1204
+ node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false , /* consistency_check_ratio */ check_addrman);
1205
+ node.addrman ->m_asmap = asmap;
1206
+
1178
1207
// Load addresses from peers.dat
1179
1208
uiInterface.InitMessage (_ (" Loading P2P addresses…" ).translated );
1180
1209
int64_t nStart = GetTimeMillis ();
@@ -1184,10 +1213,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1184
1213
} else {
1185
1214
// Addrman can be in an inconsistent state after failure, reset it
1186
1215
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false , /* consistency_check_ratio */ check_addrman);
1216
+ node.addrman ->m_asmap = asmap;
1187
1217
LogPrintf (" Recreating peers.dat\n " );
1188
1218
adb.Write (*node.addrman );
1189
1219
}
1190
1220
}
1221
+
1191
1222
assert (!node.banman );
1192
1223
node.banman = std::make_unique<BanMan>(gArgs .GetDataDirNet () / " banlist" , &uiInterface, args.GetArg (" -bantime" , DEFAULT_MISBEHAVING_BANTIME));
1193
1224
assert (!node.connman );
@@ -1292,31 +1323,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1292
1323
return InitError (ResolveErrMsg (" externalip" , strAddr));
1293
1324
}
1294
1325
1295
- // Read asmap file if configured
1296
- if (args.IsArgSet (" -asmap" )) {
1297
- fs::path asmap_path = fs::path (args.GetArg (" -asmap" , " " ));
1298
- if (asmap_path.empty ()) {
1299
- asmap_path = DEFAULT_ASMAP_FILENAME;
1300
- }
1301
- if (!asmap_path.is_absolute ()) {
1302
- asmap_path = gArgs .GetDataDirNet () / asmap_path;
1303
- }
1304
- if (!fs::exists (asmap_path)) {
1305
- InitError (strprintf (_ (" Could not find asmap file %s" ), asmap_path));
1306
- return false ;
1307
- }
1308
- std::vector<bool > asmap = CAddrMan::DecodeAsmap (asmap_path);
1309
- if (asmap.size () == 0 ) {
1310
- InitError (strprintf (_ (" Could not parse asmap file %s" ), asmap_path));
1311
- return false ;
1312
- }
1313
- const uint256 asmap_version = SerializeHash (asmap);
1314
- node.connman ->SetAsmap (std::move (asmap));
1315
- LogPrintf (" Using asmap version %s for IP bucketing\n " , asmap_version.ToString ());
1316
- } else {
1317
- LogPrintf (" Using /16 prefix for IP bucketing\n " );
1318
- }
1319
-
1320
1326
#if ENABLE_ZMQ
1321
1327
g_zmq_notification_interface = CZMQNotificationInterface::Create ();
1322
1328
0 commit comments