Skip to content

Commit 1ba3e1c

Browse files
committed
init: move asmap code earlier in init process
and update feature_asmap.py and test_runner.py This commit moves the asmap init.cpp code from the end of "Step 12: start node" to "Step 6: network initialization" to provide feedback on passing an -asmap config arg much more quickly. This change speeds up the feature_asmap.py functional test file from 60 to 5 seconds by accelerating the 2 tests that use `assert_start_raises_init_error`. Credit to Wladimir J. van der Laan for the suggestion.
1 parent 5ba829e commit 1ba3e1c

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

src/init.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,31 @@ bool AppInitMain(NodeContext& node)
14181418
return InitError(ResolveErrMsg("externalip", strAddr));
14191419
}
14201420

1421+
// Read asmap file if configured
1422+
if (gArgs.IsArgSet("-asmap")) {
1423+
fs::path asmap_path = fs::path(gArgs.GetArg("-asmap", ""));
1424+
if (asmap_path.empty()) {
1425+
asmap_path = DEFAULT_ASMAP_FILENAME;
1426+
}
1427+
if (!asmap_path.is_absolute()) {
1428+
asmap_path = GetDataDir() / asmap_path;
1429+
}
1430+
if (!fs::exists(asmap_path)) {
1431+
InitError(strprintf(_("Could not find asmap file %s").translated, asmap_path));
1432+
return false;
1433+
}
1434+
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
1435+
if (asmap.size() == 0) {
1436+
InitError(strprintf(_("Could not parse asmap file %s").translated, asmap_path));
1437+
return false;
1438+
}
1439+
const uint256 asmap_version = SerializeHash(asmap);
1440+
node.connman->SetAsmap(std::move(asmap));
1441+
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
1442+
} else {
1443+
LogPrintf("Using /16 prefix for IP bucketing\n");
1444+
}
1445+
14211446
#if ENABLE_ZMQ
14221447
g_zmq_notification_interface = CZMQNotificationInterface::Create();
14231448

@@ -1825,31 +1850,6 @@ bool AppInitMain(NodeContext& node)
18251850
return false;
18261851
}
18271852

1828-
// Read asmap file if configured
1829-
if (gArgs.IsArgSet("-asmap")) {
1830-
fs::path asmap_path = fs::path(gArgs.GetArg("-asmap", ""));
1831-
if (asmap_path.empty()) {
1832-
asmap_path = DEFAULT_ASMAP_FILENAME;
1833-
}
1834-
if (!asmap_path.is_absolute()) {
1835-
asmap_path = GetDataDir() / asmap_path;
1836-
}
1837-
if (!fs::exists(asmap_path)) {
1838-
InitError(strprintf(_("Could not find asmap file %s").translated, asmap_path));
1839-
return false;
1840-
}
1841-
std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
1842-
if (asmap.size() == 0) {
1843-
InitError(strprintf(_("Could not parse asmap file %s").translated, asmap_path));
1844-
return false;
1845-
}
1846-
const uint256 asmap_version = SerializeHash(asmap);
1847-
node.connman->SetAsmap(std::move(asmap));
1848-
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
1849-
} else {
1850-
LogPrintf("Using /16 prefix for IP bucketing\n");
1851-
}
1852-
18531853
// ********************************************************* Step 13: finished
18541854

18551855
SetRPCWarmupFinished();

test/functional/feature_asmap.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
1919
6. `bitcoind -asmap` with an empty (unparsable) default asmap file
2020
21-
The tests are order-independent. The slowest tests (missing default asmap and
22-
empty asmap) are placed last.
21+
The tests are order-independent.
2322
2423
"""
2524
import os

test/functional/test_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
'rpc_txoutproof.py',
102102
'wallet_listreceivedby.py',
103103
'wallet_abandonconflict.py',
104-
'feature_asmap.py',
105104
'feature_csv_activation.py',
106105
'rpc_rawtransaction.py',
107106
'wallet_address_types.py',
@@ -207,6 +206,7 @@
207206
'p2p_dos_header_tree.py',
208207
'p2p_unrequested_blocks.py',
209208
'feature_includeconf.py',
209+
'feature_asmap.py',
210210
'rpc_deriveaddresses.py',
211211
'rpc_deriveaddresses.py --usecli',
212212
'rpc_scantxoutset.py',

0 commit comments

Comments
 (0)