simplify ChainstateManager::SnapshotBlockhash() return semantics

Don't return null snapshotblockhash values to avoid caller complexity/confusion.
This commit is contained in:
James O'Beirne
2020-08-25 13:50:23 -04:00
parent 7a6c46b37e
commit f6e2da5fb7
7 changed files with 348 additions and 3 deletions

View File

@@ -28,6 +28,8 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
std::vector<CChainState*> chainstates;
const CChainParams& chainparams = Params();
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
// Create a legacy (IBD) chainstate.
//
CChainState& c1 = WITH_LOCK(::cs_main, return manager.InitializeChainstate(mempool));
@@ -54,10 +56,17 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
auto& validated_cs = manager.ValidatedChainstate();
BOOST_CHECK_EQUAL(&validated_cs, &c1);
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
// Create a snapshot-based chainstate.
//
CChainState& c2 = WITH_LOCK(::cs_main, return manager.InitializeChainstate(mempool, GetRandHash()));
const uint256 snapshot_blockhash = GetRandHash();
CChainState& c2 = WITH_LOCK(::cs_main, return manager.InitializeChainstate(
mempool, snapshot_blockhash));
chainstates.push_back(&c2);
BOOST_CHECK_EQUAL(manager.SnapshotBlockhash().value(), snapshot_blockhash);
c2.InitCoinsDB(
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
WITH_LOCK(::cs_main, c2.InitCoinsCache(1 << 23));