Skip to content

Commit e89a740

Browse files
jsvisagballet
authored andcommitted
core: use unix time to check fork readiness (ethereum#31800)
1 parent a43b457 commit e89a740

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

core/blockchain.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,14 +2543,22 @@ func (bc *BlockChain) reportBlock(block *types.Block, res *ProcessResult, err er
25432543
// logForkReadiness will write a log when a future fork is scheduled, but not
25442544
// active. This is useful so operators know their client is ready for the fork.
25452545
func (bc *BlockChain) logForkReadiness(block *types.Block) {
2546-
c := bc.Config()
2547-
current, last := c.LatestFork(block.Time()), c.LatestFork(math.MaxUint64)
2548-
t := c.Timestamp(last)
2549-
if t == nil {
2546+
config := bc.Config()
2547+
current, last := config.LatestFork(block.Time()), config.LatestFork(math.MaxUint64)
2548+
2549+
// Short circuit if the timestamp of the last fork is undefined,
2550+
// or if the network has already passed the last configured fork.
2551+
t := config.Timestamp(last)
2552+
if t == nil || current >= last {
25502553
return
25512554
}
25522555
at := time.Unix(int64(*t), 0)
2553-
if current < last && time.Now().After(bc.lastForkReadyAlert.Add(forkReadyInterval)) {
2556+
2557+
// Only log if:
2558+
// - Current time is before the fork activation time
2559+
// - Enough time has passed since last alert
2560+
now := time.Now()
2561+
if now.Before(at) && now.After(bc.lastForkReadyAlert.Add(forkReadyInterval)) {
25542562
log.Info("Ready for fork activation", "fork", last, "date", at.Format(time.RFC822),
25552563
"remaining", time.Until(at).Round(time.Second), "timestamp", at.Unix())
25562564
bc.lastForkReadyAlert = time.Now()

0 commit comments

Comments
 (0)