Skip to content

Commit 67db88f

Browse files
committed
refactor(logging): show block height instead of batch count in progress
Change fetcher and indexer progress logging from "blocks fetched / total blocks" to "current height / chain tip height". This is more meaningful during initial sync — users can immediately see how far along the chain the sync has progressed rather than counting opaque batch numbers.
1 parent aff4278 commit 67db88f

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/new_index/fetch.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ pub fn start_fetcher(
3333
daemon: &Daemon,
3434
new_headers: Vec<HeaderEntry>,
3535
batch_size: usize,
36+
chain_tip_height: usize,
3637
) -> Result<Fetcher<Vec<BlockEntry>>> {
3738
match from {
38-
FetchFrom::Bitcoind => bitcoind_fetcher(daemon, new_headers, batch_size),
39+
FetchFrom::Bitcoind => bitcoind_fetcher(daemon, new_headers, batch_size, chain_tip_height),
3940
FetchFrom::BlkFiles => blkfiles_fetcher(daemon, new_headers),
4041
}
4142
}
@@ -77,6 +78,7 @@ fn bitcoind_fetcher(
7778
daemon: &Daemon,
7879
new_headers: Vec<HeaderEntry>,
7980
batch_size: usize,
81+
chain_tip_height: usize,
8082
) -> Result<Fetcher<Vec<BlockEntry>>> {
8183
if let Some(tip) = new_headers.last() {
8284
debug!("{:?} ({} left to index)", tip, new_headers.len());
@@ -88,18 +90,17 @@ fn bitcoind_fetcher(
8890
chan.into_receiver(),
8991
spawn_thread("bitcoind_fetcher", move || {
9092
let mut fetcher_count = 0;
91-
let mut blocks_fetched = 0;
9293
let total_blocks_fetched = new_headers.len();
9394
for entries in new_headers.chunks(batch_size) {
9495
if fetcher_count % 50 == 0 && total_blocks_fetched >= 50 {
96+
let batch_height = entries.last().map(|e| e.height()).unwrap_or(0);
9597
info!("fetching blocks {}/{} ({:.1}%)",
96-
blocks_fetched,
97-
total_blocks_fetched,
98-
blocks_fetched as f32 / total_blocks_fetched as f32 * 100.0
98+
batch_height,
99+
chain_tip_height,
100+
batch_height as f32 / chain_tip_height.max(1) as f32 * 100.0
99101
);
100102
}
101103
fetcher_count += 1;
102-
blocks_fetched += entries.len();
103104

104105
let blockhashes: Vec<BlockHash> = entries.iter().map(|e| *e.hash()).collect();
105106
let blocks = daemon

src/new_index/schema.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl Indexer {
293293
let tip = daemon.getbestblockhash()?;
294294

295295
let (new_headers, reorged_since) = self.get_new_headers(&daemon, &tip)?;
296+
let chain_tip_height = new_headers.last().map(|h| h.height()).unwrap_or(0);
296297

297298
// Handle reorgs by undoing the reorged (stale) blocks first
298299
if let Some(reorged_since) = reorged_since {
@@ -324,7 +325,7 @@ impl Indexer {
324325

325326
// Fetch the reorged blocks, then undo their history index db rows.
326327
// The txstore db rows are kept for reorged blocks/transactions.
327-
start_fetcher(self.from, &daemon, reorged_headers, self.iconfig.block_batch_size)?
328+
start_fetcher(self.from, &daemon, reorged_headers, self.iconfig.block_batch_size, chain_tip_height)?
328329
.map(|blocks| self.undo_index(&blocks));
329330
}
330331

@@ -350,20 +351,19 @@ impl Indexer {
350351
);
351352

352353
let mut fetcher_count = 0;
353-
let mut blocks_fetched = 0;
354354
let to_process_total = to_process.len();
355355

356-
start_fetcher(self.from, &daemon, to_process, self.iconfig.block_batch_size)?.map(|blocks| {
356+
start_fetcher(self.from, &daemon, to_process, self.iconfig.block_batch_size, chain_tip_height)?.map(|blocks| {
357357
if fetcher_count % 25 == 0 && to_process_total > 20 {
358+
let batch_height = blocks.last().map(|b| b.entry.height()).unwrap_or(0);
358359
info!(
359360
"processing blocks {}/{} ({:.1}%)",
360-
blocks_fetched,
361-
to_process_total,
362-
blocks_fetched as f32 / to_process_total as f32 * 100.0
361+
batch_height,
362+
chain_tip_height,
363+
batch_height as f32 / chain_tip_height.max(1) as f32 * 100.0
363364
);
364365
}
365366
fetcher_count += 1;
366-
blocks_fetched += blocks.len();
367367

368368
// Add blocks not yet in txstore (idempotent: crash recovery skips already-added blocks)
369369
let to_add: Vec<_> = {

0 commit comments

Comments
 (0)