Skip to content

Commit e2f0548

Browse files
committed
Use addrv2 serialization in anchors.dat
1 parent 8cd8f37 commit e2f0548

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/addrdb.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool SerializeDB(Stream& stream, const Data& data)
2323
{
2424
// Write and commit header, data
2525
try {
26-
CHashWriter hasher(SER_DISK, CLIENT_VERSION);
26+
CHashWriter hasher(stream.GetType(), stream.GetVersion());
2727
stream << Params().MessageStart() << data;
2828
hasher << Params().MessageStart() << data;
2929
stream << hasher.GetHash();
@@ -35,7 +35,7 @@ bool SerializeDB(Stream& stream, const Data& data)
3535
}
3636

3737
template <typename Data>
38-
bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data)
38+
bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data, int version)
3939
{
4040
// Generate random temporary filename
4141
uint16_t randv = 0;
@@ -45,7 +45,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
4545
// open temp output file, and associate with CAutoFile
4646
fs::path pathTmp = gArgs.GetDataDirNet() / tmpfn;
4747
FILE *file = fsbridge::fopen(pathTmp, "wb");
48-
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
48+
CAutoFile fileout(file, SER_DISK, version);
4949
if (fileout.IsNull()) {
5050
fileout.fclose();
5151
remove(pathTmp);
@@ -106,11 +106,11 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
106106
}
107107

108108
template <typename Data>
109-
bool DeserializeFileDB(const fs::path& path, Data& data)
109+
bool DeserializeFileDB(const fs::path& path, Data& data, int version)
110110
{
111111
// open input file, and associate with CAutoFile
112112
FILE* file = fsbridge::fopen(path, "rb");
113-
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
113+
CAutoFile filein(file, SER_DISK, version);
114114
if (filein.IsNull()) {
115115
LogPrintf("Missing or invalid file %s\n", path.string());
116116
return false;
@@ -125,12 +125,12 @@ CBanDB::CBanDB(fs::path ban_list_path) : m_ban_list_path(std::move(ban_list_path
125125

126126
bool CBanDB::Write(const banmap_t& banSet)
127127
{
128-
return SerializeFileDB("banlist", m_ban_list_path, banSet);
128+
return SerializeFileDB("banlist", m_ban_list_path, banSet, CLIENT_VERSION);
129129
}
130130

131131
bool CBanDB::Read(banmap_t& banSet)
132132
{
133-
return DeserializeFileDB(m_ban_list_path, banSet);
133+
return DeserializeFileDB(m_ban_list_path, banSet, CLIENT_VERSION);
134134
}
135135

136136
CAddrDB::CAddrDB()
@@ -140,12 +140,12 @@ CAddrDB::CAddrDB()
140140

141141
bool CAddrDB::Write(const CAddrMan& addr)
142142
{
143-
return SerializeFileDB("peers", pathAddr, addr);
143+
return SerializeFileDB("peers", pathAddr, addr, CLIENT_VERSION);
144144
}
145145

146146
bool CAddrDB::Read(CAddrMan& addr)
147147
{
148-
return DeserializeFileDB(pathAddr, addr);
148+
return DeserializeFileDB(pathAddr, addr, CLIENT_VERSION);
149149
}
150150

151151
bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
@@ -161,13 +161,13 @@ bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
161161
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
162162
{
163163
LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size()));
164-
SerializeFileDB("anchors", anchors_db_path, anchors);
164+
SerializeFileDB("anchors", anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT);
165165
}
166166

167167
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path)
168168
{
169169
std::vector<CAddress> anchors;
170-
if (DeserializeFileDB(anchors_db_path, anchors)) {
170+
if (DeserializeFileDB(anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT)) {
171171
LogPrintf("Loaded %i addresses from %s\n", anchors.size(), anchors_db_path.filename());
172172
} else {
173173
anchors.clear();

0 commit comments

Comments
 (0)