Skip to content

Commit 579c49b

Browse files
committed
Merge bitcoin/bitcoin#28428: Hard-code version number value for CBlockLocator and CDiskBlockIndex
e73d2a8 refactor: remove clientversion include from dbwrapper.h (Cory Fields) 4240a08 refactor: Use DataStream now that version/type are unused (Cory Fields) f15f790 Remove version/hashing options from CBlockLocator/CDiskBlockIndex (Cory Fields) Pull request description: This is also a much simpler replacement for #28327. There are version fields in `CBlockLocator` and `CDiskBlockIndex` that have always been written but discarded when read. I intended to convert them to use SerParams as introduced by #25284, which [ended up looking like this](theuni/bitcoin@3e3af45). However because we don't currently have any definition of what a hash value would mean for either one of those, and we've never assigned the version field any meaning, I think it's better to just not worry about them. If we ever need to assign meaning in the future, we can introduce `SerParams` as was done for `CAddress`. As for the dummy values chosen: `CDiskBlockIndex::DUMMY_VERSION` was easy as the highest ever client version, and I don't expect any objection there. `CBlockLocator::DUMMY_VERSION` is hard-coded to the higest _PROTOCOL_ version ever used. This is to avoid a sudden bump that would be visible on the network if CLIENT_VERSION were used instead. In the future, if we ever need to use the value, we can discard anything in the CLIENT_VERSION range (for a few years as needed), as it's quite a bit higher. While reviewing, I suggest looking at the throwaway `SerParams` commit above as it shows where the call-sites are. I believe that should be enough to convince one's self that hashing is never used. ACKs for top commit: TheCharlatan: Re-ACK e73d2a8 ajtowns: reACK e73d2a8 Tree-SHA512: 45b0dd7c2e918493e2ee92a8e35320ad17991cb8908cb811150a96c5fd584ce177c775baeeb8675a602c90b9ba9203b8cefc0a2a0c6a71078b1d9c2b41e1f3ba
2 parents 4e1a38c + e73d2a8 commit 579c49b

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

src/chain.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex*
388388
/** Used to marshal pointers into hashes for db storage. */
389389
class CDiskBlockIndex : public CBlockIndex
390390
{
391+
/** Historically CBlockLocator's version field has been written to disk
392+
* streams as the client version, but the value has never been used.
393+
*
394+
* Hard-code to the highest client version ever written.
395+
* SerParams can be used if the field requires any meaning in the future.
396+
**/
397+
static constexpr int DUMMY_VERSION = 259900;
398+
391399
public:
392400
uint256 hashPrev;
393401

@@ -404,8 +412,8 @@ class CDiskBlockIndex : public CBlockIndex
404412
SERIALIZE_METHODS(CDiskBlockIndex, obj)
405413
{
406414
LOCK(::cs_main);
407-
int _nVersion = s.GetVersion();
408-
if (!(s.GetType() & SER_GETHASH)) READWRITE(VARINT_MODE(_nVersion, VarIntMode::NONNEGATIVE_SIGNED));
415+
int _nVersion = DUMMY_VERSION;
416+
READWRITE(VARINT_MODE(_nVersion, VarIntMode::NONNEGATIVE_SIGNED));
409417

410418
READWRITE(VARINT_MODE(obj.nHeight, VarIntMode::NONNEGATIVE_SIGNED));
411419
READWRITE(VARINT(obj.nStatus));

src/dbwrapper.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_DBWRAPPER_H
77

88
#include <attributes.h>
9-
#include <clientversion.h>
109
#include <serialize.h>
1110
#include <span.h>
1211
#include <streams.h>
@@ -167,7 +166,7 @@ class CDBIterator
167166

168167
template<typename V> bool GetValue(V& value) {
169168
try {
170-
CDataStream ssValue{GetValueImpl(), SER_DISK, CLIENT_VERSION};
169+
DataStream ssValue{GetValueImpl()};
171170
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
172171
ssValue >> value;
173172
} catch (const std::exception&) {
@@ -229,7 +228,7 @@ class CDBWrapper
229228
return false;
230229
}
231230
try {
232-
CDataStream ssValue{MakeByteSpan(*strValue), SER_DISK, CLIENT_VERSION};
231+
DataStream ssValue{MakeByteSpan(*strValue)};
233232
ssValue.Xor(obfuscate_key);
234233
ssValue >> value;
235234
} catch (const std::exception&) {

src/index/blockfilterindex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <map>
66

7+
#include <clientversion.h>
78
#include <common/args.h>
89
#include <dbwrapper.h>
910
#include <hash.h>

src/index/txindex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <index/txindex.h>
66

7+
#include <clientversion.h>
78
#include <common/args.h>
89
#include <index/disktxpos.h>
910
#include <logging.h>

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <chain.h>
2020
#include <chainparams.h>
2121
#include <chainparamsbase.h>
22+
#include <clientversion.h>
2223
#include <common/args.h>
2324
#include <common/system.h>
2425
#include <consensus/amount.h>

src/primitives/block.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ class CBlock : public CBlockHeader
118118
*/
119119
struct CBlockLocator
120120
{
121+
/** Historically CBlockLocator's version field has been written to network
122+
* streams as the negotiated protocol version and to disk streams as the
123+
* client version, but the value has never been used.
124+
*
125+
* Hard-code to the highest protocol version ever written to a network stream.
126+
* SerParams can be used if the field requires any meaning in the future,
127+
**/
128+
static constexpr int DUMMY_VERSION = 70016;
129+
121130
std::vector<uint256> vHave;
122131

123132
CBlockLocator() {}
@@ -126,9 +135,8 @@ struct CBlockLocator
126135

127136
SERIALIZE_METHODS(CBlockLocator, obj)
128137
{
129-
int nVersion = s.GetVersion();
130-
if (!(s.GetType() & SER_GETHASH))
131-
READWRITE(nVersion);
138+
int nVersion = DUMMY_VERSION;
139+
READWRITE(nVersion);
132140
READWRITE(obj.vHave);
133141
}
134142

src/test/blockmanager_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <chainparams.h>
6+
#include <clientversion.h>
67
#include <node/blockstorage.h>
78
#include <node/context.h>
89
#include <node/kernel_notifications.h>

src/validation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <arith_uint256.h>
1212
#include <chain.h>
1313
#include <checkqueue.h>
14+
#include <clientversion.h>
1415
#include <consensus/amount.h>
1516
#include <consensus/consensus.h>
1617
#include <consensus/merkle.h>

0 commit comments

Comments
 (0)