5 #ifndef BITCOIN_TEST_UTIL_CHAINSTATE_H 6 #define BITCOIN_TEST_UTIL_CHAINSTATE_H 31 template<
typename F = decltype(NoMalleation)>
36 bool reset_chainstate =
false,
37 bool in_memory_chainstate =
false)
51 node,
node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path);
60 auto_infile >> metadata;
62 malleation(auto_infile, metadata);
64 if (reset_chainstate) {
74 CBlockIndex *orig_tip =
node.chainman->ActiveChainstate().m_chain.Tip();
75 uint256 gen_hash =
node.chainman->ActiveChainstate().m_chain[0]->GetBlockHash();
76 node.chainman->ResetChainstates();
77 node.chainman->InitializeChainstate(
node.mempool.get());
81 chain.InitCoinsDB(1 << 20,
true,
false,
"");
82 chain.InitCoinsCache(1 << 20);
86 node.chainman->MaybeRebalanceCaches();
93 while (pindex && pindex != chain.
m_chain.
Tip()) {
104 pindex = pindex->
pprev;
108 if (!
node.chainman->ActiveChainstate().ActivateBestChain(state)) {
109 throw std::runtime_error(
strprintf(
"ActivateBestChain failed. (%s)", state.
ToString()));
112 0 ==
WITH_LOCK(
node.chainman->GetMutex(),
return node.chainman->ActiveHeight()));
115 auto& new_active =
node.chainman->ActiveChainstate();
116 auto* tip = new_active.m_chain.Tip();
124 new_active.m_chain.SetTip(*(tip->pprev));
127 auto res =
node.chainman->ActivateSnapshot(auto_infile, metadata, in_memory_chainstate);
130 new_active.m_chain.SetTip(*tip);
135 #endif // BITCOIN_TEST_UTIL_CHAINSTATE_H CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
FILE * fopen(const fs::path &p, const char *mode)
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
UniValue CreateUTXOSnapshot(NodeContext &node, Chainstate &chainstate, AutoFile &afile, const fs::path &path, const fs::path &temppath)
Helper to create UTXO snapshots given a chainstate and a file handle.
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
CChain m_chain
The current chain of blockheaders we consult and build on.
Non-refcounted RAII wrapper for FILE*.
void SetBestBlock(const uint256 &hashBlock)
NodeContext struct containing references to chain state and connection state.
static std::string PathToString(const path &path)
Convert path object to a byte string.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
uint64_t m_chain_tx_count
(memory only) Number of transactions in the chain up to and including this block. ...
std::string ToString() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
const CBlockIndex *SnapshotBase() EXCLUSIVE_LOCKS_REQUIRED(std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The base of the snapshot this chainstate was created from.
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
The block chain is a tree shaped structure starting with the genesis block at the root...
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...
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
static path u8path(const std::string &utf8_str)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
unsigned int nTx
Number of transactions in this block.
Testing setup that configures a complete environment.
#define Assert(val)
Identity function.