Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in state sync eta #1195

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add UT
  • Loading branch information
darioush committed May 29, 2024
commit ef8eea18a9c8cf76aeafca121041879470e9c1eb
8 changes: 5 additions & 3 deletions sync/statesync/trie_sync_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (t *trieSyncStats) trieDone(root common.Hash) {
// updateETA calculates and logs and ETA based on the number of leafs
// currently in progress and the number of tries remaining.
// assumes lock is held.
func (t *trieSyncStats) updateETA(sinceUpdate time.Duration, now time.Time) {
func (t *trieSyncStats) updateETA(sinceUpdate time.Duration, now time.Time) time.Duration {
leafsRate := float64(t.leafsSinceUpdate) / sinceUpdate.Seconds()
if t.leafsRate == nil {
t.leafsRate = utils_math.NewAverager(leafsRate, leafRateHalfLife, now)
Expand All @@ -128,15 +128,17 @@ func (t *trieSyncStats) updateETA(sinceUpdate time.Duration, now time.Time) {
// provide a separate ETA for the account trie syncing step since we
// don't know the total number of storage tries yet.
log.Info("state sync: syncing account trie", "ETA", roundETA(leafsTime))
return
return leafsTime
}

triesTime := now.Sub(t.triesStartTime) * time.Duration(t.triesRemaining/t.triesSynced)
ceyonur marked this conversation as resolved.
Show resolved Hide resolved
eta := leafsTime + triesTime // TODO: should we use max instead of sum?
tsachiherman marked this conversation as resolved.
Show resolved Hide resolved
log.Info(
"state sync: syncing storage tries",
"triesRemaining", t.triesRemaining,
"ETA", roundETA(leafsTime+triesTime), // TODO: should we use max instead of sum?
"ETA", roundETA(eta),
)
return eta
}

func (t *trieSyncStats) setTriesRemaining(triesRemaining int) {
Expand Down
26 changes: 26 additions & 0 deletions sync/statesync/trie_sync_stats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// (c) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package statesync

import (
"testing"
"time"

"github.com/ava-labs/subnet-evm/metrics"
"github.com/stretchr/testify/require"
)

func TestETAShouldNotOverflow(t *testing.T) {
require := require.New(t)
now := time.Now()
start := now.Add(-6 * time.Hour)

stats := &trieSyncStats{
triesStartTime: start,
triesSynced: 100_000,
triesRemaining: 450_000,
leafsRateGauge: metrics.NilGauge{},
}
require.Positive(stats.updateETA(time.Minute, now))
}
Loading