Skip to content

Commit

Permalink
Merge bitcoin#28451: refactor: Remove unused SER_DISK, SER_NETWORK, C…
Browse files Browse the repository at this point in the history
…DataStream

fa98a09 Rename version.h to node/protocol_version.h (MarcoFalke)
fa4fbd5 Remove unused version.h include (MarcoFalke)
fa0ae22 Remove unused SER_NETWORK, SER_DISK (MarcoFalke)
fae00fe Remove unused CDataStream (MarcoFalke)
fa7eb4f fuzz: Drop unused version from fuzz input format (MarcoFalke)

Pull request description:

  Seems odd to have code that is completely dead.

  Fix this by removing all of it.

ACKs for top commit:
  sipa:
    utACK fa98a09
  ajtowns:
    ACK fa98a09
  ryanofsky:
    Seems odd to not code review ACK fa98a09 (looks good)

Tree-SHA512: 9f1b9d9f92bda0512610bda6653e892756f637860362a9abfa439faab62de233cbad94b7df78ebacc160d9667aadfed4d9df08c0edefa618c040a049050fb913
  • Loading branch information
ryanofsky committed Nov 30, 2023
2 parents cdb7723 + fa98a09 commit ffb0216
Show file tree
Hide file tree
Showing 38 changed files with 69 additions and 138 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ BITCOIN_CORE_H = \
node/mini_miner.h \
node/minisketchwrapper.h \
node/peerman_args.h \
node/protocol_version.h \
node/psbt.h \
node/transaction.h \
node/txreconciliation.h \
Expand Down Expand Up @@ -658,8 +659,7 @@ libbitcoin_consensus_a_SOURCES = \
uint256.cpp \
uint256.h \
util/strencodings.cpp \
util/strencodings.h \
version.h
util/strencodings.h
#

# common #
Expand Down
2 changes: 1 addition & 1 deletion src/bench/rpc_blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct TestBlockAndIndex {

TestBlockAndIndex()
{
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
DataStream stream{benchmark::data::block413567};
std::byte a{0};
stream.write({&a, 1}); // Prevent compaction

Expand Down
1 change: 0 additions & 1 deletion src/external_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <core_io.h>
#include <psbt.h>
#include <util/strencodings.h>
#include <version.h>

#include <algorithm>
#include <stdexcept>
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <netbase.h>
#include <netgroup.h>
#include <node/connection_types.h>
#include <node/protocol_version.h>
#include <policy/feerate.h>
#include <protocol.h>
#include <random.h>
Expand All @@ -30,7 +31,6 @@
#include <util/check.h>
#include <util/sock.h>
#include <util/threadinterrupt.h>
#include <version.h>

#include <atomic>
#include <condition_variable>
Expand Down
8 changes: 4 additions & 4 deletions src/version.h → src/node/protocol_version.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2012-2020 The Bitcoin Core developers
// Copyright (c) 2012-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_VERSION_H
#define BITCOIN_VERSION_H
#ifndef BITCOIN_NODE_PROTOCOL_VERSION_H
#define BITCOIN_NODE_PROTOCOL_VERSION_H

/**
* network protocol versioning
Expand Down Expand Up @@ -35,4 +35,4 @@ static const int INVALID_CB_NO_BAN_VERSION = 70015;
//! "wtxidrelay" command for wtxid-based relay starts with this version
static const int WTXID_RELAY_VERSION = 70016;

#endif // BITCOIN_VERSION_H
#endif // BITCOIN_NODE_PROTOCOL_VERSION_H
3 changes: 1 addition & 2 deletions src/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <script/signingprovider.h>
#include <util/check.h>
#include <util/strencodings.h>
#include <version.h>


PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx)
Expand Down Expand Up @@ -546,7 +545,7 @@ bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base6

bool DecodeRawPSBT(PartiallySignedTransaction& psbt, Span<const std::byte> tx_data, std::string& error)
{
CDataStream ss_data(tx_data, SER_NETWORK, PROTOCOL_VERSION);
DataStream ss_data{tx_data};
try {
ss_data >> psbt;
if (!ss_data.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <net_types.h> // For banmap_t
#include <netbase.h>
#include <node/context.h>
#include <node/protocol_version.h>
#include <policy/settings.h>
#include <protocol.h>
#include <rpc/blockchain.h>
Expand All @@ -29,7 +30,6 @@
#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
#include <version.h>
#include <warnings.h>

#include <optional>
Expand Down
1 change: 0 additions & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <util/vector.h>
#include <validation.h>
#include <validationinterface.h>
#include <version.h>

#include <numeric>
#include <stdint.h>
Expand Down
16 changes: 3 additions & 13 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,8 @@ template<typename Stream> inline uint64_t ser_readdata64(Stream &s)
}


/////////////////////////////////////////////////////////////////
//
// Templates for serializing to anything that looks like a stream,
// i.e. anything that supports .read(Span<std::byte>) and .write(Span<const std::byte>)
//

class SizeComputer;

enum
{
// primary actions
SER_NETWORK = (1 << 0),
SER_DISK = (1 << 1),
};

/**
* Convert any argument to a reference to X, maintaining constness.
*
Expand Down Expand Up @@ -268,6 +255,9 @@ const Out& AsBase(const In& x)
BASE_SERIALIZE_METHODS(cls) \
FORMATTER_METHODS_PARAMS(cls, obj, paramcls, paramobj)

// Templates for serializing to anything that looks like a stream,
// i.e. anything that supports .read(Span<std::byte>) and .write(Span<const std::byte>)
//
// clang-format off
#ifndef CHAR_EQUALS_INT8
template <typename Stream> void Serialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t
Expand Down
36 changes: 0 additions & 36 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,42 +279,6 @@ class DataStream
}
};

class CDataStream : public DataStream
{
private:
int nType;
int nVersion;

public:
explicit CDataStream(int nTypeIn, int nVersionIn)
: nType{nTypeIn},
nVersion{nVersionIn} {}

explicit CDataStream(Span<const uint8_t> sp, int type, int version) : CDataStream{AsBytes(sp), type, version} {}
explicit CDataStream(Span<const value_type> sp, int nTypeIn, int nVersionIn)
: DataStream{sp},
nType{nTypeIn},
nVersion{nVersionIn} {}

int GetType() const { return nType; }
void SetVersion(int n) { nVersion = n; }
int GetVersion() const { return nVersion; }

template <typename T>
CDataStream& operator<<(const T& obj)
{
::Serialize(*this, obj);
return *this;
}

template <typename T>
CDataStream& operator>>(T&& obj)
{
::Unserialize(*this, obj);
return *this;
}
};

template <typename IStream>
class BitStreamReader
{
Expand Down
Loading

0 comments on commit ffb0216

Please sign in to comment.