aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-08-05 11:09:55 +0100
committerJohn Newbery <john@johnnewbery.com>2021-08-18 14:00:52 +0100
commit181a1207ba6bd179d181f3e2534ef8676565ce72 (patch)
tree3732dfba53c61dfd09383a18ff86325e593394eb /src/init.cpp
parente35c4a3d80578e8feff1f1ae5db81d3c0992a865 (diff)
[addrman] Move peers.dat parsing to init.cpp
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 9154fc0a6f..2ca6cebee7 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1167,6 +1167,19 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
assert(!node.addrman);
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);
+ {
+ // Load addresses from peers.dat
+ uiInterface.InitMessage(_("Loading P2P addresses…").translated);
+ int64_t nStart = GetTimeMillis();
+ CAddrDB adb;
+ if (adb.Read(*node.addrman)) {
+ LogPrintf("Loaded %i addresses from peers.dat %dms\n", node.addrman->size(), GetTimeMillis() - nStart);
+ } else {
+ node.addrman->Clear(); // Addrman can be in an inconsistent state after failure, reset it
+ LogPrintf("Recreating peers.dat\n");
+ adb.Write(*node.addrman);
+ }
+ }
assert(!node.banman);
node.banman = std::make_unique<BanMan>(gArgs.GetDataDirNet() / "banlist", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!node.connman);