index: Generalize logged statements in BaseIndex.
This commit is contained in:
parent
61a1226d87
commit
f376a49241
2 changed files with 16 additions and 10 deletions
|
@ -107,7 +107,8 @@ void BaseIndex::ThreadSync()
|
||||||
|
|
||||||
int64_t current_time = GetTime();
|
int64_t current_time = GetTime();
|
||||||
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
|
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;
|
last_log_time = current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ void BaseIndex::ThreadSync()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!WriteBlock(block, pindex)) {
|
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());
|
__func__, pindex->GetBlockHash().ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -131,9 +132,9 @@ void BaseIndex::ThreadSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pindex) {
|
if (pindex) {
|
||||||
LogPrintf("txindex is enabled at height %d\n", pindex->nHeight);
|
LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight);
|
||||||
} else {
|
} 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.
|
// 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) {
|
if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) {
|
||||||
LogPrintf("%s: WARNING: Block %s does not connect to an ancestor of " /* Continued */
|
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(),
|
__func__, pindex->GetBlockHash().ToString(),
|
||||||
best_block_index->GetBlockHash().ToString());
|
best_block_index->GetBlockHash().ToString());
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +193,7 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const
|
||||||
if (WriteBlock(*block, pindex)) {
|
if (WriteBlock(*block, pindex)) {
|
||||||
m_best_block_index = pindex;
|
m_best_block_index = pindex;
|
||||||
} else {
|
} else {
|
||||||
FatalError("%s: Failed to write block %s to txindex",
|
FatalError("%s: Failed to write block %s to index",
|
||||||
__func__, pindex->GetBlockHash().ToString());
|
__func__, pindex->GetBlockHash().ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -225,7 +226,7 @@ void BaseIndex::ChainStateFlushed(const CBlockLocator& locator)
|
||||||
const CBlockIndex* best_block_index = m_best_block_index.load();
|
const CBlockIndex* best_block_index = m_best_block_index.load();
|
||||||
if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) {
|
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 */
|
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(),
|
__func__, locator_tip_hash.ToString(),
|
||||||
best_block_index->GetBlockHash().ToString());
|
best_block_index->GetBlockHash().ToString());
|
||||||
return;
|
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();
|
SyncWithValidationInterfaceQueue();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -299,11 +300,11 @@ void BaseIndex::Start()
|
||||||
// callbacks are not missed if Init sets m_synced to true.
|
// callbacks are not missed if Init sets m_synced to true.
|
||||||
RegisterValidationInterface(this);
|
RegisterValidationInterface(this);
|
||||||
if (!Init()) {
|
if (!Init()) {
|
||||||
FatalError("%s: txindex failed to initialize", __func__);
|
FatalError("%s: %s failed to initialize", __func__, GetName());
|
||||||
return;
|
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));
|
std::bind(&BaseIndex::ThreadSync, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ protected:
|
||||||
|
|
||||||
virtual BaseIndexDB& GetDB() const = 0;
|
virtual BaseIndexDB& GetDB() const = 0;
|
||||||
|
|
||||||
|
/// Get the name of the index for display in logs.
|
||||||
|
virtual const char* GetName() const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Destructor interrupts sync thread if running and blocks until it exits.
|
/// Destructor interrupts sync thread if running and blocks until it exits.
|
||||||
virtual ~BaseIndex();
|
virtual ~BaseIndex();
|
||||||
|
@ -96,6 +99,8 @@ protected:
|
||||||
|
|
||||||
BaseIndexDB& GetDB() const override;
|
BaseIndexDB& GetDB() const override;
|
||||||
|
|
||||||
|
const char* GetName() const override { return "txindex"; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constructs the index, which becomes available to be queried.
|
/// Constructs the index, which becomes available to be queried.
|
||||||
explicit TxIndex(std::unique_ptr<TxIndexDB> db);
|
explicit TxIndex(std::unique_ptr<TxIndexDB> db);
|
||||||
|
|
Loading…
Add table
Reference in a new issue