Skip to content

Commit fa7c834

Browse files
author
MacroFake
committed
Move ::fCheckBlockIndex into ChainstateManager
This changes the flag for the bitcoin-chainstate executable. Previously it was false, now it is the chain's default value (still false for the main chain).
1 parent fa43188 commit fa7c834

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

src/init.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
934934
init::SetLoggingCategories(args);
935935
init::SetLoggingLevel(args);
936936

937-
fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
938-
939937
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
940938
int64_t nPruneArg = args.GetIntArg("-prune", 0);
941939
if (nPruneArg < 0) {

src/kernel/chainstatemanager_opts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace kernel {
2828
struct ChainstateManagerOpts {
2929
const CChainParams& chainparams;
3030
const std::function<NodeClock::time_point()> adjusted_time_callback{nullptr};
31+
std::optional<bool> check_block_index{};
3132
bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED};
3233
//! If set, it will override the minimum work we will assume exists on some valid chain.
3334
std::optional<arith_uint256> minimum_chain_work;

src/node/chainstatemanager_args.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
namespace node {
2020
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts)
2121
{
22+
if (auto value{args.GetBoolArg("-checkblockindex")}) opts.check_block_index = *value;
23+
2224
if (auto value{args.GetBoolArg("-checkpoints")}) opts.checkpoints_enabled = *value;
2325

2426
if (auto value{args.GetArg("-minimumchainwork")}) {

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
146146
Assert(InitScriptExecutionCache(validation_cache_sizes.script_execution_cache_bytes));
147147

148148
m_node.chain = interfaces::MakeChain(m_node);
149-
fCheckBlockIndex = true;
150149
static bool noui_connected = false;
151150
if (!noui_connected) {
152151
noui_connect();
@@ -194,6 +193,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
194193
const ChainstateManager::Options chainman_opts{
195194
.chainparams = chainparams,
196195
.adjusted_time_callback = GetAdjustedTime,
196+
.check_block_index = true,
197197
};
198198
m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts);
199199
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ GlobalMutex g_best_block_mutex;
121121
std::condition_variable g_best_block_cv;
122122
uint256 g_best_block;
123123
bool g_parallel_script_checks{false};
124-
bool fCheckBlockIndex = false;
125124

126125
const CBlockIndex* Chainstate::FindForkInGlobalIndex(const CBlockLocator& locator) const
127126
{
@@ -4507,7 +4506,7 @@ void Chainstate::LoadExternalBlockFile(
45074506

45084507
void Chainstate::CheckBlockIndex()
45094508
{
4510-
if (!fCheckBlockIndex) {
4509+
if (!m_chainman.ShouldCheckBlockIndex()) {
45114510
return;
45124511
}
45134512

@@ -5248,6 +5247,7 @@ void ChainstateManager::ResetChainstates()
52485247
*/
52495248
static ChainstateManager::Options&& Flatten(ChainstateManager::Options&& opts)
52505249
{
5250+
if (!opts.check_block_index.has_value()) opts.check_block_index = opts.chainparams.DefaultConsistencyChecks();
52515251
if (!opts.minimum_chain_work.has_value()) opts.minimum_chain_work = UintToArith256(opts.chainparams.GetConsensus().nMinimumChainWork);
52525252
if (!opts.assumed_valid_block.has_value()) opts.assumed_valid_block = opts.chainparams.GetConsensus().defaultAssumeValid;
52535253
Assert(opts.adjusted_time_callback);

src/validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ extern uint256 g_best_block;
9595
* False indicates all script checking is done on the main threadMessageHandler thread.
9696
*/
9797
extern bool g_parallel_script_checks;
98-
extern bool fCheckBlockIndex;
9998

10099
/** Documentation for argument 'checklevel'. */
101100
extern const std::vector<std::string> CHECKLEVEL_DOC;
@@ -691,7 +690,7 @@ class Chainstate
691690
/**
692691
* Make various assertions about the state of the block index.
693692
*
694-
* By default this only executes fully when using the Regtest chain; see: fCheckBlockIndex.
693+
* By default this only executes fully when using the Regtest chain; see: m_options.check_block_index.
695694
*/
696695
void CheckBlockIndex();
697696

@@ -860,6 +859,7 @@ class ChainstateManager
860859

861860
const CChainParams& GetParams() const { return m_options.chainparams; }
862861
const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
862+
bool ShouldCheckBlockIndex() const { return *Assert(m_options.check_block_index); }
863863
const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
864864
const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
865865

0 commit comments

Comments
 (0)