Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
validation.h
Go to the documentation of this file.
1// Copyright (c) 2020-present 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_TEST_UTIL_VALIDATION_H
6#define BITCOIN_TEST_UTIL_VALIDATION_H
7
8#include <consensus/amount.h>
10#include <util/task_runner.h>
11#include <validation.h>
12
13#include <cstddef>
14#include <functional>
15#include <thread>
16#include <utility>
17#include <vector>
18
19namespace node {
20class BlockManager;
21struct NodeContext;
22}
23class BaseIndex;
25class FakeNodeClock;
26struct TestingSetup;
27
30{
31public:
32 void insert(std::function<void()> func) override { std::thread(std::move(func)).join(); }
33 void flush() override {}
34 size_t size() override { return 0; }
35};
36
39 void CleanupForFuzzing();
40};
41
55
57{
58public:
59 static void BlockConnected(
60 const kernel::ChainstateRole& role,
62 const std::shared_ptr<const CBlock>& block,
63 const CBlockIndex* pindex);
64};
65
68};
69
70std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup& setup, FakeNodeClock& node_clock, const ResetOptions& opts = {});
71
74
75#endif // BITCOIN_TEST_UTIL_VALIDATION_H
Base class for indices of blockchain data.
Definition base.h:55
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition chain.h:94
Implement this to subscribe to events generated in validation and mempool.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition validation.h:950
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition time.h:54
Runs callbacks synchronously and deterministically, while avoiding DEBUG_LOCKORDER false positives.
Definition validation.h:30
size_t size() override
Returns the number of currently pending events.
Definition validation.h:34
void flush() override
Forces the processing of all pending events.
Definition validation.h:33
void insert(std::function< void()> func) override
The callback can either be queued for later/asynchronous/threaded processing, or be executed immediat...
Definition validation.h:32
static void BlockConnected(const kernel::ChainstateRole &role, CValidationInterface &obj, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
bool init_block_filter_basic
Definition validation.h:67
void CleanupForFuzzing()
Test-only method to clear internal state for fuzzing.
void ResetBestInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CBlockIndex * FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void DisableNextWrite()
Disable the next write of all chainstates.
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Wrappers that avoid making chainstatemanager internals public for tests.
void JumpOutOfIbd()
Toggle IsInitialBlockDownload from true to false.
void ResetIbd()
Reset the ibd cache to its initial state.
Testing setup that configures a complete environment.
Information about chainstate that notifications are sent from.
Definition types.h:20
NodeContext struct containing references to chain state and connection state.
Definition context.h:57
This header provides an interface and simple implementation for a task runner.
std::vector< std::pair< COutPoint, CAmount > > ResetChainmanAndMempool(TestingSetup &setup, FakeNodeClock &node_clock, const ResetOptions &opts={})
void StopIndex(BaseIndex &index, node::NodeContext &node)
Drain validation callbacks before stopping an index, matching Shutdown() in init.cpp.
static int setup(void)
Definition tests.c:8289
#define EXCLUSIVE_LOCKS_REQUIRED(...)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82