Skip to content

Commit 15e5c08

Browse files
committed
core, eth/downloader: fix chain sync eta
1 parent c0bad81 commit 15e5c08

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

core/blockchain_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4339,6 +4339,13 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64)
43394339
if header.Hash() != hash {
43404340
t.Errorf("block #%d: header mismatch: want: %v, got: %v", num, hash, header.Hash())
43414341
}
4342+
tail, err := db.Tail()
4343+
if err != nil {
4344+
t.Fatalf("Failed to get chain tail, %v", err)
4345+
}
4346+
if tail != cutoffBlock.NumberU64() {
4347+
t.Fatalf("Unexpected chain tail, want: %d, got: %d", cutoffBlock.NumberU64(), tail)
4348+
}
43424349
// Block bodies and receipts before the cutoff should be non-existent
43434350
if num < cutoffBlock.NumberU64() {
43444351
body := chain.GetBody(hash)

eth/downloader/downloader.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,10 +1133,20 @@ func (d *Downloader) reportSnapSyncProgress(force bool) {
11331133
header = d.blockchain.CurrentHeader()
11341134
block = d.blockchain.CurrentSnapBlock()
11351135
)
1136-
syncedBlocks := block.Number.Uint64() - d.syncStartBlock
1137-
if syncedBlocks == 0 {
1136+
// Prevent reporting if nothing has been synchronized yet
1137+
if block.Number.Uint64() <= d.syncStartBlock {
11381138
return
11391139
}
1140+
// Prevent reporting noise if the actual chain synchronization (headers
1141+
// and bodies) hasn't started yet. Inserting the ancient header chain is
1142+
// fast enough and would introduce significant bias if included in the count.
1143+
if d.chainCutoffNumber != 0 && block.Number.Uint64() < d.chainCutoffNumber {
1144+
return
1145+
}
1146+
fetchedBlocks := block.Number.Uint64() - d.syncStartBlock
1147+
if d.chainCutoffNumber != 0 {
1148+
fetchedBlocks = block.Number.Uint64() - d.chainCutoffNumber
1149+
}
11401150
// Retrieve the current chain head and calculate the ETA
11411151
latest, _, _, err := d.skeleton.Bounds()
11421152
if err != nil {
@@ -1151,9 +1161,7 @@ func (d *Downloader) reportSnapSyncProgress(force bool) {
11511161
}
11521162
var (
11531163
left = latest.Number.Uint64() - block.Number.Uint64()
1154-
1155-
// TODO(rjl493456442) fix the ETA in the pruning mode.
1156-
eta = time.Since(d.syncStartTime) / time.Duration(syncedBlocks) * time.Duration(left)
1164+
eta = time.Since(d.syncStartTime) / time.Duration(fetchedBlocks) * time.Duration(left)
11571165

11581166
progress = fmt.Sprintf("%.2f%%", float64(block.Number.Uint64())*100/float64(latest.Number.Uint64()))
11591167
headers = fmt.Sprintf("%v@%v", log.FormatLogfmtUint64(header.Number.Uint64()), common.StorageSize(headerBytes).TerminalString())

0 commit comments

Comments
 (0)