mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-13 19:46:39 +00:00
core: use unix time to check fork readiness (#31800)
This commit is contained in:
parent
c53db5e1f6
commit
88a7ef233a
1 changed files with 13 additions and 5 deletions
|
|
@ -2543,14 +2543,22 @@ 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(block *types.Block) {
|
func (bc *BlockChain) logForkReadiness(block *types.Block) {
|
||||||
c := bc.Config()
|
config := bc.Config()
|
||||||
current, last := c.LatestFork(block.Time()), c.LatestFork(math.MaxUint64)
|
current, last := config.LatestFork(block.Time()), config.LatestFork(math.MaxUint64)
|
||||||
t := c.Timestamp(last)
|
|
||||||
if t == nil {
|
// Short circuit if the timestamp of the last fork is undefined,
|
||||||
|
// 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)
|
||||||
if current < last && time.Now().After(bc.lastForkReadyAlert.Add(forkReadyInterval)) {
|
|
||||||
|
// Only log if:
|
||||||
|
// - Current time is before the fork activation time
|
||||||
|
// - Enough time has passed since last alert
|
||||||
|
now := time.Now()
|
||||||
|
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()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue