Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
util
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
>
9
#include <
primitives/transaction.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
19
namespace
node
{
20
class
BlockManager
;
21
}
22
class
CValidationInterface
;
23
class
FakeNodeClock
;
24
struct
TestingSetup
;
25
27
class
ImmediateBackgroundTaskRunner
:
public
util::TaskRunnerInterface
28
{
29
public
:
30
void
insert
(std::function<
void
()> func)
override
{ std::thread(std::move(func)).join(); }
31
void
flush
()
override
{}
32
size_t
size
()
override
{
return
0; }
33
};
34
35
struct
TestBlockManager
:
public
node::BlockManager
{
37
void
CleanupForFuzzing
();
38
};
39
40
struct
TestChainstateManager
:
public
ChainstateManager
{
42
void
DisableNextWrite
();
44
void
ResetIbd
();
46
void
JumpOutOfIbd
();
48
void
InvalidBlockFound
(
CBlockIndex
* pindex,
const
BlockValidationState
& state)
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
);
49
void
InvalidChainFound
(
CBlockIndex
* pindexNew)
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
);
50
CBlockIndex
*
FindMostWorkChain
()
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
);
51
void
ResetBestInvalid
()
EXCLUSIVE_LOCKS_REQUIRED
(
cs_main
);
52
};
53
54
class
ValidationInterfaceTest
55
{
56
public
:
57
static
void
BlockConnected
(
58
const
kernel::ChainstateRole
& role,
59
CValidationInterface
& obj,
60
const
std::shared_ptr<const CBlock>& block,
61
const
CBlockIndex
* pindex);
62
};
63
64
std::vector<std::pair<COutPoint, CAmount>>
ResetChainmanAndMempool
(
TestingSetup
& setup,
FakeNodeClock
& node_clock);
65
66
#endif
// BITCOIN_TEST_UTIL_VALIDATION_H
amount.h
BlockValidationState
Definition
validation.h:133
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition
chain.h:94
CValidationInterface
Implement this to subscribe to events generated in validation and mempool.
Definition
validationinterface.h:50
ChainstateManager::ChainstateManager
ChainstateManager(const util::SignalInterrupt &interrupt, Options options, node::BlockManager::Options blockman_options)
Definition
validation.cpp:6153
FakeNodeClock
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition
time.h:54
ImmediateBackgroundTaskRunner
Runs callbacks synchronously and deterministically, while avoiding DEBUG_LOCKORDER false positives.
Definition
validation.h:28
ImmediateBackgroundTaskRunner::size
size_t size() override
Returns the number of currently pending events.
Definition
validation.h:32
ImmediateBackgroundTaskRunner::flush
void flush() override
Forces the processing of all pending events.
Definition
validation.h:31
ImmediateBackgroundTaskRunner::insert
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:30
ValidationInterfaceTest
Definition
validation.h:55
ValidationInterfaceTest::BlockConnected
static void BlockConnected(const kernel::ChainstateRole &role, CValidationInterface &obj, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Definition
validation.cpp:59
node::BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition
blockstorage.h:194
util::TaskRunnerInterface
Definition
task_runner.h:20
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
node
Definition
messages.h:21
transaction.h
TestBlockManager
Definition
validation.h:35
TestBlockManager::CleanupForFuzzing
void CleanupForFuzzing()
Test-only method to clear internal state for fuzzing.
Definition
validation.cpp:28
TestChainstateManager
Definition
validation.h:40
TestChainstateManager::ResetBestInvalid
void ResetBestInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition
validation.cpp:103
TestChainstateManager::InvalidChainFound
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition
validation.cpp:79
TestChainstateManager::FindMostWorkChain
CBlockIndex * FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition
validation.cpp:91
TestChainstateManager::DisableNextWrite
void DisableNextWrite()
Disable the next write of all chainstates.
Definition
validation.cpp:35
TestChainstateManager::InvalidBlockFound
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Wrappers that avoid making chainstatemanager internals public for tests.
Definition
validation.cpp:67
TestChainstateManager::JumpOutOfIbd
void JumpOutOfIbd()
Toggle IsInitialBlockDownload from true to false.
Definition
validation.cpp:52
TestChainstateManager::ResetIbd
void ResetIbd()
Reset the ibd cache to its initial state.
Definition
validation.cpp:46
TestingSetup
Testing setup that configures a complete environment.
Definition
setup_common.h:115
kernel::ChainstateRole
Information about chainstate that notifications are sent from.
Definition
types.h:18
task_runner.h
This header provides an interface and simple implementation for a task runner.
ResetChainmanAndMempool
std::vector< std::pair< COutPoint, CAmount > > ResetChainmanAndMempool(TestingSetup &setup, FakeNodeClock &node_clock)
Definition
validation.cpp:108
validation.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:49
Generated on
for Bitcoin Core by
1.18.0