Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.h
Show First 20 Lines • Show All 122 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/) | * Access to the txindex database (indexes/txindex/) | ||||
* | * | ||||
* The database stores a block locator of the chain the database is synced to | * 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. | * 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 | * 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 | * and block index entries may not be flushed to disk until after this database | ||||
* is updated. | * is updated. | ||||
*/ | */ | ||||
class TxIndexDB : public CDBWrapper { | class TxIndexDB : public BaseIndexDB { | ||||
public: | public: | ||||
explicit TxIndexDB(size_t n_cache_size, bool f_memory = false, | explicit TxIndexDB(size_t n_cache_size, bool f_memory = false, | ||||
bool f_wipe = false); | bool f_wipe = false); | ||||
/// Read the disk location of the transaction data with the given hash. | /// Read the disk location of the transaction data with the given hash. | ||||
/// Returns false if the transaction hash is not indexed. | /// Returns false if the transaction hash is not indexed. | ||||
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const; | bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const; | ||||
/// Write a batch of transaction positions to the DB. | /// Write a batch of transaction positions to the DB. | ||||
bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>> &v_pos); | bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>> &v_pos); | ||||
/// Read block locator of the chain that the txindex is in sync with. | |||||
bool ReadBestBlock(CBlockLocator &locator) const; | |||||
/// Write block locator of the chain that the txindex is in sync with. | |||||
bool WriteBestBlock(const CBlockLocator &locator); | |||||
/// Migrate txindex data from the block tree DB, where it may be for older | /// 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. | /// nodes that have not been upgraded yet to the new database. | ||||
bool MigrateData(CBlockTreeDB &block_tree_db, | bool MigrateData(CBlockTreeDB &block_tree_db, | ||||
const CBlockLocator &best_locator); | const CBlockLocator &best_locator); | ||||
}; | }; | ||||
#endif // BITCOIN_TXDB_H | #endif // BITCOIN_TXDB_H |