Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
validation.cpp
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
6
7#include <node/blockstorage.h>
8#include <util/check.h>
9#include <util/time.h>
10#include <validation.h>
11#include <validationinterface.h>
12
14
21
23{
24 struct TestChainstate : public Chainstate {
25 void ResetNextWrite() { m_next_write = NodeClock::time_point::max() - 1s; }
26 };
28 for (const auto& cs : m_chainstates) {
29 static_cast<TestChainstate&>(*cs).ResetNextWrite();
30 }
31}
32
38
45
47 const ChainstateRole& role,
49 const std::shared_ptr<const CBlock>& block,
50 const CBlockIndex* pindex)
51{
52 obj.BlockConnected(role, block, pindex);
53}
55{
56 struct TestChainstate : public Chainstate {
57 void CallInvalidBlockFound(CBlockIndex* pindex, const BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
58 {
59 InvalidBlockFound(pindex, state);
60 }
61 };
62
63 static_cast<TestChainstate*>(&ActiveChainstate())->CallInvalidBlockFound(pindex, state);
64}
65
67{
68 struct TestChainstate : public Chainstate {
69 void CallInvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
70 {
71 InvalidChainFound(pindexNew);
72 }
73 };
74
75 static_cast<TestChainstate*>(&ActiveChainstate())->CallInvalidChainFound(pindexNew);
76}
77
79{
80 struct TestChainstate : public Chainstate {
81 CBlockIndex* CallFindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
82 {
83 return FindMostWorkChain();
84 }
85 };
86
87 return static_cast<TestChainstate*>(&ActiveChainstate())->CallFindMostWorkChain();
88}
89
91{
92 m_best_invalid = nullptr;
93}
static void pool cs
#define Assert(val)
Identity function.
Definition check.h:113
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.
virtual void BlockConnected(const kernel::ChainstateRole &role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being connected.
bool IsInitialBlockDownload() const noexcept
Check whether we are doing an initial block download (synchronizing from disk or network).
Chainstate & ActiveChainstate() const
std::atomic_bool m_cached_is_ibd
Whether initial block download (IBD) is ongoing.
static void BlockConnected(const kernel::ChainstateRole &role, CValidationInterface &obj, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
std::set< int > m_dirty_fileinfo
Dirty block file entries.
std::set< CBlockIndex * > m_dirty_blockindex
Dirty block index entries.
std::vector< CBlockFileInfo > m_blockfile_info
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
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.
Information about chainstate that notifications are sent from.
Definition types.h:18
#define LOCK(cs)
Definition sync.h:258
#define EXCLUSIVE_LOCKS_REQUIRED(...)
assert(!tx.IsCoinBase())