5#ifndef BITCOIN_INDEX_BASE_H
6#define BITCOIN_INDEX_BASE_H
The database stores a block locator of the chain the database is synced to so that the TxIndex can ef...
void WriteBestBlock(CDBBatch &batch, const CBlockLocator &locator)
Write block locator of the chain that the index is in sync with.
bool ReadBestBlock(CBlockLocator &locator) const
Read block locator of the chain that the index is in sync with.
Base class for indices of blockchain data.
void Stop()
Stops the instance from staying in sync with blockchain updates.
void SetBestBlockIndex(const CBlockIndex *block)
Update the internal best block index as well as the prune lock.
virtual bool Init()
Initialize internal state from the database and block index.
void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
virtual const char * GetName() const =0
Get the name of the index for display in logs.
bool Start(Chainstate &active_chainstate)
Start initializes the sync state and registers the instance as a ValidationInterface so that it stays...
virtual ~BaseIndex()
Destructor interrupts sync thread if running and blocks until it exits.
std::atomic< const CBlockIndex * > m_best_block_index
The last block in the chain that the index is in sync with.
virtual bool CommitInternal(CDBBatch &batch)
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
bool BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(void Interrupt()
Blocks the current thread until the index is caught up to the current state of the block chain.
virtual bool AllowPrune() const =0
std::atomic< bool > m_synced
Whether the index is in sync with the main chain.
CThreadInterrupt m_interrupt
IndexSummary GetSummary() const
Get a summary of the index and its state.
virtual DB & GetDB() const =0
void ChainStateFlushed(const CBlockLocator &locator) override
Notifies listeners of the new active block chain on-disk.
std::thread m_thread_sync
bool Commit()
Write the current index state (eg.
virtual bool WriteBlock(const CBlock &block, const CBlockIndex *pindex)
Write update index entries for a newly connected block.
void ThreadSync()
Sync the index with the block index starting from the current best block.
Chainstate * m_chainstate
const CBlockIndex * CurrentIndex()
virtual bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip)
Rewind index to an earlier chain tip during a chain reorg.
The block chain is a tree shaped structure starting with the genesis block at the root,...
Batch of changes queued to be written to a CDBWrapper.
A helper class for interruptible sleeps.
Implement this to subscribe to events generated in validation.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
#define LOCKS_EXCLUDED(...)