Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions miner/scroll_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Loading