eth/catalyst: adjust eta for themerge (#25601)
* eth/catalyst: adjust eta for themerge * squash * squash * eth/catalyst: address review concerns
This commit is contained in:
parent
d10c280309
commit
362256ebff
@ -564,16 +564,16 @@ func (api *ConsensusAPI) heartbeat() {
|
||||
|
||||
var (
|
||||
offlineLogged time.Time
|
||||
ttd = api.eth.BlockChain().Config().TerminalTotalDifficulty
|
||||
)
|
||||
// If the network is not yet merged/merging, don't bother continuing.
|
||||
if ttd == nil {
|
||||
return
|
||||
}
|
||||
for {
|
||||
// Sleep a bit and retrieve the last known consensus updates
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// If the network is not yet merged/merging, don't bother scaring the user
|
||||
ttd := api.eth.BlockChain().Config().TerminalTotalDifficulty
|
||||
if ttd == nil {
|
||||
continue
|
||||
}
|
||||
api.lastTransitionLock.Lock()
|
||||
lastTransitionUpdate := api.lastTransitionUpdate
|
||||
api.lastTransitionLock.Unlock()
|
||||
@ -589,7 +589,10 @@ func (api *ConsensusAPI) heartbeat() {
|
||||
// If there have been no updates for the past while, warn the user
|
||||
// that the beacon client is probably offline
|
||||
if api.eth.BlockChain().Config().TerminalTotalDifficultyPassed || api.eth.Merger().TDDReached() {
|
||||
if time.Since(lastForkchoiceUpdate) > beaconUpdateConsensusTimeout && time.Since(lastNewPayloadUpdate) > beaconUpdateConsensusTimeout {
|
||||
if time.Since(lastForkchoiceUpdate) <= beaconUpdateConsensusTimeout || time.Since(lastNewPayloadUpdate) <= beaconUpdateConsensusTimeout {
|
||||
offlineLogged = time.Time{}
|
||||
continue
|
||||
}
|
||||
if time.Since(lastTransitionUpdate) > beaconUpdateExchangeTimeout {
|
||||
if time.Since(offlineLogged) > beaconUpdateWarnFrequency {
|
||||
if lastTransitionUpdate.IsZero() {
|
||||
@ -610,68 +613,62 @@ func (api *ConsensusAPI) heartbeat() {
|
||||
offlineLogged = time.Now()
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
offlineLogged = time.Time{}
|
||||
}
|
||||
} else {
|
||||
if time.Since(lastTransitionUpdate) > beaconUpdateExchangeTimeout {
|
||||
if time.Since(lastTransitionUpdate) <= beaconUpdateExchangeTimeout {
|
||||
offlineLogged = time.Time{}
|
||||
continue
|
||||
}
|
||||
if time.Since(offlineLogged) > beaconUpdateWarnFrequency {
|
||||
// Retrieve the last few blocks and make a rough estimate as
|
||||
// to when the merge transition should happen
|
||||
var (
|
||||
chain = api.eth.BlockChain()
|
||||
head = chain.CurrentBlock()
|
||||
htd = chain.GetTd(head.Hash(), head.NumberU64())
|
||||
eta time.Duration
|
||||
head = chain.CurrentHeader()
|
||||
htd = chain.GetTd(head.Hash(), head.Number.Uint64())
|
||||
)
|
||||
if head.NumberU64() > 0 && htd.Cmp(ttd) < 0 {
|
||||
// Accumulate the last 64 difficulties to estimate the growth
|
||||
var diff float64
|
||||
|
||||
block := head
|
||||
for i := 0; i < 64; i++ {
|
||||
diff += float64(block.Difficulty().Uint64())
|
||||
if parent := chain.GetBlock(block.ParentHash(), block.NumberU64()-1); parent == nil {
|
||||
break
|
||||
if htd.Cmp(ttd) >= 0 {
|
||||
if lastTransitionUpdate.IsZero() {
|
||||
log.Warn("Merge already reached, but no beacon client seen. Please launch one to follow the chain!")
|
||||
} else {
|
||||
block = parent
|
||||
log.Warn("Merge already reached, but previously seen beacon client is offline. Please ensure it is operational to follow the chain!")
|
||||
}
|
||||
offlineLogged = time.Now()
|
||||
continue
|
||||
}
|
||||
var eta time.Duration
|
||||
if head.Number.Uint64() > 0 {
|
||||
// Accumulate the last 64 difficulties to estimate the growth
|
||||
var (
|
||||
deltaDiff uint64
|
||||
deltaTime uint64
|
||||
current = head
|
||||
)
|
||||
for i := 0; i < 64; i++ {
|
||||
parent := chain.GetHeader(current.ParentHash, current.Number.Uint64()-1)
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
deltaDiff += current.Difficulty.Uint64()
|
||||
deltaTime += current.Time - parent.Time
|
||||
current = parent
|
||||
}
|
||||
// Estimate an ETA based on the block times and the difficulty growth
|
||||
growth := diff / float64(head.Time()-block.Time()+1) // +1 to avoid div by zero
|
||||
if growth > 0 {
|
||||
if left := new(big.Int).Sub(ttd, htd); left.IsUint64() {
|
||||
eta = time.Duration(float64(left.Uint64())/growth) * time.Second
|
||||
} else {
|
||||
eta = time.Duration(new(big.Int).Div(left, big.NewInt(int64(growth))).Uint64()) * time.Second
|
||||
if deltaTime > 0 {
|
||||
growth := deltaDiff / deltaTime
|
||||
left := new(big.Int).Sub(ttd, htd)
|
||||
eta = time.Duration(new(big.Int).Div(left, new(big.Int).SetUint64(growth)).Uint64()) * time.Second
|
||||
}
|
||||
}
|
||||
}
|
||||
var message string
|
||||
if htd.Cmp(ttd) > 0 {
|
||||
if lastTransitionUpdate.IsZero() {
|
||||
message = "Merge already reached, but no beacon client seen. Please launch one to follow the chain!"
|
||||
} else {
|
||||
message = "Merge already reached, but previously seen beacon client is offline. Please ensure it is operational to follow the chain!"
|
||||
}
|
||||
} else {
|
||||
message := "Merge is configured, but previously seen beacon client is offline. Please ensure it is operational before the transition arrives!"
|
||||
if lastTransitionUpdate.IsZero() {
|
||||
message = "Merge is configured, but no beacon client seen. Please ensure you have one available before the transition arrives!"
|
||||
} else {
|
||||
message = "Merge is configured, but previously seen beacon client is offline. Please ensure it is operational before the transition arrives!"
|
||||
}
|
||||
}
|
||||
if eta == 0 {
|
||||
if eta < time.Second {
|
||||
log.Warn(message)
|
||||
} else {
|
||||
log.Warn(message, "eta", common.PrettyAge(time.Now().Add(-eta))) // weird hack, but duration formatted doesn't handle days
|
||||
}
|
||||
offlineLogged = time.Now()
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
offlineLogged = time.Time{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user