Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.h
Show All 11 Lines | |||||
#include <flatfile.h> | #include <flatfile.h> | ||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
#include <utility> | #include <utility> | ||||
#include <vector> | #include <vector> | ||||
struct BlockHash; | |||||
class CBlockIndex; | class CBlockIndex; | ||||
class CCoinsViewDBCursor; | class CCoinsViewDBCursor; | ||||
class uint256; | |||||
namespace Consensus { | namespace Consensus { | ||||
struct Params; | struct Params; | ||||
} | } | ||||
//! No need to periodic flush if at least this much space still available. | //! No need to periodic flush if at least this much space still available. | ||||
static constexpr int MAX_BLOCK_COINSDB_USAGE = 10; | static constexpr int MAX_BLOCK_COINSDB_USAGE = 10; | ||||
//! -dbcache default (MiB) | //! -dbcache default (MiB) | ||||
Show All 20 Lines | protected: | ||||
CDBWrapper db; | CDBWrapper db; | ||||
public: | public: | ||||
explicit CCoinsViewDB(size_t nCacheSize, bool fMemory = false, | explicit CCoinsViewDB(size_t nCacheSize, bool fMemory = false, | ||||
bool fWipe = false); | bool fWipe = false); | ||||
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; | ||||
uint256 GetBestBlock() const override; | BlockHash GetBestBlock() const override; | ||||
std::vector<uint256> GetHeadBlocks() const override; | std::vector<BlockHash> GetHeadBlocks() const override; | ||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &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; | ||||
}; | }; | ||||
/** 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; | ||||
bool GetValue(Coin &coin) const override; | bool GetValue(Coin &coin) const override; | ||||
unsigned int GetValueSize() const override; | unsigned int GetValueSize() const override; | ||||
bool Valid() const override; | bool Valid() const override; | ||||
void Next() override; | void Next() override; | ||||
private: | private: | ||||
CCoinsViewDBCursor(CDBIterator *pcursorIn, const uint256 &hashBlockIn) | CCoinsViewDBCursor(CDBIterator *pcursorIn, const BlockHash &hashBlockIn) | ||||
: CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {} | : CCoinsViewCursor(hashBlockIn), pcursor(pcursorIn) {} | ||||
std::unique_ptr<CDBIterator> pcursor; | std::unique_ptr<CDBIterator> pcursor; | ||||
std::pair<char, COutPoint> keyTmp; | std::pair<char, COutPoint> keyTmp; | ||||
friend class CCoinsViewDB; | friend class CCoinsViewDB; | ||||
}; | }; | ||||
/** Access to the block database (blocks/index/) */ | /** Access to the block database (blocks/index/) */ | ||||
class CBlockTreeDB : public CDBWrapper { | class CBlockTreeDB : public CDBWrapper { | ||||
public: | public: | ||||
explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, | explicit CBlockTreeDB(size_t nCacheSize, bool fMemory = false, | ||||
bool fWipe = false); | bool fWipe = false); | ||||
bool WriteBatchSync( | bool WriteBatchSync( | ||||
const std::vector<std::pair<int, const CBlockFileInfo *>> &fileInfo, | const std::vector<std::pair<int, const CBlockFileInfo *>> &fileInfo, | ||||
int nLastFile, const std::vector<const CBlockIndex *> &blockinfo); | int nLastFile, const std::vector<const CBlockIndex *> &blockinfo); | ||||
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info); | bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info); | ||||
bool ReadLastBlockFile(int &nFile); | bool ReadLastBlockFile(int &nFile); | ||||
bool WriteReindexing(bool fReindexing); | bool WriteReindexing(bool fReindexing); | ||||
void ReadReindexing(bool &fReindexing); | void ReadReindexing(bool &fReindexing); | ||||
bool WriteFlag(const std::string &name, bool fValue); | bool WriteFlag(const std::string &name, bool fValue); | ||||
bool ReadFlag(const std::string &name, bool &fValue); | bool ReadFlag(const std::string &name, bool &fValue); | ||||
bool LoadBlockIndexGuts( | bool LoadBlockIndexGuts( | ||||
const Consensus::Params ¶ms, | const Consensus::Params ¶ms, | ||||
std::function<CBlockIndex *(const uint256 &)> insertBlockIndex); | std::function<CBlockIndex *(const BlockHash &)> insertBlockIndex); | ||||
}; | }; | ||||
#endif // BITCOIN_TXDB_H | #endif // BITCOIN_TXDB_H |