diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -838,8 +838,8 @@ const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main) = nullptr; public: - CChainState(BlockManager &blockman) : m_blockman(blockman) {} - CChainState(); + explicit CChainState(BlockManager &blockman) : m_blockman(blockman) {} + explicit CChainState(BlockHash from_snapshot_blockhash = BlockHash()); /** * Initialize the CoinsViews UTXO set database management data structures. @@ -864,6 +864,15 @@ //! The current chain of blockheaders we consult and build on. //! @see CChain, CBlockIndex. CChain m_chain; + + /** + * The blockhash which is the base of the snapshot this chainstate was + * created from. + * + * IsNull() if this chainstate was not created from a snapshot. + */ + const BlockHash m_from_snapshot_blockhash{}; + /** * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for * itself and all ancestors) and as good as our current tip or better. diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -741,10 +741,15 @@ // NOTE: for now m_blockman is set to a global, but this will be changed // in a future commit. -CChainState::CChainState() : m_blockman(g_blockman) {} +CChainState::CChainState(BlockHash from_snapshot_blockhash) + : m_blockman(g_blockman), + m_from_snapshot_blockhash(from_snapshot_blockhash) {} void CChainState::InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe, std::string leveldb_name) { + if (!m_from_snapshot_blockhash.IsNull()) { + leveldb_name += "_" + m_from_snapshot_blockhash.ToString(); + } m_coins_views = std::make_unique(leveldb_name, cache_size_bytes, in_memory, should_wipe); }