I think this will not deserialize properly anchors.dat
from before this PR.
CLIENT_VERSION
is something like 219900
ADDRV2_FORMAT
is 0x20000000
In anchors.dat
before this PR we have CAddress
entries which contain version=219900
and addresses serialized in addrv1 format.
With this PR we will set the stream version to ADDRV2_FORMAT
during deserialize:
0 // Notice added comments below
1 SERIALIZE_METHODS(CAddress, obj)
2 {
3 SER_READ(obj, obj.nTime = TIME_INIT);
4 int nVersion = s.GetVersion(); // nVersion will be assigned ADDRV2_FORMAT (0x20000000)
5 if (s.GetType() & SER_DISK) {
6 READWRITE(nVersion); // nVersion will be assigned CLIENT_VERSION (219900)
7 }
8...
9 if (nVersion & ADDRV2_FORMAT) { // this will be false
10 uint64_t services_tmp;
11 SER_WRITE(obj, services_tmp = obj.nServices);
12 READWRITE(Using<CompactSizeFormatter<false>>(services_tmp));
13 SER_READ(obj, obj.nServices = static_cast<ServiceFlags>(services_tmp));
14 } else {
15 // it will read services as 8 bytes (correct, as that is what is actually stored on disk)
16 READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
17 }
18 // oops, this will deserialize CService, which will deserialize CNetAddr which will check
19 // s.GetVersion() which is ADDRV2_FORMAT (0x20000000) and will deserialize the
20 // address as if it is stored in addrv2 format on disk, but it is actually stored in addrv1,
21 // so this will deserialize garbage
22 READWRITEAS(CService, obj);
23 }