Bitcoin Core 30.99.0
P2P Digital Currency
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
16{
17 m_dirty_blockindex.clear();
18 m_dirty_fileinfo.clear();
19 m_blockfile_info.resize(1);
20}
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
34{
37}
38
40{
44}
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}
#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:95
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.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:545
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
Chainstate & ActiveChainstate() const
Alternatives to CurrentChainstate() used by older code to query latest chainstate information without...
std::atomic< bool > m_cached_finished_ibd
Whether initial block download has ended and IsInitialBlockDownload should return false from now on.
Definition: validation.h:1039
static void BlockConnected(const kernel::ChainstateRole &role, CValidationInterface &obj, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Definition: validation.cpp:46
std::set< int > m_dirty_fileinfo
Dirty block file entries.
Definition: blockstorage.h:307
std::set< CBlockIndex * > m_dirty_blockindex
Dirty block index entries.
Definition: blockstorage.h:304
std::vector< CBlockFileInfo > m_blockfile_info
Definition: blockstorage.h:301
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.
Definition: validation.cpp:15
void ResetBestInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:90
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:66
CBlockIndex * FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:78
void DisableNextWrite()
Disable the next write of all chainstates.
Definition: validation.cpp:22
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Wrappers that avoid making chainstatemanager internals public for tests.
Definition: validation.cpp:54
void JumpOutOfIbd()
Toggle IsInitialBlockDownload from true to false.
Definition: validation.cpp:39
void ResetIbd()
Reset the ibd cache to its initial state.
Definition: validation.cpp:33
Information about chainstate that notifications are sent from.
Definition: types.h:18
#define LOCK(cs)
Definition: sync.h:259
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
static bool pool cs
Definition: validation.cpp:402
assert(!tx.IsCoinBase())