19#include <validation.h>
22constexpr uint32_t FUZZ_MAX_HEADERS_RESULTS{16};
26 std::vector<CNode*> m_connections;
48void HeadersSyncSetup::ResetAndInitialize()
50 m_connections.clear();
55 std::vector<ConnectionType> conn_types = {
61 for (
auto conn_type : conn_types) {
63 m_connections.push_back(
new CNode(
id++,
nullptr, addr, 0, 0, addr,
"", conn_type,
false));
64 CNode& p2p_node = *m_connections.back();
74 connman.AddTestNode(p2p_node);
81 CNode& connection = *
PickValue(fuzzed_data_provider, m_connections);
83 connman.FlushSendBuffer(connection);
84 (void)connman.ReceiveMsgFrom(connection, std::move(
msg));
87 connman.ProcessMessagesOnce(connection);
88 }
catch (
const std::ios_base::failure&) {
107 header.
nBits = prev_nbits;
112 header.
nBits = target.GetCompact();
122 auto header = ConsumeHeader(fuzzed_data_provider, prev_hash, prev_nbits);
129 tx.
vout[0].nValue = 0;
130 tx.
vin[0].scriptSig.resize(2);
132 block.hashMerkleRoot = block.vtx[0]->GetHash();
145HeadersSyncSetup* g_testing_setup;
149 static auto setup = MakeNoLogFileContext<HeadersSyncSetup>(
ChainType::MAIN, {.extra_args = {
"-checkpoints=0"}});
150 g_testing_setup = setup.get();
161 g_testing_setup->ResetAndInitialize();
172 std::vector<CBlockHeader> all_headers;
176 auto finalized_block = [&]() {
177 CBlock block = ConsumeBlock(fuzzed_data_provider, base.GetHash(), base.nBits);
178 FinalizeHeader(block, chainman);
184 fuzzed_data_provider,
187 std::vector<CBlock> headers;
188 headers.resize(FUZZ_MAX_HEADERS_RESULTS);
189 for (
CBlock& header : headers) {
190 header = ConsumeHeader(fuzzed_data_provider, base.GetHash(), base.nBits);
191 FinalizeHeader(header, chainman);
195 all_headers.insert(all_headers.end(), headers.begin(), headers.end());
198 g_testing_setup->SendMessage(fuzzed_data_provider, std::move(headers_msg));
202 auto block = finalized_block();
205 all_headers.push_back(block);
208 g_testing_setup->SendMessage(fuzzed_data_provider, std::move(headers_msg));
212 auto block = finalized_block();
214 all_headers.push_back(block);
217 g_testing_setup->SendMessage(fuzzed_data_provider, std::move(headers_msg));
234 g_testing_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
arith_uint256 UintToArith256(const uint256 &a)
A CService with information about it as peer.
const CBlock & GenesisBlock() const
const Consensus::Params & GetConsensus() const
Information about a peer.
std::atomic_bool fPauseSend
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
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.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
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)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
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
uint32_t max_headers_result
Number of headers sent in one getheaders message result (this is a test-only option).
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.
int64_t 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)
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
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.