p2p: Avoid InitError when downgrading peers.dat

fixes #24188
When downgrading, a peers.dat with a future version that has a minimum
required version larger than the downgraded version would cause an InitError.

This commit changes this behavior to overwrite the existing peers.dat with
a new empty one, while creating a backup in peers.dat.bak.
This commit is contained in:
junderw
2022-01-29 21:58:59 +09:00
parent 5b4b8f76f3
commit d41ed32153
4 changed files with 24 additions and 10 deletions

View File

@@ -248,7 +248,7 @@ void AddrManImpl::Unserialize(Stream& s_)
s >> compat;
const uint8_t lowest_compatible = compat - INCOMPATIBILITY_BASE;
if (lowest_compatible > FILE_FORMAT) {
throw std::ios_base::failure(strprintf(
throw InvalidAddrManVersionError(strprintf(
"Unsupported format of addrman database: %u. It is compatible with formats >=%u, "
"but the maximum supported by this version of %s is %u.",
uint8_t{format}, uint8_t{lowest_compatible}, PACKAGE_NAME, uint8_t{FILE_FORMAT}));