Skip to content

Commit 534b314

Browse files
TheCharlatantheuni
andcommitted
kernel: Move MessageStartChars to its own file
The protocol.h file contains many non-consensus related definitions and should thus not be part of the libbitcoinkernel. This commit makes protocol.h no longer a required include for users of the libbitcoinkernel. This commit is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel. Co-Authored-By: Cory Fields <cory-nospam-@coryfields.com>
1 parent 9be330b commit 534b314

File tree

12 files changed

+31
-13
lines changed

12 files changed

+31
-13
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ BITCOIN_CORE_H = \
191191
kernel/mempool_options.h \
192192
kernel/mempool_persist.h \
193193
kernel/mempool_removal_reason.h \
194+
kernel/messagestartchars.h \
194195
kernel/notifications_interface.h \
195196
kernel/validation_cache_sizes.h \
196197
key.h \

src/addrdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void DeserializeDB(Stream& stream, Data&& data, bool fCheckSum = true)
9090
{
9191
HashVerifier verifier{stream};
9292
// de-serialize file header (network specific magic number) and ..
93-
CMessageHeader::MessageStartChars pchMsgTmp;
93+
MessageStartChars pchMsgTmp;
9494
verifier >> pchMsgTmp;
9595
// ... verify the network matches ours
9696
if (pchMsgTmp != Params().MessageStart()) {

src/kernel/chainparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <consensus/merkle.h>
1111
#include <consensus/params.h>
1212
#include <hash.h>
13+
#include <kernel/messagestartchars.h>
1314
#include <logging.h>
1415
#include <primitives/block.h>
1516
#include <primitives/transaction.h>

src/kernel/chainparams.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#define BITCOIN_KERNEL_CHAINPARAMS_H
88

99
#include <consensus/params.h>
10+
#include <kernel/messagestartchars.h>
1011
#include <netaddress.h>
1112
#include <primitives/block.h>
12-
#include <protocol.h>
1313
#include <uint256.h>
1414
#include <util/chaintype.h>
1515
#include <util/hash_type.h>
@@ -87,7 +87,7 @@ class CChainParams
8787
};
8888

8989
const Consensus::Params& GetConsensus() const { return consensus; }
90-
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
90+
const MessageStartChars& MessageStart() const { return pchMessageStart; }
9191
uint16_t GetDefaultPort() const { return nDefaultPort; }
9292
uint16_t GetDefaultPort(Network net) const
9393
{
@@ -165,7 +165,7 @@ class CChainParams
165165
CChainParams() {}
166166

167167
Consensus::Params consensus;
168-
CMessageHeader::MessageStartChars pchMessageStart;
168+
MessageStartChars pchMessageStart;
169169
uint16_t nDefaultPort;
170170
uint64_t nPruneAfterHeight;
171171
uint64_t m_assumed_blockchain_size;

src/kernel/messagestartchars.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_KERNEL_MESSAGESTARTCHARS_H
6+
#define BITCOIN_KERNEL_MESSAGESTARTCHARS_H
7+
8+
#include <array>
9+
#include <cstdint>
10+
11+
using MessageStartChars = std::array<uint8_t, 4>;
12+
13+
#endif // BITCOIN_KERNEL_MESSAGESTARTCHARS_H

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ bool V2Transport::ProcessReceivedKeyBytes() noexcept
11441144
// they receive our uniformly random key and garbage, but detecting this case specially
11451145
// means we can log it.
11461146
static constexpr std::array<uint8_t, 12> MATCH = {'v', 'e', 'r', 's', 'i', 'o', 'n', 0, 0, 0, 0, 0};
1147-
static constexpr size_t OFFSET = std::tuple_size_v<CMessageHeader::MessageStartChars>;
1147+
static constexpr size_t OFFSET = std::tuple_size_v<MessageStartChars>;
11481148
if (!m_initiating && m_recv_buffer.size() >= OFFSET + MATCH.size()) {
11491149
if (std::equal(MATCH.begin(), MATCH.end(), m_recv_buffer.begin() + OFFSET)) {
11501150
LogPrint(BCLog::NET, "V2 transport error: V1 peer with wrong MessageStart %s\n",

src/net.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
#include <chainparams.h>
1111
#include <common/bloom.h>
1212
#include <compat/compat.h>
13-
#include <node/connection_types.h>
1413
#include <consensus/amount.h>
1514
#include <crypto/siphash.h>
1615
#include <hash.h>
1716
#include <i2p.h>
17+
#include <kernel/messagestartchars.h>
1818
#include <net_permissions.h>
1919
#include <netaddress.h>
2020
#include <netbase.h>
2121
#include <netgroup.h>
22+
#include <node/connection_types.h>
2223
#include <policy/feerate.h>
2324
#include <protocol.h>
2425
#include <random.h>
@@ -360,7 +361,7 @@ class Transport {
360361
class V1Transport final : public Transport
361362
{
362363
private:
363-
CMessageHeader::MessageStartChars m_magic_bytes;
364+
MessageStartChars m_magic_bytes;
364365
const NodeId m_node_id; // Only for logging
365366
mutable Mutex m_recv_mutex; //!< Lock for receive state
366367
mutable CHash256 hasher GUARDED_BY(m_recv_mutex);

src/node/blockstorage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <flatfile.h>
1212
#include <hash.h>
1313
#include <kernel/chainparams.h>
14+
#include <kernel/messagestartchars.h>
1415
#include <logging.h>
1516
#include <pow.h>
1617
#include <reverse_iterator.h>
@@ -927,7 +928,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
927928
}
928929

929930
try {
930-
CMessageHeader::MessageStartChars blk_start;
931+
MessageStartChars blk_start;
931932
unsigned int blk_size;
932933

933934
filein >> blk_start >> blk_size;

src/node/blockstorage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <kernel/blockmanager_opts.h>
1212
#include <kernel/chainparams.h>
1313
#include <kernel/cs_main.h>
14-
#include <protocol.h>
14+
#include <kernel/messagestartchars.h>
1515
#include <sync.h>
1616
#include <util/fs.h>
1717
#include <util/hasher.h>
@@ -73,7 +73,7 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
7373
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
7474

7575
/** Size of header written by WriteBlockToDisk before a serialized CBlock */
76-
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = std::tuple_size_v<CMessageHeader::MessageStartChars> + sizeof(unsigned int);
76+
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = std::tuple_size_v<MessageStartChars> + sizeof(unsigned int);
7777

7878
extern std::atomic_bool fReindex;
7979

src/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_PROTOCOL_H
77
#define BITCOIN_PROTOCOL_H
88

9+
#include <kernel/messagestartchars.h> // IWYU pragma: export
910
#include <netaddress.h>
1011
#include <primitives/transaction.h>
1112
#include <serialize.h>
@@ -27,7 +28,6 @@
2728
class CMessageHeader
2829
{
2930
public:
30-
using MessageStartChars = std::array<uint8_t, 4>;
3131
static constexpr size_t COMMAND_SIZE = 12;
3232
static constexpr size_t MESSAGE_SIZE_SIZE = 4;
3333
static constexpr size_t CHECKSUM_SIZE = 4;

0 commit comments

Comments
 (0)