aboutsummaryrefslogtreecommitdiff
path: root/src/addrdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/addrdb.cpp')
-rw-r--r--src/addrdb.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/addrdb.cpp b/src/addrdb.cpp
index 856f318961..fd85e717e3 100644
--- a/src/addrdb.cpp
+++ b/src/addrdb.cpp
@@ -18,6 +18,7 @@
#include <univalue.h>
#include <util/settings.h>
#include <util/system.h>
+#include <util/translation.h>
namespace {
template <typename Stream, typename Data>
@@ -187,6 +188,23 @@ bool ReadFromStream(CAddrMan& addr, CDataStream& ssPeers)
return DeserializeDB(ssPeers, addr, false);
}
+std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<CAddrMan>& addrman)
+{
+ auto check_addrman = std::clamp<int32_t>(args.GetArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
+ addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
+
+ int64_t nStart = GetTimeMillis();
+ if (ReadPeerAddresses(args, *addrman)) {
+ LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart);
+ } else {
+ // Addrman can be in an inconsistent state after failure, reset it
+ addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
+ LogPrintf("Recreating peers.dat\n");
+ DumpPeerAddresses(args, *addrman);
+ }
+ return std::nullopt;
+}
+
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
{
LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size()));