Skip to content

Commit f376a49

Browse files
committed
index: Generalize logged statements in BaseIndex.
1 parent 61a1226 commit f376a49

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/index/txindex.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ void BaseIndex::ThreadSync()
107107

108108
int64_t current_time = GetTime();
109109
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
110-
LogPrintf("Syncing txindex with block chain from height %d\n", pindex->nHeight);
110+
LogPrintf("Syncing %s with block chain from height %d\n",
111+
GetName(), pindex->nHeight);
111112
last_log_time = current_time;
112113
}
113114

@@ -123,17 +124,17 @@ void BaseIndex::ThreadSync()
123124
return;
124125
}
125126
if (!WriteBlock(block, pindex)) {
126-
FatalError("%s: Failed to write block %s to tx index database",
127+
FatalError("%s: Failed to write block %s to index database",
127128
__func__, pindex->GetBlockHash().ToString());
128129
return;
129130
}
130131
}
131132
}
132133

133134
if (pindex) {
134-
LogPrintf("txindex is enabled at height %d\n", pindex->nHeight);
135+
LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight);
135136
} else {
136-
LogPrintf("txindex is enabled\n");
137+
LogPrintf("%s is enabled\n", GetName());
137138
}
138139
}
139140

@@ -182,7 +183,7 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const
182183
// new chain tip. In this unlikely event, log a warning and let the queue clear.
183184
if (best_block_index->GetAncestor(pindex->nHeight - 1) != pindex->pprev) {
184185
LogPrintf("%s: WARNING: Block %s does not connect to an ancestor of " /* Continued */
185-
"known best chain (tip=%s); not updating txindex\n",
186+
"known best chain (tip=%s); not updating index\n",
186187
__func__, pindex->GetBlockHash().ToString(),
187188
best_block_index->GetBlockHash().ToString());
188189
return;
@@ -192,7 +193,7 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const
192193
if (WriteBlock(*block, pindex)) {
193194
m_best_block_index = pindex;
194195
} else {
195-
FatalError("%s: Failed to write block %s to txindex",
196+
FatalError("%s: Failed to write block %s to index",
196197
__func__, pindex->GetBlockHash().ToString());
197198
return;
198199
}
@@ -225,7 +226,7 @@ void BaseIndex::ChainStateFlushed(const CBlockLocator& locator)
225226
const CBlockIndex* best_block_index = m_best_block_index.load();
226227
if (best_block_index->GetAncestor(locator_tip_index->nHeight) != locator_tip_index) {
227228
LogPrintf("%s: WARNING: Locator contains block (hash=%s) not on known best " /* Continued */
228-
"chain (tip=%s); not writing txindex locator\n",
229+
"chain (tip=%s); not writing index locator\n",
229230
__func__, locator_tip_hash.ToString(),
230231
best_block_index->GetBlockHash().ToString());
231232
return;
@@ -255,7 +256,7 @@ bool BaseIndex::BlockUntilSyncedToCurrentChain()
255256
}
256257
}
257258

258-
LogPrintf("%s: txindex is catching up on block notifications\n", __func__);
259+
LogPrintf("%s: %s is catching up on block notifications\n", __func__, GetName());
259260
SyncWithValidationInterfaceQueue();
260261
return true;
261262
}
@@ -299,11 +300,11 @@ void BaseIndex::Start()
299300
// callbacks are not missed if Init sets m_synced to true.
300301
RegisterValidationInterface(this);
301302
if (!Init()) {
302-
FatalError("%s: txindex failed to initialize", __func__);
303+
FatalError("%s: %s failed to initialize", __func__, GetName());
303304
return;
304305
}
305306

306-
m_thread_sync = std::thread(&TraceThread<std::function<void()>>, "txindex",
307+
m_thread_sync = std::thread(&TraceThread<std::function<void()>>, GetName(),
307308
std::bind(&BaseIndex::ThreadSync, this));
308309
}
309310

src/index/txindex.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class BaseIndex : public CValidationInterface
5757

5858
virtual BaseIndexDB& GetDB() const = 0;
5959

60+
/// Get the name of the index for display in logs.
61+
virtual const char* GetName() const = 0;
62+
6063
public:
6164
/// Destructor interrupts sync thread if running and blocks until it exits.
6265
virtual ~BaseIndex();
@@ -96,6 +99,8 @@ class TxIndex final : public BaseIndex
9699

97100
BaseIndexDB& GetDB() const override;
98101

102+
const char* GetName() const override { return "txindex"; }
103+
99104
public:
100105
/// Constructs the index, which becomes available to be queried.
101106
explicit TxIndex(std::unique_ptr<TxIndexDB> db);

0 commit comments

Comments
 (0)