From f15f790618d328abd207d55e6291229eb2a8643f Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 7 Sep 2023 15:20:24 +0000 Subject: [PATCH] Remove version/hashing options from CBlockLocator/CDiskBlockIndex --- src/chain.h | 12 ++++++++++-- src/primitives/block.h | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/chain.h b/src/chain.h index 2e1fb37bec0..7806720ce9e 100644 --- a/src/chain.h +++ b/src/chain.h @@ -388,6 +388,14 @@ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex* /** Used to marshal pointers into hashes for db storage. */ class CDiskBlockIndex : public CBlockIndex { + /** Historically CBlockLocator's version field has been written to disk + * streams as the client version, but the value has never been used. + * + * Hard-code to the highest client version ever written. + * SerParams can be used if the field requires any meaning in the future. + **/ + static constexpr int DUMMY_VERSION = 259900; + public: uint256 hashPrev; @@ -404,8 +412,8 @@ public: SERIALIZE_METHODS(CDiskBlockIndex, obj) { LOCK(::cs_main); - int _nVersion = s.GetVersion(); - if (!(s.GetType() & SER_GETHASH)) READWRITE(VARINT_MODE(_nVersion, VarIntMode::NONNEGATIVE_SIGNED)); + int _nVersion = DUMMY_VERSION; + READWRITE(VARINT_MODE(_nVersion, VarIntMode::NONNEGATIVE_SIGNED)); READWRITE(VARINT_MODE(obj.nHeight, VarIntMode::NONNEGATIVE_SIGNED)); READWRITE(VARINT(obj.nStatus)); diff --git a/src/primitives/block.h b/src/primitives/block.h index 861d362414b..99accfc7dd9 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -118,6 +118,15 @@ public: */ struct CBlockLocator { + /** Historically CBlockLocator's version field has been written to network + * streams as the negotiated protocol version and to disk streams as the + * client version, but the value has never been used. + * + * Hard-code to the highest protocol version ever written to a network stream. + * SerParams can be used if the field requires any meaning in the future, + **/ + static constexpr int DUMMY_VERSION = 70016; + std::vector vHave; CBlockLocator() {} @@ -126,9 +135,8 @@ struct CBlockLocator SERIALIZE_METHODS(CBlockLocator, obj) { - int nVersion = s.GetVersion(); - if (!(s.GetType() & SER_GETHASH)) - READWRITE(nVersion); + int nVersion = DUMMY_VERSION; + READWRITE(nVersion); READWRITE(obj.vHave); }