diff options
author | Jim Posen <jim.posen@gmail.com> | 2018-05-15 15:45:20 -0700 |
---|---|---|
committer | Jim Posen <jim.posen@gmail.com> | 2018-06-04 19:22:24 -0700 |
commit | f376a4924109af2496b5fd16a787299eb039f1c8 (patch) | |
tree | 925e460c230e5c061b21e1782e5ec56944cca29e | |
parent | 61a1226d87d80234b2be123c5cad07534c318cfb (diff) |
index: Generalize logged statements in BaseIndex.
-rw-r--r-- | src/index/txindex.cpp | 21 | ||||
-rw-r--r-- | src/index/txindex.h | 5 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 90de0fde97..4434ce3f21 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -107,7 +107,8 @@ void BaseIndex::ThreadSync() 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; } @@ -123,7 +124,7 @@ void BaseIndex::ThreadSync() 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; } @@ -131,9 +132,9 @@ void BaseIndex::ThreadSync() } 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()); } } @@ -182,7 +183,7 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const // new chain tip. In this unlikely event, log a warning and let the queue clear. if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) { LogPrintf("%s: WARNING: Block %s does not connect to an ancestor of " /* Continued */ - "known best chain (tip=%s); not updating txindex\n", + "known best chain (tip=%s); not updating index\n", __func__, pindex->GetBlockHash().ToString(), best_block_index->GetBlockHash().ToString()); return; @@ -192,7 +193,7 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const if (WriteBlock(*block, pindex)) { m_best_block_index = pindex; } else { - FatalError("%s: Failed to write block %s to txindex", + FatalError("%s: Failed to write block %s to index", __func__, pindex->GetBlockHash().ToString()); return; } @@ -225,7 +226,7 @@ void BaseIndex::ChainStateFlushed(const CBlockLocator& locator) const CBlockIndex* best_block_index = m_best_block_index.load(); if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) { LogPrintf("%s: WARNING: Locator contains block (hash=%s) not on known best " /* Continued */ - "chain (tip=%s); not writing txindex locator\n", + "chain (tip=%s); not writing index locator\n", __func__, locator_tip_hash.ToString(), best_block_index->GetBlockHash().ToString()); return; @@ -255,7 +256,7 @@ bool BaseIndex::BlockUntilSyncedToCurrentChain() } } - 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; } @@ -299,11 +300,11 @@ void BaseIndex::Start() // 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<std::function<void()>>, "txindex", + m_thread_sync = std::thread(&TraceThread<std::function<void()>>, GetName(), std::bind(&BaseIndex::ThreadSync, this)); } diff --git a/src/index/txindex.h b/src/index/txindex.h index f38d845998..29626332ab 100644 --- a/src/index/txindex.h +++ b/src/index/txindex.h @@ -57,6 +57,9 @@ protected: 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(); @@ -96,6 +99,8 @@ protected: 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<TxIndexDB> db); |