Skip to content

Commit e8e7392

Browse files
committed
[addrman] Don't call Clear() if parsing peers.dat fails
Now that we manage the lifespan of node.addrman, we can just reset node.addrman to a newly initialized CAddrMan if parsing peers.dat fails, eliminating the possibility that Clear() leaves some old state behind.
1 parent 181a120 commit e8e7392

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
11751175
if (adb.Read(*node.addrman)) {
11761176
LogPrintf("Loaded %i addresses from peers.dat %dms\n", node.addrman->size(), GetTimeMillis() - nStart);
11771177
} else {
1178-
node.addrman->Clear(); // Addrman can be in an inconsistent state after failure, reset it
1178+
// Addrman can be in an inconsistent state after failure, reset it
1179+
node.addrman = std::make_unique<CAddrMan>(/* deterministic */ false, /* consistency_check_ratio */ check_addrman);
11791180
LogPrintf("Recreating peers.dat\n");
11801181
adb.Write(*node.addrman);
11811182
}

0 commit comments

Comments
 (0)