From 3411e9f87fe71ab0c9f81c75820c6525fe6f13de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Mar 2025 15:23:19 +0100 Subject: [PATCH 1/3] fix: address timing issue in system config worker --- consensus/system_contract/consensus.go | 8 ++++++-- miner/scroll_worker.go | 5 +++++ params/version.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/consensus/system_contract/consensus.go b/consensus/system_contract/consensus.go index 299577ac141f..8c7457eec869 100644 --- a/consensus/system_contract/consensus.go +++ b/consensus/system_contract/consensus.go @@ -116,8 +116,12 @@ func (s *SystemContract) verifyHeader(chain consensus.ChainHeaderReader, header } // Don't waste time checking blocks from the future - if header.Time > uint64(time.Now().Unix()) { - return consensus.ErrFutureBlock + now := time.Now() + if header.Time > uint64(now.Unix()) { + // Add 100ms leeway since the scroll_worker internal timers might trigger early. + if uint64(now.Unix())+1 != header.Time || now.Nanosecond() < 900000000 { + return consensus.ErrFutureBlock + } } // Ensure that the coinbase is zero if header.Coinbase != (common.Address{}) { diff --git a/miner/scroll_worker.go b/miner/scroll_worker.go index 2818abc761bc..3b2e05e8acb3 100644 --- a/miner/scroll_worker.go +++ b/miner/scroll_worker.go @@ -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)), diff --git a/params/version.go b/params/version.go index 6ca0a4f92b34..7e953ffe6a8b 100644 --- a/params/version.go +++ b/params/version.go @@ -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 ) From b2fb98e1a2413b0ef500504cf0383cde7302eadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Mar 2025 15:42:24 +0100 Subject: [PATCH 2/3] make code easier to understand --- consensus/system_contract/consensus.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/consensus/system_contract/consensus.go b/consensus/system_contract/consensus.go index 8c7457eec869..66178d7a87cb 100644 --- a/consensus/system_contract/consensus.go +++ b/consensus/system_contract/consensus.go @@ -115,13 +115,11 @@ func (s *SystemContract) verifyHeader(chain consensus.ChainHeaderReader, header return errUnknownBlock } - // Don't waste time checking blocks from the future + // 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()) { - // Add 100ms leeway since the scroll_worker internal timers might trigger early. - if uint64(now.Unix())+1 != header.Time || now.Nanosecond() < 900000000 { - return consensus.ErrFutureBlock - } + 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 if header.Coinbase != (common.Address{}) { From e9db4648a8fa2b045154291bcd63a841554f946b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 3 Mar 2025 16:09:59 +0100 Subject: [PATCH 3/3] add 100ms header verification grace period to Clique --- consensus/clique/clique.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index bbc90195092b..afc12326ec42 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -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