19#include <validation.h>
22constexpr uint32_t FUZZ_MAX_HEADERS_RESULTS{16};
26 std::vector<CNode*> m_connections;
57void HeadersSyncSetup::ResetAndInitialize()
59 m_connections.clear();
64 std::vector<ConnectionType> conn_types = {
70 for (
auto conn_type : conn_types) {
72 m_connections.push_back(
new CNode(
id++,
nullptr, addr, 0, 0, addr,
"", conn_type,
false, 0));
73 CNode& p2p_node = *m_connections.back();
83 connman.AddTestNode(p2p_node);
92 connman.FlushSendBuffer(connection);
93 (void)connman.ReceiveMsgFrom(connection, std::move(
msg));
96 connman.ProcessMessagesOnce(connection);
97 }
catch (
const std::ios_base::failure&) {
116 header.
nBits = prev_nbits;
121 header.
nBits = target.GetCompact();
138 tx.
vout[0].nValue = 0;
139 tx.
vin[0].scriptSig.resize(2);
141 block.hashMerkleRoot = block.vtx[0]->GetHash().ToUint256();
147HeadersSyncSetup* g_testing_setup;
154 .setup_validation_interface =
false,
157 g_testing_setup =
setup.get();
175 g_testing_setup->ResetAndInitialize();
181 std::vector<CBlockHeader> all_headers;
185 auto finalized_block = [&]() {
196 std::vector<CBlock> headers;
197 headers.resize(FUZZ_MAX_HEADERS_RESULTS);
198 for (
CBlock& header : headers) {
204 all_headers.insert(all_headers.end(), headers.begin(), headers.end());
211 auto block = finalized_block();
214 all_headers.push_back(block);
221 auto block = finalized_block();
223 all_headers.push_back(block);
arith_uint256 UintToArith256(const uint256 &a)
A CService with information about it as peer.
const CBlock & GenesisBlock() const
void StopNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex
Information about a peer.
std::atomic_bool fPauseSend
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
const CChainParams & GetParams() const
const arith_uint256 & MinimumChainWork() const
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Interface for message handling.
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
Helper to initialize the global MockableSteadyClock, let a duration elapse, and reset it after use in...
256-bit unsigned big integer.
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ INBOUND
Inbound connections are those initiated by a peer.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
CSerializedNetMsg Make(std::string msg_type, Args &&... args)
constexpr const char * HEADERS
The headers message sends one or more block headers to a node which previously requested certain head...
constexpr const char * CMPCTBLOCK
Contains a CBlockHeaderAndShortTxIDs object - providing a header and list of "short txids".
constexpr const char * BLOCK
The block message transmits a single serialized block.
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
static constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
ServiceFlags
nServices flags
static const int PROTOCOL_VERSION
network protocol versioning
NetEventsInterface * m_msgproc
A mutable version of CTransaction.
std::vector< CTxOut > vout
bool deterministic_rng
Whether or not the internal RNG behaves deterministically (this is a test-only option).
uint32_t max_headers_result
Number of headers sent in one getheaders message result (this is a test-only option).
bool ignore_incoming_txs
Whether this node is running in -blocksonly mode.
Testing setup that configures a complete environment.
std::unique_ptr< CConnman > connman
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< BanMan > banman
std::unique_ptr< AddrMan > addrman
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
std::unique_ptr< PeerManager > peerman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
void FinalizeHeader(CBlockHeader &header, const ChainstateManager &chainman)
arith_uint256 ConsumeArithUInt256InRange(FuzzedDataProvider &fuzzed_data_provider, const arith_uint256 &min, const arith_uint256 &max) noexcept
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define NO_THREAD_SAFETY_ANALYSIS
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.
FuzzedDataProvider & fuzzed_data_provider