Skip to content

Commit

Permalink
Require CBlockIndex::IsAssumedValid() to hold cs_main
Browse files Browse the repository at this point in the history
Summary:
This is a partial backport of [[bitcoin/bitcoin#22932 | core#22932]]
bitcoin/bitcoin@8ef457c

Depends on D13034

Test Plan:
With clang and DEBUG:

`ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13035
  • Loading branch information
PiRK committed Jan 24, 2023
1 parent fb7c3b8 commit 7b92966
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/blockindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ class CBlockIndex {

//! @returns true if the block is assumed-valid; this means it is queued
//! to be validated by a background chainstate.
bool IsAssumedValid() const { return nStatus.isAssumedValid(); }
bool IsAssumedValid() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
AssertLockHeld(::cs_main);
return nStatus.isAssumedValid();
}

//! Raise the validity level of this block index entry.
//! Returns true if the validity was changed.
Expand Down
4 changes: 3 additions & 1 deletion src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot,
*chainman.SnapshotBlockhash());

// Ensure that the genesis block was not marked assumed-valid.
BOOST_CHECK(!chainman.ActiveChain().Genesis()->IsAssumedValid());
BOOST_CHECK(WITH_LOCK(
::cs_main, return !chainman.ActiveChain().Genesis()->IsAssumedValid()));

const AssumeutxoData &au_data =
*ExpectedAssumeutxo(snapshot_height, ::Params());
Expand Down Expand Up @@ -368,6 +369,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup) {

CBlockIndex *validated_tip{nullptr};
for (int i = 0; i <= cs1.m_chain.Height(); ++i) {
LOCK(::cs_main);
auto index = cs1.m_chain[i];

if (i < last_assumed_valid_idx && i >= assumed_valid_start_idx) {
Expand Down

0 comments on commit 7b92966

Please sign in to comment.