Skip to content

Commit

Permalink
index: Generalize logged statements in BaseIndex.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo committed Jun 5, 2018
1 parent 61a1226 commit f376a49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/index/txindex.cpp
Expand Up @@ -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;
}

Expand All @@ -123,17 +124,17 @@ 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;
}
}
}

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());
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}

Expand Down
5 changes: 5 additions & 0 deletions src/index/txindex.h
Expand Up @@ -57,6 +57,9 @@ class BaseIndex : public CValidationInterface

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();
Expand Down Expand Up @@ -96,6 +99,8 @@ class TxIndex final : public BaseIndex

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);
Expand Down

0 comments on commit f376a49

Please sign in to comment.