core: polish

This commit is contained in:
Gary Rong 2025-05-13 19:52:58 +08:00
parent a61c0485ac
commit 78f154b170

View file

@ -2541,21 +2541,23 @@ func (bc *BlockChain) reportBlock(block *types.Block, res *ProcessResult, err er
// logForkReadiness will write a log when a future fork is scheduled, but not // logForkReadiness will write a log when a future fork is scheduled, but not
// active. This is useful so operators know their client is ready for the fork. // active. This is useful so operators know their client is ready for the fork.
func (bc *BlockChain) logForkReadiness() { func (bc *BlockChain) logForkReadiness(block *types.Block) {
c := bc.Config() config := bc.Config()
now := time.Now() current, last := config.LatestFork(block.Time()), config.LatestFork(math.MaxUint64)
current, last := c.LatestFork(uint64(now.Unix())), c.LatestFork(math.MaxUint64)
t := c.Timestamp(last) // Short circuit if the timestamp of the last fork is undefined,
if t == nil { // or if the network has already passed the last configured fork.
t := config.Timestamp(last)
if t == nil || current >= last {
return return
} }
at := time.Unix(int64(*t), 0) at := time.Unix(int64(*t), 0)
// Only log if: // Only log if:
// 1. Current fork is behind the latest fork // - Current time is before the fork activation time
// 2. Current time is before the fork activation time // - Enough time has passed since last alert
// 3. Enough time has passed since last alert now := time.Now()
if current < last && now.Before(at) && now.After(bc.lastForkReadyAlert.Add(forkReadyInterval)) { if now.Before(at) && now.After(bc.lastForkReadyAlert.Add(forkReadyInterval)) {
log.Info("Ready for fork activation", "fork", last, "date", at.Format(time.RFC822), log.Info("Ready for fork activation", "fork", last, "date", at.Format(time.RFC822),
"remaining", time.Until(at).Round(time.Second), "timestamp", at.Unix()) "remaining", time.Until(at).Round(time.Second), "timestamp", at.Unix())
bc.lastForkReadyAlert = time.Now() bc.lastForkReadyAlert = time.Now()