mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#28423: kernel: Remove protocol.h/netaddress.h/compat.h from kernel headers
d506765199
[refactor] Remove compat.h from kernel headers (TheCharlatan)36193af47c
[refactor] Remove netaddress.h from kernel headers (TheCharlatan)2b08c55f01
[refactor] Add CChainParams member to CConnman (TheCharlatan)f0d1d8b35c
[refactor] Add missing includes for next commit (TheCharlatan)534b314a74
kernel: Move MessageStartChars to its own file (TheCharlatan)9be330b654
[refactor] Define MessageStartChars as std::array (TheCharlatan)37e2b01113
[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](https://github.com/bitcoin/bitcoin/issues/27587), namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel. ACKs for top commit: stickies-v: re-ACKd506765
hebasto: ACKd506765199
. ajtowns: utACKd506765199
MarcoFalke: lgtm ACKd506765199
🍛 Tree-SHA512: 6f90ea510a302c2927e84d16900e89997c39b8ff3ce9d4effeb8a134bd29cc52bd9e81e51aaa11f7496bad00025b78a58b88c5a9e0bb3f4ebbe9a76309215fb7
This commit is contained in:
commit
1e9d367d0d
31 changed files with 90 additions and 53 deletions
|
@ -191,6 +191,7 @@ BITCOIN_CORE_H = \
|
||||||
kernel/mempool_options.h \
|
kernel/mempool_options.h \
|
||||||
kernel/mempool_persist.h \
|
kernel/mempool_persist.h \
|
||||||
kernel/mempool_removal_reason.h \
|
kernel/mempool_removal_reason.h \
|
||||||
|
kernel/messagestartchars.h \
|
||||||
kernel/notifications_interface.h \
|
kernel/notifications_interface.h \
|
||||||
kernel/validation_cache_sizes.h \
|
kernel/validation_cache_sizes.h \
|
||||||
key.h \
|
key.h \
|
||||||
|
|
|
@ -90,10 +90,10 @@ void DeserializeDB(Stream& stream, Data&& data, bool fCheckSum = true)
|
||||||
{
|
{
|
||||||
HashVerifier verifier{stream};
|
HashVerifier verifier{stream};
|
||||||
// de-serialize file header (network specific magic number) and ..
|
// de-serialize file header (network specific magic number) and ..
|
||||||
unsigned char pchMsgTmp[4];
|
MessageStartChars pchMsgTmp;
|
||||||
verifier >> pchMsgTmp;
|
verifier >> pchMsgTmp;
|
||||||
// ... verify the network matches ours
|
// ... verify the network matches ours
|
||||||
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) {
|
if (pchMsgTmp != Params().MessageStart()) {
|
||||||
throw std::runtime_error{"Invalid network magic number"};
|
throw std::runtime_error{"Invalid network magic number"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <crypto/sha256.h>
|
#include <crypto/sha256.h>
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
|
#include <random.h>
|
||||||
#include <test/util/mining.h>
|
#include <test/util/mining.h>
|
||||||
#include <test/util/script.h>
|
#include <test/util/script.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <consensus/merkle.h>
|
#include <consensus/merkle.h>
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <pow.h>
|
#include <pow.h>
|
||||||
|
#include <random.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <bench/bench.h>
|
#include <bench/bench.h>
|
||||||
#include <kernel/mempool_entry.h>
|
#include <kernel/mempool_entry.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
|
#include <random.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/caches.h>
|
#include <node/caches.h>
|
||||||
#include <node/chainstate.h>
|
#include <node/chainstate.h>
|
||||||
|
#include <random.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <script/sigcache.h>
|
#include <script/sigcache.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <util/exception.h>
|
#include <util/exception.h>
|
||||||
|
#include <util/strencodings.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
|
|
|
@ -1223,7 +1223,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
assert(!node.connman);
|
assert(!node.connman);
|
||||||
node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
|
node.connman = std::make_unique<CConnman>(GetRand<uint64_t>(),
|
||||||
GetRand<uint64_t>(),
|
GetRand<uint64_t>(),
|
||||||
*node.addrman, *node.netgroupman, args.GetBoolArg("-networkactive", true));
|
*node.addrman, *node.netgroupman, chainparams, args.GetBoolArg("-networkactive", true));
|
||||||
|
|
||||||
assert(!node.fee_estimator);
|
assert(!node.fee_estimator);
|
||||||
// Don't initialize fee estimation with old data if we don't relay transactions,
|
// Don't initialize fee estimation with old data if we don't relay transactions,
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <consensus/merkle.h>
|
#include <consensus/merkle.h>
|
||||||
#include <consensus/params.h>
|
#include <consensus/params.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
|
#include <kernel/messagestartchars.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
@ -359,7 +360,7 @@ public:
|
||||||
HashWriter h{};
|
HashWriter h{};
|
||||||
h << consensus.signet_challenge;
|
h << consensus.signet_challenge;
|
||||||
uint256 hash = h.GetHash();
|
uint256 hash = h.GetHash();
|
||||||
memcpy(pchMessageStart, hash.begin(), 4);
|
std::copy_n(hash.begin(), 4, pchMessageStart.begin());
|
||||||
|
|
||||||
nDefaultPort = 38333;
|
nDefaultPort = 38333;
|
||||||
nPruneAfterHeight = 1000;
|
nPruneAfterHeight = 1000;
|
||||||
|
|
|
@ -7,9 +7,8 @@
|
||||||
#define BITCOIN_KERNEL_CHAINPARAMS_H
|
#define BITCOIN_KERNEL_CHAINPARAMS_H
|
||||||
|
|
||||||
#include <consensus/params.h>
|
#include <consensus/params.h>
|
||||||
#include <netaddress.h>
|
#include <kernel/messagestartchars.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <protocol.h>
|
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
#include <util/hash_type.h>
|
#include <util/hash_type.h>
|
||||||
|
@ -87,17 +86,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
const Consensus::Params& GetConsensus() const { return consensus; }
|
const Consensus::Params& GetConsensus() const { return consensus; }
|
||||||
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
const MessageStartChars& MessageStart() const { return pchMessageStart; }
|
||||||
uint16_t GetDefaultPort() const { return nDefaultPort; }
|
uint16_t GetDefaultPort() const { return nDefaultPort; }
|
||||||
uint16_t GetDefaultPort(Network net) const
|
|
||||||
{
|
|
||||||
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
|
|
||||||
}
|
|
||||||
uint16_t GetDefaultPort(const std::string& addr) const
|
|
||||||
{
|
|
||||||
CNetAddr a;
|
|
||||||
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
const CBlock& GenesisBlock() const { return genesis; }
|
const CBlock& GenesisBlock() const { return genesis; }
|
||||||
/** Default value for -checkmempool and -checkblockindex argument */
|
/** Default value for -checkmempool and -checkblockindex argument */
|
||||||
|
@ -165,7 +155,7 @@ protected:
|
||||||
CChainParams() {}
|
CChainParams() {}
|
||||||
|
|
||||||
Consensus::Params consensus;
|
Consensus::Params consensus;
|
||||||
CMessageHeader::MessageStartChars pchMessageStart;
|
MessageStartChars pchMessageStart;
|
||||||
uint16_t nDefaultPort;
|
uint16_t nDefaultPort;
|
||||||
uint64_t nPruneAfterHeight;
|
uint64_t nPruneAfterHeight;
|
||||||
uint64_t m_assumed_blockchain_size;
|
uint64_t m_assumed_blockchain_size;
|
||||||
|
|
13
src/kernel/messagestartchars.h
Normal file
13
src/kernel/messagestartchars.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright (c) 2023 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_KERNEL_MESSAGESTARTCHARS_H
|
||||||
|
#define BITCOIN_KERNEL_MESSAGESTARTCHARS_H
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
using MessageStartChars = std::array<uint8_t, 4>;
|
||||||
|
|
||||||
|
#endif // BITCOIN_KERNEL_MESSAGESTARTCHARS_H
|
|
@ -8,6 +8,7 @@
|
||||||
#include <bech32.h>
|
#include <bech32.h>
|
||||||
#include <script/interpreter.h>
|
#include <script/interpreter.h>
|
||||||
#include <script/solver.h>
|
#include <script/solver.h>
|
||||||
|
#include <tinyformat.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
31
src/net.cpp
31
src/net.cpp
|
@ -470,8 +470,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
|
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
|
||||||
|
|
||||||
// Resolve
|
// Resolve
|
||||||
const uint16_t default_port{pszDest != nullptr ? Params().GetDefaultPort(pszDest) :
|
const uint16_t default_port{pszDest != nullptr ? GetDefaultPort(pszDest) :
|
||||||
Params().GetDefaultPort()};
|
m_params.GetDefaultPort()};
|
||||||
if (pszDest) {
|
if (pszDest) {
|
||||||
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
|
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
|
||||||
if (!resolved.empty()) {
|
if (!resolved.empty()) {
|
||||||
|
@ -730,7 +730,7 @@ V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noex
|
||||||
m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
|
m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
|
||||||
{
|
{
|
||||||
assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes));
|
assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes));
|
||||||
std::copy(std::begin(Params().MessageStart()), std::end(Params().MessageStart()), m_magic_bytes);
|
m_magic_bytes = Params().MessageStart();
|
||||||
LOCK(m_recv_mutex);
|
LOCK(m_recv_mutex);
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
@ -759,7 +759,7 @@ int V1Transport::readHeader(Span<const uint8_t> msg_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check start string, network magic
|
// Check start string, network magic
|
||||||
if (memcmp(hdr.pchMessageStart, m_magic_bytes, CMessageHeader::MESSAGE_START_SIZE) != 0) {
|
if (hdr.pchMessageStart != m_magic_bytes) {
|
||||||
LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
|
LogPrint(BCLog::NET, "Header error: Wrong MessageStart %s received, peer=%d\n", HexStr(hdr.pchMessageStart), m_node_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1144,7 +1144,7 @@ bool V2Transport::ProcessReceivedKeyBytes() noexcept
|
||||||
// they receive our uniformly random key and garbage, but detecting this case specially
|
// they receive our uniformly random key and garbage, but detecting this case specially
|
||||||
// means we can log it.
|
// means we can log it.
|
||||||
static constexpr std::array<uint8_t, 12> MATCH = {'v', 'e', 'r', 's', 'i', 'o', 'n', 0, 0, 0, 0, 0};
|
static constexpr std::array<uint8_t, 12> MATCH = {'v', 'e', 'r', 's', 'i', 'o', 'n', 0, 0, 0, 0, 0};
|
||||||
static constexpr size_t OFFSET = sizeof(CMessageHeader::MessageStartChars);
|
static constexpr size_t OFFSET = std::tuple_size_v<MessageStartChars>;
|
||||||
if (!m_initiating && m_recv_buffer.size() >= OFFSET + MATCH.size()) {
|
if (!m_initiating && m_recv_buffer.size() >= OFFSET + MATCH.size()) {
|
||||||
if (std::equal(MATCH.begin(), MATCH.end(), m_recv_buffer.begin() + OFFSET)) {
|
if (std::equal(MATCH.begin(), MATCH.end(), m_recv_buffer.begin() + OFFSET)) {
|
||||||
LogPrint(BCLog::NET, "V2 transport error: V1 peer with wrong MessageStart %s\n",
|
LogPrint(BCLog::NET, "V2 transport error: V1 peer with wrong MessageStart %s\n",
|
||||||
|
@ -2184,7 +2184,7 @@ void CConnman::WakeMessageHandler()
|
||||||
void CConnman::ThreadDNSAddressSeed()
|
void CConnman::ThreadDNSAddressSeed()
|
||||||
{
|
{
|
||||||
FastRandomContext rng;
|
FastRandomContext rng;
|
||||||
std::vector<std::string> seeds = Params().DNSSeeds();
|
std::vector<std::string> seeds = m_params.DNSSeeds();
|
||||||
Shuffle(seeds.begin(), seeds.end(), rng);
|
Shuffle(seeds.begin(), seeds.end(), rng);
|
||||||
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
int seeds_right_now = 0; // Number of seeds left before testing if we have enough connections
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
@ -2275,7 +2275,7 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
const auto addresses{LookupHost(host, nMaxIPs, true)};
|
const auto addresses{LookupHost(host, nMaxIPs, true)};
|
||||||
if (!addresses.empty()) {
|
if (!addresses.empty()) {
|
||||||
for (const CNetAddr& ip : addresses) {
|
for (const CNetAddr& ip : addresses) {
|
||||||
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
|
CAddress addr = CAddress(CService(ip, m_params.GetDefaultPort()), requiredServiceBits);
|
||||||
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
|
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - 3 * 24h, -4 * 24h); // use a random age between 3 and 7 days old
|
||||||
vAdd.push_back(addr);
|
vAdd.push_back(addr);
|
||||||
found++;
|
found++;
|
||||||
|
@ -2480,7 +2480,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_fixed_seeds_now) {
|
if (add_fixed_seeds_now) {
|
||||||
std::vector<CAddress> seed_addrs{ConvertSeeds(Params().FixedSeeds())};
|
std::vector<CAddress> seed_addrs{ConvertSeeds(m_params.FixedSeeds())};
|
||||||
// We will not make outgoing connections to peers that are unreachable
|
// We will not make outgoing connections to peers that are unreachable
|
||||||
// (e.g. because of -onlynet configuration).
|
// (e.g. because of -onlynet configuration).
|
||||||
// Therefore, we do not add them to addrman in the first place.
|
// Therefore, we do not add them to addrman in the first place.
|
||||||
|
@ -2769,7 +2769,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::string& strAddNode : lAddresses) {
|
for (const std::string& strAddNode : lAddresses) {
|
||||||
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort(strAddNode)));
|
CService service(LookupNumeric(strAddNode, GetDefaultPort(strAddNode)));
|
||||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
||||||
if (service.IsValid()) {
|
if (service.IsValid()) {
|
||||||
// strAddNode is an IP:port
|
// strAddNode is an IP:port
|
||||||
|
@ -3075,11 +3075,12 @@ void CConnman::SetNetworkActive(bool active)
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, AddrMan& addrman_in,
|
CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, AddrMan& addrman_in,
|
||||||
const NetGroupManager& netgroupman, bool network_active)
|
const NetGroupManager& netgroupman, const CChainParams& params, bool network_active)
|
||||||
: addrman(addrman_in)
|
: addrman(addrman_in)
|
||||||
, m_netgroupman{netgroupman}
|
, m_netgroupman{netgroupman}
|
||||||
, nSeed0(nSeed0In)
|
, nSeed0(nSeed0In)
|
||||||
, nSeed1(nSeed1In)
|
, nSeed1(nSeed1In)
|
||||||
|
, m_params(params)
|
||||||
{
|
{
|
||||||
SetTryNewOutboundPeer(false);
|
SetTryNewOutboundPeer(false);
|
||||||
|
|
||||||
|
@ -3093,6 +3094,16 @@ NodeId CConnman::GetNewNodeId()
|
||||||
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
|
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t CConnman::GetDefaultPort(Network net) const
|
||||||
|
{
|
||||||
|
return net == NET_I2P ? I2P_SAM31_PORT : m_params.GetDefaultPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CConnman::GetDefaultPort(const std::string& addr) const
|
||||||
|
{
|
||||||
|
CNetAddr a;
|
||||||
|
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : m_params.GetDefaultPort();
|
||||||
|
}
|
||||||
|
|
||||||
bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlags permissions)
|
bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlags permissions)
|
||||||
{
|
{
|
||||||
|
|
13
src/net.h
13
src/net.h
|
@ -10,15 +10,16 @@
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <common/bloom.h>
|
#include <common/bloom.h>
|
||||||
#include <compat/compat.h>
|
#include <compat/compat.h>
|
||||||
#include <node/connection_types.h>
|
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <crypto/siphash.h>
|
#include <crypto/siphash.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <i2p.h>
|
#include <i2p.h>
|
||||||
|
#include <kernel/messagestartchars.h>
|
||||||
#include <net_permissions.h>
|
#include <net_permissions.h>
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
#include <netgroup.h>
|
#include <netgroup.h>
|
||||||
|
#include <node/connection_types.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
|
@ -46,6 +47,7 @@
|
||||||
|
|
||||||
class AddrMan;
|
class AddrMan;
|
||||||
class BanMan;
|
class BanMan;
|
||||||
|
class CChainParams;
|
||||||
class CNode;
|
class CNode;
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
@ -360,7 +362,7 @@ public:
|
||||||
class V1Transport final : public Transport
|
class V1Transport final : public Transport
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CMessageHeader::MessageStartChars m_magic_bytes;
|
MessageStartChars m_magic_bytes;
|
||||||
const NodeId m_node_id; // Only for logging
|
const NodeId m_node_id; // Only for logging
|
||||||
mutable Mutex m_recv_mutex; //!< Lock for receive state
|
mutable Mutex m_recv_mutex; //!< Lock for receive state
|
||||||
mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
|
mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
|
||||||
|
@ -1080,7 +1082,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
|
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
|
||||||
bool network_active = true);
|
const CChainParams& params, bool network_active = true);
|
||||||
|
|
||||||
~CConnman();
|
~CConnman();
|
||||||
|
|
||||||
|
@ -1356,6 +1358,9 @@ private:
|
||||||
// Whether the node should be passed out in ForEach* callbacks
|
// Whether the node should be passed out in ForEach* callbacks
|
||||||
static bool NodeFullyConnected(const CNode* pnode);
|
static bool NodeFullyConnected(const CNode* pnode);
|
||||||
|
|
||||||
|
uint16_t GetDefaultPort(Network net) const;
|
||||||
|
uint16_t GetDefaultPort(const std::string& addr) const;
|
||||||
|
|
||||||
// Network usage totals
|
// Network usage totals
|
||||||
mutable Mutex m_total_bytes_sent_mutex;
|
mutable Mutex m_total_bytes_sent_mutex;
|
||||||
std::atomic<uint64_t> nTotalBytesRecv{0};
|
std::atomic<uint64_t> nTotalBytesRecv{0};
|
||||||
|
@ -1565,6 +1570,8 @@ private:
|
||||||
std::vector<CNode*> m_nodes_copy;
|
std::vector<CNode*> m_nodes_copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CChainParams& m_params;
|
||||||
|
|
||||||
friend struct ConnmanTestMsg;
|
friend struct ConnmanTestMsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <flatfile.h>
|
#include <flatfile.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <kernel/chainparams.h>
|
#include <kernel/chainparams.h>
|
||||||
|
#include <kernel/messagestartchars.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <pow.h>
|
#include <pow.h>
|
||||||
#include <reverse_iterator.h>
|
#include <reverse_iterator.h>
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
#include <util/batchpriority.h>
|
#include <util/batchpriority.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/signalinterrupt.h>
|
#include <util/signalinterrupt.h>
|
||||||
|
#include <util/strencodings.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
|
@ -927,12 +929,12 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CMessageHeader::MessageStartChars blk_start;
|
MessageStartChars blk_start;
|
||||||
unsigned int blk_size;
|
unsigned int blk_size;
|
||||||
|
|
||||||
filein >> blk_start >> blk_size;
|
filein >> blk_start >> blk_size;
|
||||||
|
|
||||||
if (memcmp(blk_start, GetParams().MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) {
|
if (blk_start != GetParams().MessageStart()) {
|
||||||
return error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(),
|
return error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(),
|
||||||
HexStr(blk_start),
|
HexStr(blk_start),
|
||||||
HexStr(GetParams().MessageStart()));
|
HexStr(GetParams().MessageStart()));
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <kernel/blockmanager_opts.h>
|
#include <kernel/blockmanager_opts.h>
|
||||||
#include <kernel/chainparams.h>
|
#include <kernel/chainparams.h>
|
||||||
#include <kernel/cs_main.h>
|
#include <kernel/cs_main.h>
|
||||||
#include <protocol.h>
|
#include <kernel/messagestartchars.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/hasher.h>
|
#include <util/hasher.h>
|
||||||
|
@ -73,7 +73,7 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
|
||||||
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
|
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
|
||||||
|
|
||||||
/** Size of header written by WriteBlockToDisk before a serialized CBlock */
|
/** Size of header written by WriteBlockToDisk before a serialized CBlock */
|
||||||
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAGE_START_SIZE + sizeof(unsigned int);
|
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = std::tuple_size_v<MessageStartChars> + sizeof(unsigned int);
|
||||||
|
|
||||||
extern std::atomic_bool fReindex;
|
extern std::atomic_bool fReindex;
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ const static std::vector<std::string> g_all_net_message_types{
|
||||||
|
|
||||||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
||||||
{
|
{
|
||||||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
|
pchMessageStart = pchMessageStartIn;
|
||||||
|
|
||||||
// Copy the command name
|
// Copy the command name
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#ifndef BITCOIN_PROTOCOL_H
|
#ifndef BITCOIN_PROTOCOL_H
|
||||||
#define BITCOIN_PROTOCOL_H
|
#define BITCOIN_PROTOCOL_H
|
||||||
|
|
||||||
|
#include <kernel/messagestartchars.h> // IWYU pragma: export
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -26,14 +28,12 @@
|
||||||
class CMessageHeader
|
class CMessageHeader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr size_t MESSAGE_START_SIZE = 4;
|
|
||||||
static constexpr size_t COMMAND_SIZE = 12;
|
static constexpr size_t COMMAND_SIZE = 12;
|
||||||
static constexpr size_t MESSAGE_SIZE_SIZE = 4;
|
static constexpr size_t MESSAGE_SIZE_SIZE = 4;
|
||||||
static constexpr size_t CHECKSUM_SIZE = 4;
|
static constexpr size_t CHECKSUM_SIZE = 4;
|
||||||
static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
|
static constexpr size_t MESSAGE_SIZE_OFFSET = std::tuple_size_v<MessageStartChars> + COMMAND_SIZE;
|
||||||
static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
|
static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
|
||||||
static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
|
static constexpr size_t HEADER_SIZE = std::tuple_size_v<MessageStartChars> + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
|
||||||
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
|
|
||||||
|
|
||||||
explicit CMessageHeader() = default;
|
explicit CMessageHeader() = default;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public:
|
||||||
|
|
||||||
SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
|
SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
|
||||||
|
|
||||||
char pchMessageStart[MESSAGE_START_SIZE]{};
|
MessageStartChars pchMessageStart{};
|
||||||
char pchCommand[COMMAND_SIZE]{};
|
char pchCommand[COMMAND_SIZE]{};
|
||||||
uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()};
|
uint32_t nMessageSize{std::numeric_limits<uint32_t>::max()};
|
||||||
uint8_t pchChecksum[CHECKSUM_SIZE]{};
|
uint8_t pchChecksum[CHECKSUM_SIZE]{};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
|
|
||||||
|
#include <compat/compat.h>
|
||||||
#include <compat/cpuid.h>
|
#include <compat/cpuid.h>
|
||||||
#include <crypto/chacha20.h>
|
#include <crypto/chacha20.h>
|
||||||
#include <crypto/sha256.h>
|
#include <crypto/sha256.h>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <randomenv.h>
|
#include <randomenv.h>
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <compat/compat.h>
|
||||||
#include <compat/cpuid.h>
|
#include <compat/cpuid.h>
|
||||||
#include <crypto/sha512.h>
|
#include <crypto/sha512.h>
|
||||||
#include <support/cleanse.h>
|
#include <support/cleanse.h>
|
||||||
|
|
|
@ -285,6 +285,7 @@ template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_wri
|
||||||
template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); }
|
template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); }
|
||||||
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); }
|
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); }
|
||||||
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); }
|
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); }
|
||||||
|
template <typename Stream, typename B, std::size_t N> void Serialize(Stream& s, const std::array<B, N>& a) { (void)/* force byte-type */UCharCast(a.data()); s.write(MakeByteSpan(a)); }
|
||||||
template <typename Stream, typename B> void Serialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.write(AsBytes(span)); }
|
template <typename Stream, typename B> void Serialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.write(AsBytes(span)); }
|
||||||
|
|
||||||
#ifndef CHAR_EQUALS_INT8
|
#ifndef CHAR_EQUALS_INT8
|
||||||
|
@ -301,6 +302,7 @@ template<typename Stream> inline void Unserialize(Stream& s, int64_t& a ) { a =
|
||||||
template<typename Stream> inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); }
|
template<typename Stream> inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); }
|
||||||
template<typename Stream, int N> inline void Unserialize(Stream& s, char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
|
template<typename Stream, int N> inline void Unserialize(Stream& s, char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
|
||||||
template<typename Stream, int N> inline void Unserialize(Stream& s, unsigned char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
|
template<typename Stream, int N> inline void Unserialize(Stream& s, unsigned char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
|
||||||
|
template <typename Stream, typename B, std::size_t N> void Unserialize(Stream& s, std::array<B, N>& a) { (void)/* force byte-type */UCharCast(a.data()); s.read(MakeWritableByteSpan(a)); }
|
||||||
template <typename Stream, typename B> void Unserialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.read(AsWritableBytes(span)); }
|
template <typename Stream, typename B> void Unserialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.read(AsWritableBytes(span)); }
|
||||||
|
|
||||||
template <typename Stream> inline void Serialize(Stream& s, bool a) { uint8_t f = a; ser_writedata8(s, f); }
|
template <typename Stream> inline void Serialize(Stream& s, bool a) { uint8_t f = a; ser_writedata8(s, f); }
|
||||||
|
|
|
@ -142,7 +142,7 @@ static void AddRandomOutboundPeer(NodeId& id, std::vector<CNode*>& vNodes, PeerM
|
||||||
BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
||||||
|
@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
||||||
|
@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
||||||
LOCK(NetEventsInterface::g_msgproc_mutex);
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
CNetAddr tor_netaddr;
|
CNetAddr tor_netaddr;
|
||||||
|
@ -407,7 +407,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||||
LOCK(NetEventsInterface::g_msgproc_mutex);
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman);
|
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
||||||
|
|
||||||
banman->ClearBanned();
|
banman->ClearBanned();
|
||||||
|
|
|
@ -36,6 +36,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
||||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||||
*g_setup->m_node.addrman,
|
*g_setup->m_node.addrman,
|
||||||
*g_setup->m_node.netgroupman,
|
*g_setup->m_node.netgroupman,
|
||||||
|
Params(),
|
||||||
fuzzed_data_provider.ConsumeBool()};
|
fuzzed_data_provider.ConsumeBool()};
|
||||||
CNetAddr random_netaddr;
|
CNetAddr random_netaddr;
|
||||||
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
CNode random_node = ConsumeNode(fuzzed_data_provider);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <script/descriptor.h>
|
#include <script/descriptor.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
//! Types are raw (un)compressed pubkeys, raw xonly pubkeys, raw privkeys (WIF), xpubs, xprvs.
|
//! Types are raw (un)compressed pubkeys, raw xonly pubkeys, raw privkeys (WIF), xpubs, xprvs.
|
||||||
static constexpr uint8_t KEY_TYPES_COUNT{6};
|
static constexpr uint8_t KEY_TYPES_COUNT{6};
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send V1 version message header to the transport. */
|
/** Send V1 version message header to the transport. */
|
||||||
void SendV1Version(const CMessageHeader::MessageStartChars& magic)
|
void SendV1Version(const MessageStartChars& magic)
|
||||||
{
|
{
|
||||||
CMessageHeader hdr(magic, "version", 126 + InsecureRandRange(11));
|
CMessageHeader hdr(magic, "version", 126 + InsecureRandRange(11));
|
||||||
CDataStream ser(SER_NETWORK, CLIENT_VERSION);
|
CDataStream ser(SER_NETWORK, CLIENT_VERSION);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
|
#include <random.h>
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
|
|
@ -253,7 +253,7 @@ TestingSetup::TestingSetup(
|
||||||
/*deterministic=*/false,
|
/*deterministic=*/false,
|
||||||
m_node.args->GetIntArg("-checkaddrman", 0));
|
m_node.args->GetIntArg("-checkaddrman", 0));
|
||||||
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman); // Deterministic randomness for tests.
|
m_node.connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params()); // Deterministic randomness for tests.
|
||||||
PeerManager::Options peerman_opts;
|
PeerManager::Options peerman_opts;
|
||||||
ApplyArgsManOptions(*m_node.args, peerman_opts);
|
ApplyArgsManOptions(*m_node.args, peerman_opts);
|
||||||
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
#ifndef BITCOIN_UTIL_TIME_H
|
#ifndef BITCOIN_UTIL_TIME_H
|
||||||
#define BITCOIN_UTIL_TIME_H
|
#define BITCOIN_UTIL_TIME_H
|
||||||
|
|
||||||
#include <compat/compat.h>
|
|
||||||
|
|
||||||
#include <chrono> // IWYU pragma: export
|
#include <chrono> // IWYU pragma: export
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <kernel/chainparams.h>
|
#include <kernel/chainparams.h>
|
||||||
#include <kernel/mempool_entry.h>
|
#include <kernel/mempool_entry.h>
|
||||||
|
#include <kernel/messagestartchars.h>
|
||||||
#include <kernel/notifications_interface.h>
|
#include <kernel/notifications_interface.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <logging/timer.h>
|
#include <logging/timer.h>
|
||||||
|
@ -4602,11 +4603,11 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||||
unsigned int nSize = 0;
|
unsigned int nSize = 0;
|
||||||
try {
|
try {
|
||||||
// locate a header
|
// locate a header
|
||||||
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
|
MessageStartChars buf;
|
||||||
blkdat.FindByte(std::byte(params.MessageStart()[0]));
|
blkdat.FindByte(std::byte(params.MessageStart()[0]));
|
||||||
nRewind = blkdat.GetPos() + 1;
|
nRewind = blkdat.GetPos() + 1;
|
||||||
blkdat >> buf;
|
blkdat >> buf;
|
||||||
if (memcmp(buf, params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) {
|
if (buf != params.MessageStart()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// read size
|
// read size
|
||||||
|
|
|
@ -136,7 +136,7 @@ bool IsSQLiteFile(const fs::path& path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the application id matches our network magic
|
// Check the application id matches our network magic
|
||||||
return memcmp(Params().MessageStart(), app_id, 4) == 0;
|
return memcmp(Params().MessageStart().data(), app_id, 4) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options)
|
void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options)
|
||||||
|
|
|
@ -193,7 +193,7 @@ bool SQLiteDatabase::Verify(bilingual_str& error)
|
||||||
auto read_result = ReadPragmaInteger(m_db, "application_id", "the application id", error);
|
auto read_result = ReadPragmaInteger(m_db, "application_id", "the application id", error);
|
||||||
if (!read_result.has_value()) return false;
|
if (!read_result.has_value()) return false;
|
||||||
uint32_t app_id = static_cast<uint32_t>(read_result.value());
|
uint32_t app_id = static_cast<uint32_t>(read_result.value());
|
||||||
uint32_t net_magic = ReadBE32(Params().MessageStart());
|
uint32_t net_magic = ReadBE32(Params().MessageStart().data());
|
||||||
if (app_id != net_magic) {
|
if (app_id != net_magic) {
|
||||||
error = strprintf(_("SQLiteDatabase: Unexpected application id. Expected %u, got %u"), net_magic, app_id);
|
error = strprintf(_("SQLiteDatabase: Unexpected application id. Expected %u, got %u"), net_magic, app_id);
|
||||||
return false;
|
return false;
|
||||||
|
@ -324,7 +324,7 @@ void SQLiteDatabase::Open()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the application id
|
// Set the application id
|
||||||
uint32_t app_id = ReadBE32(Params().MessageStart());
|
uint32_t app_id = ReadBE32(Params().MessageStart().data());
|
||||||
SetPragma(m_db, "application_id", strprintf("%d", static_cast<int32_t>(app_id)),
|
SetPragma(m_db, "application_id", strprintf("%d", static_cast<int32_t>(app_id)),
|
||||||
"Failed to set the application id");
|
"Failed to set the application id");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue