5 #include <chainparams.h> 24 #include <boost/test/unit_test.hpp> 36 1 << 23,
true,
false);
76 outpoint =
AddTestCoin(m_rng, chainstate.CoinsTip());
77 chainstate.CoinsTip().Flush(
false);
81 tx.
vin.emplace_back(outpoint);
84 const auto tip{
WITH_LOCK(
cs_main,
return chainstate.m_chain.Tip()->GetBlockHash())};
90 BOOST_CHECK(!chainstate.CoinsTip().HaveCoinInCache(outpoint));
100 const auto get_notify_tip{[&]() {
105 uint256 curr_tip = get_notify_tip();
115 std::shared_ptr<CBlock> pblockone = std::make_shared<CBlock>();
127 curr_tip = get_notify_tip();
135 curr_tip = get_notify_tip();
143 bool newblock =
false;
152 pblockone, state, &pindex,
true,
nullptr, &newblock,
true);
157 bool block_added = background_cs.ActivateBestChain(state, pblockone);
160 BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), pblockone->GetHash());
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from. ...
Testing setup that performs all steps up until right before ChainstateManager gets initialized...
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
COutPoint AddTestCoin(FastRandomContext &rng, CCoinsViewCache &coins_view)
Create a Coin with DynamicMemoryUsage of 80 bytes and add it to the given view.
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
Test resizing coins-related Chainstate caches during runtime.
BOOST_FIXTURE_TEST_CASE(connect_tip_does_not_cache_inputs_on_failed_connect, TestChain100Setup)
std::unique_ptr< CTxMemPool > mempool
void SetBestBlock(const uint256 &hashBlock)
Chainstate stores and provides an API to update our local knowledge of the current best chain...
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
SnapshotCompletionResult MaybeValidateSnapshot(Chainstate &validated_cs, Chainstate &unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(Chainstate & CurrentChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Try to validate an assumeutxo snapshot by using a validated historical chainstate targeted at the sna...
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
#define BOOST_CHECK_EQUAL(v1, v2)
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
static bool CreateAndActivateUTXOSnapshot(TestingSetup *fixture, F malleation=NoMalleation, bool reset_chainstate=false, bool in_memory_chainstate=false)
Create and activate a UTXO snapshot, optionally providing a function to malleate the snapshot...
std::unique_ptr< KernelNotifications > notifications
Issues blocking calls about sync status, errors and warnings.
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool ReadBlock(CBlock &block, const FlatFilePos &pos, const std::optional< uint256 > &expected_hash) const
Functions for disk access for blocks.
bool AcceptBlock(const std::shared_ptr< const CBlock > &pblock, BlockValidationState &state, CBlockIndex **ppindex, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock, bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Sufficiently validate a block for disk storage (and store on disk).
A mutable version of CTransaction.
const Consensus::Params & GetConsensus() const
Chainstate * HistoricalChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Return historical chainstate targeting a specific block, if any.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
std::unique_ptr< ChainstateManager > chainman
#define Assert(val)
Identity function.
#define BOOST_CHECK(expr)