5 #ifndef BITCOIN_INDEX_BASE_H 6 #define BITCOIN_INDEX_BASE_H 54 bool f_memory =
false,
bool f_wipe =
false,
bool f_obfuscate =
false);
96 template <
typename... Args>
109 [[nodiscard]]
virtual bool CustomInit(
const std::optional<interfaces::BlockKey>& block) {
return true; }
122 virtual DB&
GetDB()
const = 0;
128 BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string
name);
146 [[nodiscard]]
bool Init();
165 #endif // BITCOIN_INDEX_BASE_H
bool Commit()
Write the current index state (eg.
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
CThreadInterrupt m_interrupt
BaseIndex(std::unique_ptr< interfaces::Chain > chain, std::string name)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
std::atomic< bool > m_synced
Whether the index is in sync with the main chain.
Batch of changes queued to be written to a CDBWrapper.
virtual bool CustomAppend(const interfaces::BlockInfo &block)
Write update index entries for a newly connected block.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
void SetBestBlockIndex(const CBlockIndex *block)
Update the internal best block index as well as the prune lock.
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip)
Loop over disconnected blocks and call CustomRewind.
Implement this to subscribe to events generated in validation and mempool.
void Stop()
Stops the instance from staying in sync with blockchain updates.
The database stores a block locator of the chain the database is synced to so that the index can effi...
std::thread m_thread_sync
Block data sent with blockConnected, blockDisconnected notifications.
void FatalErrorf(const char *fmt, const Args &... args)
virtual ~BaseIndex()
Destructor interrupts sync thread if running and blocks until it exits.
Base class for indices of blockchain data.
void WriteBestBlock(CDBBatch &batch, const CBlockLocator &locator)
Write block locator of the chain that the index is in sync with.
virtual bool CustomInit(const std::optional< interfaces::BlockKey > &block)
Initialize internal state from the database and block index.
void ChainStateFlushed(ChainstateRole role, const CBlockLocator &locator) override
Notifies listeners of the new active block chain on-disk.
Chainstate stores and provides an API to update our local knowledge of the current best chain...
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
const std::string & GetName() const LIFETIMEBOUND
Get the name of the index for display in logs.
std::atomic< bool > m_init
Whether the index has been initialized or not.
void Sync()
Sync the index with the block index starting from the current best block.
A helper class for interruptible sleeps.
bool StartBackgroundSync()
Starts the initial sync process on a background thread.
virtual bool CustomRewind(const interfaces::BlockKey ¤t_tip, const interfaces::BlockKey &new_tip)
Rewind index to an earlier chain tip during a chain reorg.
virtual bool CustomCommit(CDBBatch &batch)
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
#define LOCKS_EXCLUDED(...)
The block chain is a tree shaped structure starting with the genesis block at the root...
Hash/height pair to help track and identify blocks.
Chainstate * m_chainstate
void BlockConnected(ChainstateRole role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
DB(const fs::path &path, size_t n_cache_size, bool f_memory=false, bool f_wipe=false, bool f_obfuscate=false)
bool ReadBestBlock(CBlockLocator &locator) const
Read block locator of the chain that the index is in sync with.
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...
virtual DB & GetDB() const =0
std::atomic< const CBlockIndex * > m_best_block_index
The last block in the chain that the index is in sync with.
virtual bool AllowPrune() const =0
std::unique_ptr< interfaces::Chain > m_chain
IndexSummary GetSummary() const
Get a summary of the index and its state.