@@ -23,7 +23,7 @@ bool SerializeDB(Stream& stream, const Data& data)
23
23
{
24
24
// Write and commit header, data
25
25
try {
26
- CHashWriter hasher (SER_DISK, CLIENT_VERSION );
26
+ CHashWriter hasher (stream. GetType (), stream. GetVersion () );
27
27
stream << Params ().MessageStart () << data;
28
28
hasher << Params ().MessageStart () << data;
29
29
stream << hasher.GetHash ();
@@ -35,7 +35,7 @@ bool SerializeDB(Stream& stream, const Data& data)
35
35
}
36
36
37
37
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 )
39
39
{
40
40
// Generate random temporary filename
41
41
uint16_t randv = 0 ;
@@ -45,7 +45,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
45
45
// open temp output file, and associate with CAutoFile
46
46
fs::path pathTmp = gArgs .GetDataDirNet () / tmpfn;
47
47
FILE *file = fsbridge::fopen (pathTmp, " wb" );
48
- CAutoFile fileout (file, SER_DISK, CLIENT_VERSION );
48
+ CAutoFile fileout (file, SER_DISK, version );
49
49
if (fileout.IsNull ()) {
50
50
fileout.fclose ();
51
51
remove (pathTmp);
@@ -106,11 +106,11 @@ bool DeserializeDB(Stream& stream, Data& data, bool fCheckSum = true)
106
106
}
107
107
108
108
template <typename Data>
109
- bool DeserializeFileDB (const fs::path& path, Data& data)
109
+ bool DeserializeFileDB (const fs::path& path, Data& data, int version )
110
110
{
111
111
// open input file, and associate with CAutoFile
112
112
FILE* file = fsbridge::fopen (path, " rb" );
113
- CAutoFile filein (file, SER_DISK, CLIENT_VERSION );
113
+ CAutoFile filein (file, SER_DISK, version );
114
114
if (filein.IsNull ()) {
115
115
LogPrintf (" Missing or invalid file %s\n " , path.string ());
116
116
return false ;
@@ -125,12 +125,12 @@ CBanDB::CBanDB(fs::path ban_list_path) : m_ban_list_path(std::move(ban_list_path
125
125
126
126
bool CBanDB::Write (const banmap_t & banSet)
127
127
{
128
- return SerializeFileDB (" banlist" , m_ban_list_path, banSet);
128
+ return SerializeFileDB (" banlist" , m_ban_list_path, banSet, CLIENT_VERSION );
129
129
}
130
130
131
131
bool CBanDB::Read (banmap_t & banSet)
132
132
{
133
- return DeserializeFileDB (m_ban_list_path, banSet);
133
+ return DeserializeFileDB (m_ban_list_path, banSet, CLIENT_VERSION );
134
134
}
135
135
136
136
CAddrDB::CAddrDB ()
@@ -140,12 +140,12 @@ CAddrDB::CAddrDB()
140
140
141
141
bool CAddrDB::Write (const CAddrMan& addr)
142
142
{
143
- return SerializeFileDB (" peers" , pathAddr, addr);
143
+ return SerializeFileDB (" peers" , pathAddr, addr, CLIENT_VERSION );
144
144
}
145
145
146
146
bool CAddrDB::Read (CAddrMan& addr)
147
147
{
148
- return DeserializeFileDB (pathAddr, addr);
148
+ return DeserializeFileDB (pathAddr, addr, CLIENT_VERSION );
149
149
}
150
150
151
151
bool CAddrDB::Read (CAddrMan& addr, CDataStream& ssPeers)
@@ -161,13 +161,13 @@ bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
161
161
void DumpAnchors (const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
162
162
{
163
163
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 );
165
165
}
166
166
167
167
std::vector<CAddress> ReadAnchors (const fs::path& anchors_db_path)
168
168
{
169
169
std::vector<CAddress> anchors;
170
- if (DeserializeFileDB (anchors_db_path, anchors)) {
170
+ if (DeserializeFileDB (anchors_db_path, anchors, CLIENT_VERSION | ADDRV2_FORMAT )) {
171
171
LogPrintf (" Loaded %i addresses from %s\n " , anchors.size (), anchors_db_path.filename ());
172
172
} else {
173
173
anchors.clear ();
0 commit comments