aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2020-01-29 16:38:25 +0100
committerJon Atack <jon@atack.com>2020-03-04 14:54:30 +0100
commit1ba3e1cc21150abe632a5b82a1a38998b33815dc (patch)
treeaa5b9d7709548bc186a8d0a62dfaa38ea61d1c59 /src/init.cpp
parent5ba829e12e99f119df56cab422f827b9be03fe57 (diff)
downloadbitcoin-1ba3e1cc21150abe632a5b82a1a38998b33815dc.tar.xz
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.
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/init.cpp b/src/init.cpp
index d7a44d1d4c..14d489617c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1418,6 +1418,31 @@ bool AppInitMain(NodeContext& node)
return InitError(ResolveErrMsg("externalip", strAddr));
}
+ // Read asmap file if configured
+ if (gArgs.IsArgSet("-asmap")) {
+ fs::path asmap_path = fs::path(gArgs.GetArg("-asmap", ""));
+ if (asmap_path.empty()) {
+ asmap_path = DEFAULT_ASMAP_FILENAME;
+ }
+ if (!asmap_path.is_absolute()) {
+ asmap_path = GetDataDir() / asmap_path;
+ }
+ if (!fs::exists(asmap_path)) {
+ InitError(strprintf(_("Could not find asmap file %s").translated, asmap_path));
+ return false;
+ }
+ std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
+ if (asmap.size() == 0) {
+ InitError(strprintf(_("Could not parse asmap file %s").translated, 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
g_zmq_notification_interface = CZMQNotificationInterface::Create();
@@ -1825,31 +1850,6 @@ bool AppInitMain(NodeContext& node)
return false;
}
- // Read asmap file if configured
- if (gArgs.IsArgSet("-asmap")) {
- fs::path asmap_path = fs::path(gArgs.GetArg("-asmap", ""));
- if (asmap_path.empty()) {
- asmap_path = DEFAULT_ASMAP_FILENAME;
- }
- if (!asmap_path.is_absolute()) {
- asmap_path = GetDataDir() / asmap_path;
- }
- if (!fs::exists(asmap_path)) {
- InitError(strprintf(_("Could not find asmap file %s").translated, asmap_path));
- return false;
- }
- std::vector<bool> asmap = CAddrMan::DecodeAsmap(asmap_path);
- if (asmap.size() == 0) {
- InitError(strprintf(_("Could not parse asmap file %s").translated, 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");
- }
-
// ********************************************************* Step 13: finished
SetRPCWarmupFinished();