forked from cerc-io/plugeth
core, eth: merge snap-sync chain download progress logs (#26676)
This commit is contained in:
@@ -154,6 +154,11 @@ type Downloader struct {
|
||||
bodyFetchHook func([]*types.Header) // Method to call upon starting a block body fetch
|
||||
receiptFetchHook func([]*types.Header) // Method to call upon starting a receipt fetch
|
||||
chainInsertHook func([]*fetchResult) // Method to call upon inserting a chain of blocks (possibly in multiple invocations)
|
||||
|
||||
// Progress reporting metrics
|
||||
syncStartBlock uint64 // Head snap block when Geth was started
|
||||
syncStartTime time.Time // Time instance when chain sync started
|
||||
syncLogTime time.Time // Time instance when status was last reported
|
||||
}
|
||||
|
||||
// LightChain encapsulates functions required to synchronise a light chain.
|
||||
@@ -231,7 +236,9 @@ func New(checkpoint uint64, stateDb ethdb.Database, mux *event.TypeMux, chain Bl
|
||||
quitCh: make(chan struct{}),
|
||||
SnapSyncer: snap.NewSyncer(stateDb, chain.TrieDB().Scheme()),
|
||||
stateSyncStart: make(chan *stateSync),
|
||||
syncStartBlock: chain.CurrentFastBlock().NumberU64(),
|
||||
}
|
||||
// Create the post-merge skeleton syncer and start the process
|
||||
dl.skeleton = newSkeleton(stateDb, dl.peers, dropPeer, newBeaconBackfiller(dl, success))
|
||||
|
||||
go dl.stateFetcher()
|
||||
@@ -1614,6 +1621,7 @@ func (d *Downloader) processSnapSyncContent() error {
|
||||
if len(results) == 0 {
|
||||
// If pivot sync is done, stop
|
||||
if oldPivot == nil {
|
||||
d.reportSnapSyncProgress(true)
|
||||
return sync.Cancel()
|
||||
}
|
||||
// If sync failed, stop
|
||||
@@ -1627,6 +1635,8 @@ func (d *Downloader) processSnapSyncContent() error {
|
||||
if d.chainInsertHook != nil {
|
||||
d.chainInsertHook(results)
|
||||
}
|
||||
d.reportSnapSyncProgress(false)
|
||||
|
||||
// If we haven't downloaded the pivot block yet, check pivot staleness
|
||||
// notifications from the header downloader
|
||||
d.pivotLock.RLock()
|
||||
@@ -1739,7 +1749,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state
|
||||
}
|
||||
default:
|
||||
}
|
||||
// Retrieve the a batch of results to import
|
||||
// Retrieve the batch of results to import
|
||||
first, last := results[0].Header, results[len(results)-1].Header
|
||||
log.Debug("Inserting snap-sync blocks", "items", len(results),
|
||||
"firstnum", first.Number, "firsthash", first.Hash(),
|
||||
@@ -1820,3 +1830,56 @@ func (d *Downloader) readHeaderRange(last *types.Header, count int) []*types.Hea
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
// reportSnapSyncProgress calculates various status reports and provides it to the user.
|
||||
func (d *Downloader) reportSnapSyncProgress(force bool) {
|
||||
// Initialize the sync start time if it's the first time we're reporting
|
||||
if d.syncStartTime.IsZero() {
|
||||
d.syncStartTime = time.Now().Add(-time.Millisecond) // -1ms offset to avoid division by zero
|
||||
}
|
||||
// Don't report all the events, just occasionally
|
||||
if !force && time.Since(d.syncLogTime) < 8*time.Second {
|
||||
return
|
||||
}
|
||||
// Don't report anything until we have a meaningful progress
|
||||
var (
|
||||
headerBytes, _ = d.stateDB.AncientSize(rawdb.ChainFreezerHeaderTable)
|
||||
bodyBytes, _ = d.stateDB.AncientSize(rawdb.ChainFreezerBodiesTable)
|
||||
receiptBytes, _ = d.stateDB.AncientSize(rawdb.ChainFreezerReceiptTable)
|
||||
)
|
||||
syncedBytes := common.StorageSize(headerBytes + bodyBytes + receiptBytes)
|
||||
if syncedBytes == 0 {
|
||||
return
|
||||
}
|
||||
var (
|
||||
header = d.blockchain.CurrentHeader()
|
||||
block = d.blockchain.CurrentFastBlock()
|
||||
)
|
||||
syncedBlocks := block.NumberU64() - d.syncStartBlock
|
||||
if syncedBlocks == 0 {
|
||||
return
|
||||
}
|
||||
// Retrieve the current chain head and calculate the ETA
|
||||
latest, _, err := d.skeleton.Bounds()
|
||||
if err != nil {
|
||||
// We're going to cheat for non-merged networks, but that's fine
|
||||
latest = d.pivotHeader
|
||||
}
|
||||
if latest == nil {
|
||||
// This should really never happen, but add some defensive code for now.
|
||||
// TODO(karalabe): Remove it eventually if we don't see it blow.
|
||||
log.Error("Nil latest block in sync progress report")
|
||||
return
|
||||
}
|
||||
var (
|
||||
left = latest.Number.Uint64() - block.NumberU64()
|
||||
eta = time.Since(d.syncStartTime) / time.Duration(syncedBlocks) * time.Duration(left)
|
||||
|
||||
progress = fmt.Sprintf("%.2f%%", float64(block.NumberU64())*100/float64(latest.Number.Uint64()))
|
||||
headers = fmt.Sprintf("%v@%v", log.FormatLogfmtUint64(header.Number.Uint64()), common.StorageSize(headerBytes).TerminalString())
|
||||
bodies = fmt.Sprintf("%v@%v", log.FormatLogfmtUint64(block.NumberU64()), common.StorageSize(bodyBytes).TerminalString())
|
||||
receipts = fmt.Sprintf("%v@%v", log.FormatLogfmtUint64(block.NumberU64()), common.StorageSize(receiptBytes).TerminalString())
|
||||
)
|
||||
log.Info("Syncing: chain download in progress", "synced", progress, "chain", syncedBytes, "headers", headers, "bodies", bodies, "receipts", receipts, "eta", common.PrettyDuration(eta))
|
||||
d.syncLogTime = time.Now()
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ type queue struct {
|
||||
active *sync.Cond
|
||||
closed bool
|
||||
|
||||
lastStatLog time.Time
|
||||
logTime time.Time // Time instance when status was last reported
|
||||
}
|
||||
|
||||
// newQueue creates a new download queue for scheduling block retrieval.
|
||||
@@ -390,11 +390,12 @@ func (q *queue) Results(block bool) []*fetchResult {
|
||||
}
|
||||
}
|
||||
// Log some info at certain times
|
||||
if time.Since(q.lastStatLog) > 60*time.Second {
|
||||
q.lastStatLog = time.Now()
|
||||
if time.Since(q.logTime) >= 60*time.Second {
|
||||
q.logTime = time.Now()
|
||||
|
||||
info := q.Stats()
|
||||
info = append(info, "throttle", throttleThreshold)
|
||||
log.Info("Downloader queue stats", info...)
|
||||
log.Debug("Downloader queue stats", info...)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user