diff --git a/src/index/txindex.h b/src/index/txindex.h --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -60,6 +60,9 @@ 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(); @@ -98,6 +101,8 @@ BaseIndexDB &GetDB() const override; + const char *GetName() const override { return "txindex"; } + public: /// Constructs the index, which becomes available to be queried. explicit TxIndex(std::unique_ptr db); diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -101,8 +101,8 @@ int64_t current_time = GetTime(); if (last_log_time + SYNC_LOG_INTERVAL < current_time) { - LogPrintf("Syncing txindex with block chain from height %d\n", - pindex->nHeight); + LogPrintf("Syncing %s with block chain from height %d\n", + GetName(), pindex->nHeight); last_log_time = current_time; } @@ -119,7 +119,7 @@ return; } if (!WriteBlock(block, pindex)) { - FatalError("%s: Failed to write block %s to tx index database", + FatalError("%s: Failed to write block %s to index database", __func__, pindex->GetBlockHash().ToString()); return; } @@ -127,9 +127,9 @@ } if (pindex) { - LogPrintf("txindex is enabled at height %d\n", pindex->nHeight); + LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight); } else { - LogPrintf("txindex is enabled\n"); + LogPrintf("%s is enabled\n", GetName()); } } @@ -183,7 +183,7 @@ if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) { LogPrintf("%s: WARNING: Block %s does not connect to an ancestor " - "of known best chain (tip=%s); not updating txindex\n", + "of known best chain (tip=%s); not updating index\n", __func__, pindex->GetBlockHash().ToString(), best_block_index->GetBlockHash().ToString()); return; @@ -193,7 +193,7 @@ if (WriteBlock(*block, pindex)) { m_best_block_index = pindex; } else { - FatalError("%s: Failed to write block %s to txindex", __func__, + FatalError("%s: Failed to write block %s to index", __func__, pindex->GetBlockHash().ToString()); return; } @@ -227,7 +227,7 @@ if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) { LogPrintf("%s: WARNING: Locator contains block (hash=%s) not on known " - "best chain (tip=%s); not writing txindex locator\n", + "best chain (tip=%s); not writing index locator\n", __func__, locator_tip_hash.ToString(), best_block_index->GetBlockHash().ToString()); return; @@ -256,7 +256,8 @@ } } - LogPrintf("%s: txindex is catching up on block notifications\n", __func__); + LogPrintf("%s: %s is catching up on block notifications\n", __func__, + GetName()); SyncWithValidationInterfaceQueue(); return true; } @@ -296,11 +297,11 @@ // callbacks are not missed if Init sets m_synced to true. RegisterValidationInterface(this); if (!Init()) { - FatalError("%s: txindex failed to initialize", __func__); + FatalError("%s: %s failed to initialize", __func__, GetName()); return; } - m_thread_sync = std::thread(&TraceThread>, "txindex", + m_thread_sync = std::thread(&TraceThread>, GetName(), std::bind(&BaseIndex::ThreadSync, this)); }