 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
21 #include <boost/test/unit_test.hpp>
35 std::vector<CChainState*> chainstates;
42 chainstates.push_back(&c1);
44 1 << 23,
true,
false);
49 auto all = manager.
GetAll();
50 BOOST_CHECK_EQUAL_COLLECTIONS(all.begin(), all.end(), chainstates.begin(), chainstates.end());
67 &mempool, snapshot_blockhash));
68 chainstates.push_back(&c2);
73 1 << 23,
true,
false);
84 auto all2 = manager.
GetAll();
85 BOOST_CHECK_EQUAL_COLLECTIONS(all2.begin(), all2.end(), chainstates.begin(), chainstates.end());
112 size_t max_cache = 10000;
116 std::vector<CChainState*> chainstates;
121 chainstates.push_back(&c1);
123 1 << 23,
true,
false);
127 c1.InitCoinsCache(1 << 23);
130 manager.MaybeRebalanceCaches();
139 chainstates.push_back(&c2);
141 1 << 23,
true,
false);
145 c2.InitCoinsCache(1 << 23);
148 manager.MaybeRebalanceCaches();
165 size_t initial_total_coins{100};
172 size_t total_coins{0};
191 constexpr
int snapshot_height = 110;
194 initial_total_coins += 10;
205 auto_infile >> outpoint;
253 int chains_tested{0};
256 BOOST_TEST_MESSAGE(
"Checking coins in " << chainstate->ToString());
262 size_t total_coins{0};
279 constexpr
size_t new_coins{100};
280 mineBlocks(new_coins);
284 size_t coins_in_active{0};
285 size_t coins_in_background{0};
286 size_t coins_missing_from_background{0};
289 BOOST_TEST_MESSAGE(
"Checking coins in " << chainstate->ToString());
296 (is_background ? coins_in_background : coins_in_active)++;
297 }
else if (is_background) {
298 coins_missing_from_background++;
314 loaded_snapshot_blockhash);
334 int num_assumed_valid{0};
335 const int expected_assumed_valid{20};
336 const int last_assumed_valid_idx{40};
337 const int assumed_valid_start_idx = last_assumed_valid_idx - expected_assumed_valid;
342 auto reload_all_block_indexes = [&]() {
345 cs->UnloadBlockIndex();
354 reload_all_block_indexes();
362 if (i < last_assumed_valid_idx && i >= assumed_valid_start_idx) {
367 if (index->IsAssumedValid()) ++num_assumed_valid;
370 if (i == (assumed_valid_start_idx - 1)) {
371 validated_tip = index;
379 return chainman.InitializeChainstate(&mempool,
GetRandHash()));
381 reload_all_block_indexes();
bilingual_str _(const char *psz)
Translation function.
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
int64_t m_total_coinstip_cache
The total number of bytes available for us to use across all in-memory coins caches.
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Holds configuration for use during UTXO snapshot load and validation.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
static uint256 InsecureRand256()
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
CChainState & ActiveChainstate() const
The most-work chain.
std::shared_ptr< const CTransaction > CTransactionRef
#define BOOST_FIXTURE_TEST_SUITE(a, b)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
std::unique_ptr< CTxMemPool > mempool
BOOST_AUTO_TEST_SUITE_END()
#define Assert(val)
Identity function.
BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
Test basic snapshot activation.
CChain & ActiveChain() const
Non-refcounted RAII wrapper for FILE*.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
bool IsSnapshotActive() const
CBlockIndex * ActiveTip() const
std::optional< uint256 > SnapshotBlockhash() const
bool IsSnapshotValidated() const
Is there a snapshot in use and has it been fully validated?
uint256 GetRandHash() noexcept
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
@ BLOCK_ASSUMED_VALID
If set, this indicates that the block index entry is assumed-valid.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
static const uint256 ZERO
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 stores and provides an API to update our local knowledge of the current best chain.
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &chainparams)
Return the expected assumeutxo value for a given height, if one exists.
size_t m_coinsdb_cache_size_bytes
The cache size of the on-disk coins view.
bool IsAssumedValid() const EXCLUSIVE_LOCKS_REQUIRED(
int Height() const
Return the maximal height in the chain.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
void SetBestBlock(const uint256 &hashBlock)
BOOST_AUTO_TEST_CASE(chainstatemanager)
Basic tests for ChainstateManager.
static bool CreateAndActivateUTXOSnapshot(node::NodeContext &node, const fs::path root, F malleation=NoMalleation)
Create and activate a UTXO snapshot, optionally providing a function to malleate the snapshot.
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
const CChainParams & Params()
Return the currently selected parameters.
std::unique_ptr< ChainstateManager > chainman
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.
const unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
int64_t m_total_coinsdb_cache
The total number of bytes available for us to use across all leveldb coins databases.
An outpoint - a combination of a transaction hash and an index n into its vout.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
The block chain is a tree shaped structure starting with the genesis block at the root,...
size_t m_coinstip_cache_size_bytes
The cache size of the in-memory coins view.
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
#define BOOST_CHECK(expr)
#define BOOST_CHECK_EQUAL(v1, v2)
CChain m_chain
The current chain of blockheaders we consult and build on.
Testing setup that performs all steps up until right before ChainstateManager gets initialized.