From e70a07cc988f0fe8a4e5f886dc41e828a339e470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Sun, 6 Aug 2023 15:48:03 +0200 Subject: [PATCH] fix: Initialize nextL1MsgIndex before commit (#444) * initialize nextL1MsgIndex before commit * bump version --------- Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> --- miner/worker.go | 26 +++++++++++--------------- params/version.go | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index e9cb1e9f98..167d293042 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -792,7 +792,14 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error { env.tcount = 0 env.blockSize = 0 env.l1TxCount = 0 - env.nextL1MsgIndex = 0 // initialized in commitNewWork + + // find next L1 message queue index + nextQueueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(w.eth.ChainDb(), parent.Hash()) + if nextQueueIndex == nil { + // the parent must have been processed before we start a new mining job. + log.Crit("Failed to read last L1 message in L2 block", "parent.Hash()", parent.Hash().String()) + } + env.nextL1MsgIndex = *nextQueueIndex // Swap out the old work with the new one, terminating any leftover prefetcher // processes in the mean time and starting a new one. @@ -1086,15 +1093,9 @@ loop: return false, circuitCapacityReached } -func (w *worker) collectPendingL1Messages() (uint64, []types.L1MessageTx) { - nextQueueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(w.eth.ChainDb(), w.chain.CurrentHeader().Hash()) - if nextQueueIndex == nil { - // the parent (w.chain.CurrentHeader) must have been processed before we start a new mining job. - log.Crit("Failed to read last L1 message in L2 block", "l2BlockHash", w.chain.CurrentHeader().Hash()) - } - startIndex := *nextQueueIndex +func (w *worker) collectPendingL1Messages(startIndex uint64) []types.L1MessageTx { maxCount := w.chainConfig.Scroll.L1Config.NumL1MessagesPerBlock - return startIndex, rawdb.ReadL1MessagesFrom(w.eth.ChainDb(), startIndex, maxCount) + return rawdb.ReadL1MessagesFrom(w.eth.ChainDb(), startIndex, maxCount) } // commitNewWork generates several new sealing tasks based on the parent block. @@ -1203,12 +1204,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) l1Txs := make(map[common.Address]types.Transactions) pendingL1Txs := 0 if w.chainConfig.Scroll.ShouldIncludeL1Messages() { - nextQueueIndex, l1Messages := w.collectPendingL1Messages() - - // If l1Messages is empty, we should still set this - // to the same value as the parent block. - env.nextL1MsgIndex = nextQueueIndex - + l1Messages := w.collectPendingL1Messages(env.nextL1MsgIndex) pendingL1Txs = len(l1Messages) for _, l1msg := range l1Messages { tx := types.NewTx(&l1msg) diff --git a/params/version.go b/params/version.go index 6d75a0d05a..3b20f1e61d 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 4 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 24 // Patch version component of the current release + VersionPatch = 25 // Patch version component of the current release VersionMeta = "sepolia" // Version metadata to append to the version string )