Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.h
Show All 39 Lines | |||||
// a meaningful difference: | // a meaningful difference: | ||||
// https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991 | // https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991 | ||||
static constexpr int64_t MAX_TX_INDEX_CACHE_MB = 1024; | static constexpr int64_t MAX_TX_INDEX_CACHE_MB = 1024; | ||||
//! Max memory allocated to all block filter index caches combined in MiB. | //! Max memory allocated to all block filter index caches combined in MiB. | ||||
static constexpr int64_t MAX_FILTER_INDEX_CACHE_MB = 1024; | static constexpr int64_t MAX_FILTER_INDEX_CACHE_MB = 1024; | ||||
//! Max memory allocated to coin DB specific cache (MiB) | //! Max memory allocated to coin DB specific cache (MiB) | ||||
static constexpr int64_t MAX_COINS_DB_CACHE_MB = 8; | static constexpr int64_t MAX_COINS_DB_CACHE_MB = 8; | ||||
// Actually declared in validation.cpp; can't include because of circular | |||||
// dependency. | |||||
extern RecursiveMutex cs_main; | |||||
/** CCoinsView backed by the coin database (chainstate/) */ | /** CCoinsView backed by the coin database (chainstate/) */ | ||||
class CCoinsViewDB final : public CCoinsView { | class CCoinsViewDB final : public CCoinsView { | ||||
protected: | protected: | ||||
CDBWrapper db; | std::unique_ptr<CDBWrapper> m_db; | ||||
fs::path m_ldb_path; | |||||
bool m_is_memory; | |||||
public: | public: | ||||
/** | /** | ||||
* @param[in] ldb_path Location in the filesystem where leveldb data will | * @param[in] ldb_path Location in the filesystem where leveldb data will | ||||
* be stored. | * be stored. | ||||
*/ | */ | ||||
explicit CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, | explicit CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, | ||||
bool fWipe); | bool fWipe); | ||||
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override; | bool GetCoin(const COutPoint &outpoint, Coin &coin) const override; | ||||
bool HaveCoin(const COutPoint &outpoint) const override; | bool HaveCoin(const COutPoint &outpoint) const override; | ||||
BlockHash GetBestBlock() const override; | BlockHash GetBestBlock() const override; | ||||
std::vector<BlockHash> GetHeadBlocks() const override; | std::vector<BlockHash> GetHeadBlocks() const override; | ||||
bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override; | bool BatchWrite(CCoinsMap &mapCoins, const BlockHash &hashBlock) override; | ||||
CCoinsViewCursor *Cursor() const override; | CCoinsViewCursor *Cursor() const override; | ||||
//! Attempt to update from an older database format. | //! Attempt to update from an older database format. | ||||
//! Returns whether an error occurred. | //! Returns whether an error occurred. | ||||
bool Upgrade(); | bool Upgrade(); | ||||
size_t EstimateSize() const override; | size_t EstimateSize() const override; | ||||
//! Dynamically alter the underlying leveldb cache size. | |||||
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | |||||
}; | }; | ||||
/** Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB */ | /** Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB */ | ||||
class CCoinsViewDBCursor : public CCoinsViewCursor { | class CCoinsViewDBCursor : public CCoinsViewCursor { | ||||
public: | public: | ||||
~CCoinsViewDBCursor() {} | ~CCoinsViewDBCursor() {} | ||||
bool GetKey(COutPoint &key) const override; | bool GetKey(COutPoint &key) const override; | ||||
Show All 40 Lines |