fix: accept header at most 100ms earlier than timestamp (#1129)

* fix: address timing issue in system config worker

* make code easier to understand

* add 100ms header verification grace period to Clique
This commit is contained in:
Péter Garamvölgyi 2025-03-03 16:31:57 +01:00 committed by GitHub
parent 40ebbd6491
commit 748fb82899
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 5 deletions

View file

@ -254,8 +254,10 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
}
number := header.Number.Uint64()
// Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) {
// Don't waste time checking blocks from the future.
// We add 100ms leeway since the scroll_worker internal timers might trigger early.
now := time.Now()
if header.Time > uint64(now.Unix()) && time.Unix(int64(header.Time), 0).Sub(now) > 100*time.Millisecond {
return consensus.ErrFutureBlock
}
// Checkpoint blocks need to enforce zero beneficiary

View file

@ -115,8 +115,10 @@ func (s *SystemContract) verifyHeader(chain consensus.ChainHeaderReader, header
return errUnknownBlock
}
// Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) {
// Don't waste time checking blocks from the future.
// We add 100ms leeway since the scroll_worker internal timers might trigger early.
now := time.Now()
if header.Time > uint64(now.Unix()) && time.Unix(int64(header.Time), 0).Sub(now) > 100*time.Millisecond {
return consensus.ErrFutureBlock
}
// Ensure that the coinbase is zero

View file

@ -464,6 +464,7 @@ func (w *worker) collectPendingL1Messages(startIndex uint64) []types.L1MessageTx
if len(l1MessagesV1) > 0 {
// backdate the block to the parent block's timestamp -> not yet EuclidV2
// TODO: might need to re-run Prepare here
log.Warn("Back-labeling header timestamp to ensure it precedes the EuclidV2 transition", "blockNumber", w.current.header.Number, "oldTime", w.current.header.Time, "newTime", parent.Time)
w.current.header.Time = parent.Time
return l1MessagesV1
}
@ -541,6 +542,10 @@ func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, r
// clique with relaxed period uses time.Now() as the header.Time, calculate the deadline
deadline = time.Unix(int64(header.Time+w.chainConfig.Clique.Period), 0)
}
if w.chainConfig.SystemContract != nil && w.chainConfig.SystemContract.RelaxedPeriod {
// system contract with relaxed period uses time.Now() as the header.Time, calculate the deadline
deadline = time.Unix(int64(header.Time+w.chainConfig.SystemContract.Period), 0)
}
w.current = &work{
deadlineTimer: time.NewTimer(time.Until(deadline)),

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 8 // Minor version component of the current release
VersionPatch = 18 // Patch version component of the current release
VersionPatch = 19 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)