9
9
"time"
10
10
11
11
utils_math "github.com/ava-labs/avalanchego/utils/math"
12
+ "github.com/ava-labs/avalanchego/utils/timer"
12
13
"github.com/ava-labs/subnet-evm/metrics"
13
14
"github.com/ethereum/go-ethereum/common"
14
15
"github.com/ethereum/go-ethereum/log"
@@ -114,7 +115,7 @@ func (t *trieSyncStats) trieDone(root common.Hash) {
114
115
// updateETA calculates and logs and ETA based on the number of leafs
115
116
// currently in progress and the number of tries remaining.
116
117
// assumes lock is held.
117
- func (t * trieSyncStats ) updateETA (sinceUpdate time.Duration , now time.Time ) {
118
+ func (t * trieSyncStats ) updateETA (sinceUpdate time.Duration , now time.Time ) time. Duration {
118
119
leafsRate := float64 (t .leafsSinceUpdate ) / sinceUpdate .Seconds ()
119
120
if t .leafsRate == nil {
120
121
t .leafsRate = utils_math .NewAverager (leafsRate , leafRateHalfLife , now )
@@ -128,15 +129,17 @@ func (t *trieSyncStats) updateETA(sinceUpdate time.Duration, now time.Time) {
128
129
// provide a separate ETA for the account trie syncing step since we
129
130
// don't know the total number of storage tries yet.
130
131
log .Info ("state sync: syncing account trie" , "ETA" , roundETA (leafsTime ))
131
- return
132
+ return leafsTime
132
133
}
133
134
134
- triesTime := now .Sub (t .triesStartTime ) * time .Duration (t .triesRemaining ) / time .Duration (t .triesSynced )
135
+ triesTime := timer .EstimateETA (t .triesStartTime , uint64 (t .triesSynced ), uint64 (t .triesSynced + t .triesRemaining ))
136
+ eta := max (leafsTime , triesTime )
135
137
log .Info (
136
138
"state sync: syncing storage tries" ,
137
139
"triesRemaining" , t .triesRemaining ,
138
- "ETA" , roundETA (leafsTime + triesTime ), // TODO: should we use max instead of sum?
140
+ "ETA" , roundETA (eta ),
139
141
)
142
+ return eta
140
143
}
141
144
142
145
func (t * trieSyncStats ) setTriesRemaining (triesRemaining int ) {
0 commit comments