TxIndex

TxIndex is used to look up transactions included in the blockchain by hash. The index is written to a LevelDB database and records the block sequence number and serialized block offset of each transaction by transaction hash.

Synopsis

Declared in <index/txindex.h>

class TxIndex final
    : public BaseIndex

Base Classes

NameDescription
BaseIndexBase class for the node's optional block-chain indexes.

Member Functions

NameDescription
TxIndex [constructor]Constructs the index, which becomes available to be queried.
~TxIndex [destructor] [virtual]Destructor is declared because this class contains a unique_ptr to an incomplete type.
BlockUntilSyncedToCurrentChain 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.
CustomOptions [virtual]Return custom notification options for index.
FindTx Look up a transaction by hash.
GetName Get the name of the index for display in logs.
GetSummary Get a summary of the index and its state.
Init Initializes the sync state and registers the instance to the validation interface so that it stays in sync with blockchain updates.
Interrupt Signal the background sync thread to stop as soon as possible.
StartBackgroundSync Starts the initial sync process on a background thread.
Stop Stops the instance from staying in sync with blockchain updates.
Sync index_sync 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.

Protected Types

NameDescription
DB Database access layer for the transaction index.

Protected Member Functions

NameDescription
ActiveTipChange [virtual]Notifies listeners any time the block chain tip changes, synchronously.
BlockChecked [virtual]Notifies listeners of a block validation result. If the provided BlockValidationState IsValid, the provided block is guaranteed to be the current best block at the time the callback was generated (not necessarily now).
BlockConnected [virtual]Handle a newly connected block by appending it to the index.
BlockDisconnected [virtual]Notifies listeners of a block being disconnected Provides the block that was disconnected.
ChainStateFlushed [virtual]Handle a chainstate flush by committing the index up to the flushed point.
CustomAppend [virtual]Record the transactions of a newly connected block in the index.
CustomCommit [virtual]Virtual method called internally by Commit that can be overridden to atomically commit more index state.
CustomInit [virtual]Initialize internal state from the database and block index.
CustomRemove [virtual]Rewind index by one block during a chain reorg.
GetDB [virtual]Access the database backing this index.
MempoolTransactionsRemovedForBlock [virtual]Notifies listeners of transactions removed from the mempool as as a result of new block being connected. MempoolTransactionsRemovedForBlock will be fired before BlockConnected.
NewPoWValidBlock [virtual]Notifies listeners that a block which builds directly on our current tip has been received and connected to the headers tree, though not validated yet.
SetBestBlockIndex Update the internal best block index as well as the prune lock.
TransactionAddedToMempool [virtual]Notifies listeners of a transaction having been added to mempool.
TransactionRemovedFromMempool [virtual]Notifies listeners of a transaction leaving mempool.
UpdatedBlockTip [virtual]Notifies listeners when the block chain tip advances.

Protected Data Members

NameDescription
m_chain Interface used to query the blockchain the index tracks.
m_chainstate Chainstate the index reads blocks from (not owned).
m_name Human-readable name of the index.
m_thread_name Name given to the background sync thread.

Friends

NameDescription
txindex_tests::TxIndexTestTest fixture granting access to TxIndex private members.