Skip to content

Commit 1e9d367

Browse files
committed
Merge bitcoin/bitcoin#28423: kernel: Remove protocol.h/netaddress.h/compat.h from kernel headers
d506765 [refactor] Remove compat.h from kernel headers (TheCharlatan) 36193af [refactor] Remove netaddress.h from kernel headers (TheCharlatan) 2b08c55 [refactor] Add CChainParams member to CConnman (TheCharlatan) f0d1d8b [refactor] Add missing includes for next commit (TheCharlatan) 534b314 kernel: Move MessageStartChars to its own file (TheCharlatan) 9be330b [refactor] Define MessageStartChars as std::array (TheCharlatan) 37e2b01 [refactor] Allow std::array<std::byte, N> in serialize.h (MarcoFalke) Pull request description: This removes the non-consensus critical `protocol.h` and `netaddress.h` headers from the kernel headers. With this patch, they are no longer required to include in order to use the libbitcoinkernel library. This also allows for the removal of the `compat.h` header from the kernel headers. As an added future benefit it also reduces the number of of kernel headers that include the platform specific `bitcoin-config.h`. For those interested, the currently required kernel headers can be inspected visually with the [sourcetrail](https://github.com/CoatiSoftware/Sourcetrail) tool by looking at the required includes of `bitcoin-chainstate.cpp`. --- This is part of the [libbitcoinkernel project](bitcoin/bitcoin#27587), namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel. ACKs for top commit: stickies-v: re-ACK d506765 hebasto: ACK d506765. ajtowns: utACK d506765 MarcoFalke: lgtm ACK d506765 🍛 Tree-SHA512: 6f90ea510a302c2927e84d16900e89997c39b8ff3ce9d4effeb8a134bd29cc52bd9e81e51aaa11f7496bad00025b78a58b88c5a9e0bb3f4ebbe9a76309215fb7
2 parents 744e0e3 + d506765 commit 1e9d367

31 files changed

+90
-53
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ 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-
unsigned char pchMsgTmp[4];
93+
MessageStartChars pchMsgTmp;
9494
verifier >> pchMsgTmp;
9595
// ... verify the network matches ours
96-
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
96+
if (pchMsgTmp != Params().MessageStart()) {
9797
throw std::runtime_error{"Invalid network magic number"};
9898
}
9999

src/bench/block_assemble.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <consensus/validation.h>
77
#include <crypto/sha256.h>
88
#include <node/miner.h>
9+
#include <random.h>
910
#include <test/util/mining.h>
1011
#include <test/util/script.h>
1112
#include <test/util/setup_common.h>

src/bench/duplicate_inputs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <consensus/merkle.h>
88
#include <consensus/validation.h>
99
#include <pow.h>
10+
#include <random.h>
1011
#include <test/util/setup_common.h>
1112
#include <txmempool.h>
1213
#include <validation.h>

src/bench/mempool_stress.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <bench/bench.h>
66
#include <kernel/mempool_entry.h>
77
#include <policy/policy.h>
8+
#include <random.h>
89
#include <test/util/setup_common.h>
910
#include <txmempool.h>
1011
#include <util/chaintype.h>

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <node/blockstorage.h>
2323
#include <node/caches.h>
2424
#include <node/chainstate.h>
25+
#include <random.h>
2526
#include <scheduler.h>
2627
#include <script/sigcache.h>
2728
#include <util/chaintype.h>

src/bitcoin-util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <core_io.h>
1818
#include <streams.h>
1919
#include <util/exception.h>
20+
#include <util/strencodings.h>
2021
#include <util/translation.h>
2122
#include <version.h>
2223

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12231223
assert(!node.connman);
12241224
node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
12251225
GetRand<uint64_t>(),
1226-
*node.addrman, *node.netgroupman, args.GetBoolArg("-networkactive", true));
1226+
*node.addrman, *node.netgroupman, chainparams, args.GetBoolArg("-networkactive", true));
12271227

12281228
assert(!node.fee_estimator);
12291229
// Don't initialize fee estimation with old data if we don't relay transactions,

src/kernel/chainparams.cpp

Lines changed: 2 additions & 1 deletion
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>
@@ -359,7 +360,7 @@ class SigNetParams : public CChainParams {
359360
HashWriter h{};
360361
h << consensus.signet_challenge;
361362
uint256 hash = h.GetHash();
362-
memcpy(pchMessageStart, hash.begin(), 4);
363+
std::copy_n(hash.begin(), 4, pchMessageStart.begin());
363364

364365
nDefaultPort = 38333;
365366
nPruneAfterHeight = 1000;

src/kernel/chainparams.h

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

99
#include <consensus/params.h>
10-
#include <netaddress.h>
10+
#include <kernel/messagestartchars.h>
1111
#include <primitives/block.h>
12-
#include <protocol.h>
1312
#include <uint256.h>
1413
#include <util/chaintype.h>
1514
#include <util/hash_type.h>
@@ -87,17 +86,8 @@ class CChainParams
8786
};
8887

8988
const Consensus::Params& GetConsensus() const { return consensus; }
90-
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
89+
const MessageStartChars& MessageStart() const { return pchMessageStart; }
9190
uint16_t GetDefaultPort() const { return nDefaultPort; }
92-
uint16_t GetDefaultPort(Network net) const
93-
{
94-
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
95-
}
96-
uint16_t GetDefaultPort(const std::string& addr) const
97-
{
98-
CNetAddr a;
99-
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
100-
}
10191

10292
const CBlock& GenesisBlock() const { return genesis; }
10393
/** Default value for -checkmempool and -checkblockindex argument */
@@ -165,7 +155,7 @@ class CChainParams
165155
CChainParams() {}
166156

167157
Consensus::Params consensus;
168-
CMessageHeader::MessageStartChars pchMessageStart;
158+
MessageStartChars pchMessageStart;
169159
uint16_t nDefaultPort;
170160
uint64_t nPruneAfterHeight;
171161
uint64_t m_assumed_blockchain_size;

0 commit comments

Comments
 (0)