diff --git a/src/addrdb.cpp b/src/addrdb.cpp index ca2d66570b..27f22826a9 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -163,3 +163,16 @@ void DumpAnchors(const fs::path& anchors_db_path, const std::vector& a LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size())); SerializeFileDB("anchors", anchors_db_path, anchors); } + +std::vector ReadAnchors(const fs::path& anchors_db_path) +{ + std::vector anchors; + if (DeserializeFileDB(anchors_db_path, anchors)) { + LogPrintf("Loaded %i addresses from %s\n", anchors.size(), anchors_db_path.filename()); + } else { + anchors.clear(); + } + + fs::remove(anchors_db_path); + return anchors; +} diff --git a/src/addrdb.h b/src/addrdb.h index 614a0c20e3..4ac0e3e1b5 100644 --- a/src/addrdb.h +++ b/src/addrdb.h @@ -81,4 +81,12 @@ public: */ void DumpAnchors(const fs::path& anchors_db_path, const std::vector& anchors); +/** + * Read the anchor IP address database (anchors.dat) + * + * Deleting anchors.dat is intentional as it avoids renewed peering to anchors after + * an unclean shutdown and thus potential exploitation of the anchor peer policy. + */ +std::vector ReadAnchors(const fs::path& anchors_db_path); + #endif // BITCOIN_ADDRDB_H