From f15f790618d328abd207d55e6291229eb2a8643f Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 7 Sep 2023 15:20:24 +0000 Subject: [PATCH 1/3] 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 @@ class CDiskBlockIndex : public CBlockIndex 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 @@ class CBlock : public CBlockHeader */ 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); } From 4240a082b81d8ceb7615b1b4ca0d2857382f317b Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 7 Sep 2023 15:37:51 +0000 Subject: [PATCH 2/3] refactor: Use DataStream now that version/type are unused --- src/dbwrapper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index eac9594aa10..44366d00330 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -167,7 +167,7 @@ class CDBIterator template bool GetValue(V& value) { try { - CDataStream ssValue{GetValueImpl(), SER_DISK, CLIENT_VERSION}; + DataStream ssValue{GetValueImpl()}; ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent)); ssValue >> value; } catch (const std::exception&) { @@ -229,7 +229,7 @@ class CDBWrapper return false; } try { - CDataStream ssValue{MakeByteSpan(*strValue), SER_DISK, CLIENT_VERSION}; + DataStream ssValue{MakeByteSpan(*strValue)}; ssValue.Xor(obfuscate_key); ssValue >> value; } catch (const std::exception&) { From e73d2a8018def940afadb5d699b18f39e882c1fc Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 7 Sep 2023 15:39:30 +0000 Subject: [PATCH 3/3] refactor: remove clientversion include from dbwrapper.h --- src/dbwrapper.h | 1 - src/index/blockfilterindex.cpp | 1 + src/index/txindex.cpp | 1 + src/init.cpp | 1 + src/test/blockmanager_tests.cpp | 1 + src/validation.cpp | 1 + 6 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 44366d00330..2f7448e8780 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -6,7 +6,6 @@ #define BITCOIN_DBWRAPPER_H #include -#include #include #include #include diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index b23d66ac1d6..21132d93052 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 2e07a35d0d6..0d4de3a53e7 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include diff --git a/src/init.cpp b/src/init.cpp index 96fec92133d..f0847bd4f75 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index 553bb31ba1f..13cb1cc3140 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include diff --git a/src/validation.cpp b/src/validation.cpp index 0b6327ec558..e3a00e4241e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include