Changeset View
Changeset View
Standalone View
Standalone View
src/index/base.h
// Copyright (c) 2017-2018 The Bitcoin Core developers | // Copyright (c) 2017-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_INDEX_BASE_H | #ifndef BITCOIN_INDEX_BASE_H | ||||
#define BITCOIN_INDEX_BASE_H | #define BITCOIN_INDEX_BASE_H | ||||
#include <dbwrapper.h> | |||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <threadinterrupt.h> | #include <threadinterrupt.h> | ||||
#include <txdb.h> | |||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
class CBlockIndex; | class CBlockIndex; | ||||
/** | /** | ||||
* Base class for indices of blockchain data. This implements | * Base class for indices of blockchain data. This implements | ||||
* CValidationInterface and ensures blocks are indexed sequentially according | * CValidationInterface and ensures blocks are indexed sequentially according | ||||
* to their position in the active chain. | * to their position in the active chain. | ||||
*/ | */ | ||||
class BaseIndex : public CValidationInterface { | class BaseIndex : public CValidationInterface { | ||||
protected: | |||||
class DB : public CDBWrapper { | |||||
public: | |||||
DB(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 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); | |||||
}; | |||||
private: | private: | ||||
/// Whether the index is in sync with the main chain. The flag is flipped | /// Whether the index is in sync with the main chain. The flag is flipped | ||||
/// from false to true once, after which point this starts processing | /// from false to true once, after which point this starts processing | ||||
/// ValidationInterface notifications to stay in sync. | /// ValidationInterface notifications to stay in sync. | ||||
std::atomic<bool> m_synced{false}; | std::atomic<bool> m_synced{false}; | ||||
/// The last block in the chain that the index is in sync with. | /// The last block in the chain that the index is in sync with. | ||||
std::atomic<const CBlockIndex *> m_best_block_index{nullptr}; | std::atomic<const CBlockIndex *> m_best_block_index{nullptr}; | ||||
Show All 22 Lines | protected: | ||||
/// Initialize internal state from the database and block index. | /// Initialize internal state from the database and block index. | ||||
virtual bool Init(); | virtual bool Init(); | ||||
/// Write update index entries for a newly connected block. | /// Write update index entries for a newly connected block. | ||||
virtual bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) { | virtual bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) { | ||||
return true; | return true; | ||||
} | } | ||||
virtual BaseIndexDB &GetDB() const = 0; | virtual DB &GetDB() const = 0; | ||||
/// Get the name of the index for display in logs. | /// Get the name of the index for display in logs. | ||||
virtual const char *GetName() const = 0; | virtual const char *GetName() const = 0; | ||||
public: | public: | ||||
/// Destructor interrupts sync thread if running and blocks until it exits. | /// Destructor interrupts sync thread if running and blocks until it exits. | ||||
virtual ~BaseIndex(); | virtual ~BaseIndex(); | ||||
Show All 18 Lines |