diff options
author | Jim Posen <jim.posen@gmail.com> | 2018-05-15 15:57:48 -0700 |
---|---|---|
committer | Jim Posen <jim.posen@gmail.com> | 2018-06-04 19:22:26 -0700 |
commit | 2318affd27de436ddf9d866a4b82eed8ea2e738b (patch) | |
tree | 014e8cc6347c5668c002961fefef7ed01243f5cd /src/index/txindex.h | |
parent | f376a4924109af2496b5fd16a787299eb039f1c8 (diff) | |
download | bitcoin-2318affd27de436ddf9d866a4b82eed8ea2e738b.tar.xz |
MOVEONLY: Move BaseIndex to its own file.
Diffstat (limited to 'src/index/txindex.h')
-rw-r--r-- | src/index/txindex.h | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/src/index/txindex.h b/src/index/txindex.h index 29626332ab..fb92ad98dc 100644 --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -5,81 +5,7 @@ #ifndef BITCOIN_INDEX_TXINDEX_H #define BITCOIN_INDEX_TXINDEX_H -#include <primitives/block.h> -#include <primitives/transaction.h> -#include <threadinterrupt.h> -#include <txdb.h> -#include <uint256.h> -#include <validationinterface.h> - -class CBlockIndex; - -/** - * Base class for indices of blockchain data. This implements - * CValidationInterface and ensures blocks are indexed sequentially according - * to their position in the active chain. - */ -class BaseIndex : public CValidationInterface -{ -private: - /// 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 - /// ValidationInterface notifications to stay in sync. - std::atomic<bool> m_synced{false}; - - /// The last block in the chain that the index is in sync with. - std::atomic<const CBlockIndex*> m_best_block_index{nullptr}; - - std::thread m_thread_sync; - CThreadInterrupt m_interrupt; - - /// Sync the index with the block index starting from the current best block. - /// Intended to be run in its own thread, m_thread_sync, and can be - /// interrupted with m_interrupt. Once the index gets in sync, the m_synced - /// flag is set and the BlockConnected ValidationInterface callback takes - /// over and the sync thread exits. - void ThreadSync(); - - /// Write the current chain block locator to the DB. - bool WriteBestBlock(const CBlockIndex* block_index); - -protected: - void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex, - const std::vector<CTransactionRef>& txn_conflicted) override; - - void ChainStateFlushed(const CBlockLocator& locator) override; - - /// Initialize internal state from the database and block index. - virtual bool Init(); - - /// Write update index entries for a newly connected block. - virtual bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) { return true; } - - virtual BaseIndexDB& GetDB() const = 0; - - /// Get the name of the index for display in logs. - virtual const char* GetName() const = 0; - -public: - /// Destructor interrupts sync thread if running and blocks until it exits. - virtual ~BaseIndex(); - - /// Blocks the current thread until the index is caught up to the current - /// state of the block chain. This only blocks if the index has gotten in - /// sync once and only needs to process blocks in the ValidationInterface - /// queue. If the index is catching up from far behind, this method does - /// not block and immediately returns false. - bool BlockUntilSyncedToCurrentChain(); - - void Interrupt(); - - /// Start initializes the sync state and registers the instance as a - /// ValidationInterface so that it stays in sync with blockchain updates. - void Start(); - - /// Stops the instance from staying in sync with blockchain updates. - void Stop(); -}; +#include <index/base.h> /** * TxIndex is used to look up transactions included in the blockchain by hash. |