aboutsummaryrefslogtreecommitdiff
path: root/src/addrdb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2020-11-26 16:46:10 -0800
committerPieter Wuille <pieter@wuille.net>2021-05-24 18:06:31 -0700
commit8cd8f37dfe3ffb73a09f3ad773603d9d89452245 (patch)
tree815e6a873753f17cf6a7e7bdad563d4ef220ed52 /src/addrdb.cpp
parentb295395664bd37e26d168c329f238237b34aef8c (diff)
downloadbitcoin-8cd8f37dfe3ffb73a09f3ad773603d9d89452245.tar.xz
Introduce well-defined CAddress disk serialization
Before this commit, CAddress disk serialization was messy. It stored CLIENT_VERSION in the first 4 bytes, optionally OR'ed with ADDRV2_FORMAT. - All bits except ADDRV2_FORMAT were ignored, making it hard to use for actual future format changes. - ADDRV2_FORMAT determines whether or not nServices is serialized in LE64 format or in CompactSize format. - Whether or not the embedded CService is serialized in V1 or V2 format is determined by the stream's version having ADDRV2_FORMAT (as opposed to the nServices encoding, which is determined by the disk version). To improve the situation, this commit introduces the following disk serialization format, compatible with earlier versions, but better defined for future changes: - The first 4 bytes store a format version number. Its low 19 bits are ignored (as it historically stored the CLIENT_VERSION), but its high 13 bits specify the serialization exactly: - 0x00000000: LE64 encoding for nServices, V1 encoding for CService - 0x20000000: CompactSize encoding for nServices, V2 encoding for CService - Any other value triggers an unsupported format error on deserialization, and can be used for future format changes. - The ADDRV2_FORMAT flag in the stream's version does not impact the actual serialization format; it only determines whether V2 encoding is permitted; whether it's actually enabled depends solely on the disk version number. Operationally the changes to the deserializer are: - Failure when the stored format version number is unexpected. - The embedded CService's format is determined by the stored format version number rather than the stream's version number. These do no introduce incompatibilities, as no code versions exist that write any value other than 0 or 0x20000000 in the top 13 bits, and no code paths where the stream's version differs from the stored version.
Diffstat (limited to 'src/addrdb.cpp')
0 files changed, 0 insertions, 0 deletions