Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.h
Show All 37 Lines | |||||
//! Max memory allocated to block tree DB specific cache, if -txindex (MiB) | //! Max memory allocated to block tree DB specific cache, if -txindex (MiB) | ||||
// Unlike for the UTXO database, for the txindex scenario the leveldb cache make | // Unlike for the UTXO database, for the txindex scenario the leveldb cache make | ||||
// 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 const int64_t nMaxTxIndexCache = 1024; | static const int64_t nMaxTxIndexCache = 1024; | ||||
//! Max memory allocated to coin DB specific cache (MiB) | //! Max memory allocated to coin DB specific cache (MiB) | ||||
static const int64_t nMaxCoinsDBCache = 8; | static const int64_t nMaxCoinsDBCache = 8; | ||||
struct CDiskTxPos : public CDiskBlockPos { | |||||
unsigned int nTxOffset; // after header | |||||
ADD_SERIALIZE_METHODS; | |||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITEAS(CDiskBlockPos, *this); | |||||
READWRITE(VARINT(nTxOffset)); | |||||
} | |||||
CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) | |||||
: CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {} | |||||
CDiskTxPos() { SetNull(); } | |||||
void SetNull() { | |||||
CDiskBlockPos::SetNull(); | |||||
nTxOffset = 0; | |||||
} | |||||
}; | |||||
/** 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; | 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); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public: | ||||
bool ReadReindexing(bool &fReindexing); | bool 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 Config &config, | const Config &config, | ||||
std::function<CBlockIndex *(const uint256 &)> insertBlockIndex); | std::function<CBlockIndex *(const uint256 &)> insertBlockIndex); | ||||
}; | }; | ||||
class BaseIndexDB : public CDBWrapper { | |||||
public: | |||||
BaseIndexDB(const fs::path &path, size_t n_cache_size, | |||||
bool f_memory = false, bool f_wipe = false, | |||||
bool f_obfuscate = false); | |||||
/// Read block locator of the chain that the index is in sync with. | |||||
bool ReadBestBlock(CBlockLocator &locator) const; | |||||
/// Write block locator of the chain that the index is in sync with. | |||||
bool WriteBestBlock(const CBlockLocator &locator); | |||||
}; | |||||
/** | |||||
* Access to the txindex database (indexes/txindex/) | |||||
* | |||||
* The database stores a block locator of the chain the database is synced to | |||||
* so that the TxIndex can efficiently determine the point it last stopped at. | |||||
* A locator is used instead of a simple hash of the chain tip because blocks | |||||
* and block index entries may not be flushed to disk until after this database | |||||
* is updated. | |||||
*/ | |||||
class TxIndexDB : public BaseIndexDB { | |||||
public: | |||||
explicit TxIndexDB(size_t n_cache_size, bool f_memory = false, | |||||
bool f_wipe = false); | |||||
/// Read the disk location of the transaction data with the given hash. | |||||
/// Returns false if the transaction hash is not indexed. | |||||
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const; | |||||
/// Write a batch of transaction positions to the DB. | |||||
bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>> &v_pos); | |||||
/// Migrate txindex data from the block tree DB, where it may be for older | |||||
/// nodes that have not been upgraded yet to the new database. | |||||
bool MigrateData(CBlockTreeDB &block_tree_db, | |||||
const CBlockLocator &best_locator); | |||||
}; | |||||
#endif // BITCOIN_TXDB_H | #endif // BITCOIN_TXDB_H |