21#include <boost/test/unit_test.hpp>
33 std::vector<CChainState*> chainstates;
40 chainstates.push_back(&c1);
42 1 << 23,
true,
false);
47 auto all = manager.
GetAll();
48 BOOST_CHECK_EQUAL_COLLECTIONS(all.begin(), all.end(), chainstates.begin(), chainstates.end());
65 &mempool, snapshot_blockhash));
66 chainstates.push_back(&c2);
71 1 << 23,
true,
false);
82 auto all2 = manager.
GetAll();
83 BOOST_CHECK_EQUAL_COLLECTIONS(all2.begin(), all2.end(), chainstates.begin(), chainstates.end());
110 size_t max_cache = 10000;
114 std::vector<CChainState*> chainstates;
119 chainstates.push_back(&c1);
121 1 << 23,
true,
false);
125 c1.InitCoinsCache(1 << 23);
128 manager.MaybeRebalanceCaches();
137 chainstates.push_back(&c2);
139 1 << 23,
true,
false);
143 c2.InitCoinsCache(1 << 23);
146 manager.MaybeRebalanceCaches();
163 size_t initial_total_coins{100};
170 size_t total_coins{0};
189 constexpr int snapshot_height = 110;
192 initial_total_coins += 10;
203 auto_infile >> outpoint;
248 int chains_tested{0};
251 BOOST_TEST_MESSAGE(
"Checking coins in " << chainstate->ToString());
257 size_t total_coins{0};
274 constexpr size_t new_coins{100};
275 mineBlocks(new_coins);
279 size_t coins_in_active{0};
280 size_t coins_in_background{0};
281 size_t coins_missing_from_background{0};
284 BOOST_TEST_MESSAGE(
"Checking coins in " << chainstate->ToString());
291 (is_background ? coins_in_background : coins_in_active)++;
292 }
else if (is_background) {
293 coins_missing_from_background++;
309 loaded_snapshot_blockhash);
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
const CChainParams & Params()
Return the currently selected parameters.
static bool CreateAndActivateUTXOSnapshot(NodeContext &node, const fs::path root, F malleation=NoMalleation)
Create and activate a UTXO snapshot, optionally providing a function to malleate the snapshot.
#define Assert(val)
Identity function.
Non-refcounted RAII wrapper for FILE*.
The block chain is a tree shaped structure starting with the genesis block at the root,...
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
CChainState stores and provides an API to update our local knowledge of the current best chain.
bool ActivateBestChain(BlockValidationState &state, std::shared_ptr< const CBlock > pblock=nullptr) LOCKS_EXCLUDED(cs_main)
Find the best known block, and make it the tip of the block chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
size_t m_coinsdb_cache_size_bytes
The cache size of the on-disk coins view.
void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe, std::string leveldb_name="chainstate")
Initialize the CoinsViews UTXO set database management data structures.
CChain m_chain
The current chain of blockheaders we consult and build on.
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
size_t m_coinstip_cache_size_bytes
The cache size of the in-memory coins view.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
void SetBestBlock(const uint256 &hashBlock)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
An outpoint - a combination of a transaction hash and an index n into its vout.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
int64_t m_total_coinstip_cache
The total number of bytes available for us to use across all in-memory coins caches.
int64_t m_total_coinsdb_cache
The total number of bytes available for us to use across all leveldb coins databases.
CChainState &InitializeChainstate(CTxMemPool *mempool, const std::optional< uint256 > &snapshot_blockhash=std::nullopt) LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(std::vector< CChainState * GetAll)()
Instantiate a new chainstate and assign it based upon whether it is from a snapshot.
CChainState & ActiveChainstate() const
The most-work chain.
bool IsSnapshotActive() const
std::optional< uint256 > SnapshotBlockhash() const
CChain & ActiveChain() const
CBlockIndex * ActiveTip() const
bool IsSnapshotValidated() const
Is there a snapshot in use and has it been fully validated?
static const uint256 ZERO
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::shared_ptr< const CTransaction > CTransactionRef
uint256 GetRandHash() noexcept
static uint256 InsecureRand256()
Holds configuration for use during UTXO snapshot load and validation.
const unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
Testing setup that performs all steps up until right before ChainstateManager gets initialized.
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< CTxMemPool > mempool
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bilingual_str _(const char *psz)
Translation function.
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &chainparams)
Return the expected assumeutxo value for a given height, if one exists.
BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
Test basic snapshot activation.
BOOST_AUTO_TEST_CASE(chainstatemanager)
Basic tests for ChainstateManager.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...