mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core, eth/downloader: fix chain sync eta
This commit is contained in:
parent
c0bad8184f
commit
15e5c08b85
2 changed files with 20 additions and 5 deletions
|
|
@ -4339,6 +4339,13 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64)
|
|||
if header.Hash() != hash {
|
||||
t.Errorf("block #%d: header mismatch: want: %v, got: %v", num, hash, header.Hash())
|
||||
}
|
||||
tail, err := db.Tail()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get chain tail, %v", err)
|
||||
}
|
||||
if tail != cutoffBlock.NumberU64() {
|
||||
t.Fatalf("Unexpected chain tail, want: %d, got: %d", cutoffBlock.NumberU64(), tail)
|
||||
}
|
||||
// Block bodies and receipts before the cutoff should be non-existent
|
||||
if num < cutoffBlock.NumberU64() {
|
||||
body := chain.GetBody(hash)
|
||||
|
|
|
|||
|
|
@ -1133,10 +1133,20 @@ func (d *Downloader) reportSnapSyncProgress(force bool) {
|
|||
header = d.blockchain.CurrentHeader()
|
||||
block = d.blockchain.CurrentSnapBlock()
|
||||
)
|
||||
syncedBlocks := block.Number.Uint64() - d.syncStartBlock
|
||||
if syncedBlocks == 0 {
|
||||
// Prevent reporting if nothing has been synchronized yet
|
||||
if block.Number.Uint64() <= d.syncStartBlock {
|
||||
return
|
||||
}
|
||||
// Prevent reporting noise if the actual chain synchronization (headers
|
||||
// and bodies) hasn't started yet. Inserting the ancient header chain is
|
||||
// fast enough and would introduce significant bias if included in the count.
|
||||
if d.chainCutoffNumber != 0 && block.Number.Uint64() < d.chainCutoffNumber {
|
||||
return
|
||||
}
|
||||
fetchedBlocks := block.Number.Uint64() - d.syncStartBlock
|
||||
if d.chainCutoffNumber != 0 {
|
||||
fetchedBlocks = block.Number.Uint64() - d.chainCutoffNumber
|
||||
}
|
||||
// Retrieve the current chain head and calculate the ETA
|
||||
latest, _, _, err := d.skeleton.Bounds()
|
||||
if err != nil {
|
||||
|
|
@ -1151,9 +1161,7 @@ func (d *Downloader) reportSnapSyncProgress(force bool) {
|
|||
}
|
||||
var (
|
||||
left = latest.Number.Uint64() - block.Number.Uint64()
|
||||
|
||||
// TODO(rjl493456442) fix the ETA in the pruning mode.
|
||||
eta = time.Since(d.syncStartTime) / time.Duration(syncedBlocks) * time.Duration(left)
|
||||
eta = time.Since(d.syncStartTime) / time.Duration(fetchedBlocks) * time.Duration(left)
|
||||
|
||||
progress = fmt.Sprintf("%.2f%%", float64(block.Number.Uint64())*100/float64(latest.Number.Uint64()))
|
||||
headers = fmt.Sprintf("%v@%v", log.FormatLogfmtUint64(header.Number.Uint64()), common.StorageSize(headerBytes).TerminalString())
|
||||
|
|
|
|||
Loading…
Reference in a new issue