| 182 | } |
| 183 | |
| 184 | std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman) |
| 185 | { |
| 186 | auto check_addrman = std::clamp<int32_t>(args.GetIntArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000); |
| 187 | addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman); |
| 188 | |
| 189 | int64_t nStart = GetTimeMillis(); |
| 190 | const auto path_addr{args.GetDataDirNet() / "peers.dat"}; |
| 191 | try { |
| 192 | DeserializeFileDB(path_addr, *addrman, CLIENT_VERSION); |
| 193 | LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart); |
| 194 | } catch (const DbNotFoundError&) { |
| 195 | // Addrman can be in an inconsistent state after failure, reset it |
| 196 | addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman); |
| 197 | LogPrintf("Creating peers.dat because the file was not found (%s)\n", fs::quoted(fs::PathToString(path_addr))); |
| 198 | DumpPeerAddresses(args, *addrman); |
| 199 | } catch (const InvalidAddrManVersionError&) { |
| 200 | if (!RenameOver(path_addr, (fs::path)path_addr + ".bak")) { |
| 201 | addrman = nullptr; |
| 202 | return strprintf(_("Failed to rename invalid peers.dat file. Please move or delete it and try again.")); |
| 203 | } |
| 204 | // Addrman can be in an inconsistent state after failure, reset it |
| 205 | addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman); |
| 206 | LogPrintf("Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr))); |
| 207 | DumpPeerAddresses(args, *addrman); |
| 208 | } catch (const std::exception& e) { |
| 209 | addrman = nullptr; |
| 210 | return strprintf(_("Invalid or corrupt peers.dat (%s). If you believe this is a bug, please report it to %s. As a workaround, you can move the file (%s) out of the way (rename, move, or delete) to have a new one created on the next start."), |
| 211 | e.what(), PACKAGE_BUGREPORT, fs::quoted(fs::PathToString(path_addr))); |
| 212 | } |
| 213 | return std::nullopt; |
| 214 | } |
| 215 | |
| 216 | void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors) |
| 217 | { |
no test coverage detected