From 3186613c9f0dada02ab72600e7da076cf8cb5960 Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:24:20 +0800 Subject: [PATCH 1/3] skip messages with lower index --- rollup/sync_service/sync_service.go | 35 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/rollup/sync_service/sync_service.go b/rollup/sync_service/sync_service.go index 65743b5e7e36..4bda53ace4ac 100644 --- a/rollup/sync_service/sync_service.go +++ b/rollup/sync_service/sync_service.go @@ -1,6 +1,7 @@ package sync_service import ( + "bytes" "context" "fmt" "reflect" @@ -15,6 +16,7 @@ import ( "github.com/scroll-tech/go-ethereum/metrics" "github.com/scroll-tech/go-ethereum/node" "github.com/scroll-tech/go-ethereum/params" + "github.com/scroll-tech/go-ethereum/rlp" ) const ( @@ -82,7 +84,8 @@ func NewSyncService(ctx context.Context, genesisConfig *params.ChainConfig, node // otherwise there's no way for the node to know if it missed any messages of the V2 queue (as it was not querying it before) // but continued to query the V1 queue (which after V2 deployment does not contain any messages anymore). // this is a one-time operation and will not be repeated on subsequent restarts. - if genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock > 0 && + if genesisConfig.IsEuclidV2(uint64(time.Now().Unix())) && + genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock > 0 && genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock < latestProcessedBlock { // node synced after V2 deployment // this means the node has never synced V2 messages before -> we need to reset the synced height to re-fetch V2 messages. @@ -272,19 +275,43 @@ func (s *SyncService) fetchMessages() { if len(msgs) > 0 { log.Debug("Received new L1 events", "fromBlock", from, "toBlock", to, "count", len(msgs)) - rawdb.WriteL1Messages(batchWriter, msgs) // collect messages in memory - numMsgsCollected += len(msgs) } for _, msg := range msgs { if msg.QueueIndex > 0 { queueIndex++ } + // check if received queue index matches expected queue index - if msg.QueueIndex != queueIndex { + if msg.QueueIndex > queueIndex { log.Error("Unexpected queue index in SyncService", "expected", queueIndex, "got", msg.QueueIndex, "msg", msg) return // do not flush inconsistent data to disk } + + // compare with stored message in database, abort if not equal, ignore if already exists + if msg.QueueIndex < queueIndex { + log.Info("Duplicate queue index in SyncService", "expected", queueIndex, "got", msg.QueueIndex) + + receivedMsgBytes, err := rlp.EncodeToBytes(msg) + if err != nil { + log.Error("Failed to encode message", "err", err) + return + } + storedMsgBytes := rawdb.ReadL1MessageRLP(s.db, msg.QueueIndex) + if !bytes.Equal(storedMsgBytes, receivedMsgBytes) { + storedL1Message := rawdb.ReadL1Message(s.db, msg.QueueIndex) + log.Error("Stored message at same queue index does not match received message", "queueIndex", msg.QueueIndex, "expected", storedL1Message, "got", msg) + return + } + + // already exists, ignore + queueIndex-- + continue + } + + // store message to database (collected in memory and flushed periodically) + rawdb.WriteL1Message(batchWriter, msg) + numMsgsCollected++ } numBlocksPendingDbWrite += to - from + 1 From 3a795b9aa549948ab4da965be9933f5d3e0c3db6 Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:50:19 +0800 Subject: [PATCH 2/3] address review comments --- rollup/sync_service/sync_service.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rollup/sync_service/sync_service.go b/rollup/sync_service/sync_service.go index 4bda53ace4ac..a8edba793b80 100644 --- a/rollup/sync_service/sync_service.go +++ b/rollup/sync_service/sync_service.go @@ -84,8 +84,7 @@ func NewSyncService(ctx context.Context, genesisConfig *params.ChainConfig, node // otherwise there's no way for the node to know if it missed any messages of the V2 queue (as it was not querying it before) // but continued to query the V1 queue (which after V2 deployment does not contain any messages anymore). // this is a one-time operation and will not be repeated on subsequent restarts. - if genesisConfig.IsEuclidV2(uint64(time.Now().Unix())) && - genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock > 0 && + if genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock > 0 && genesisConfig.Scroll.L1Config.L1MessageQueueV2DeploymentBlock < latestProcessedBlock { // node synced after V2 deployment // this means the node has never synced V2 messages before -> we need to reset the synced height to re-fetch V2 messages. @@ -290,7 +289,7 @@ func (s *SyncService) fetchMessages() { // compare with stored message in database, abort if not equal, ignore if already exists if msg.QueueIndex < queueIndex { - log.Info("Duplicate queue index in SyncService", "expected", queueIndex, "got", msg.QueueIndex) + log.Warn("Duplicate queue index in SyncService", "expected", queueIndex, "got", msg.QueueIndex) receivedMsgBytes, err := rlp.EncodeToBytes(msg) if err != nil { From 548496bb74130a419dcdc07a821acee1cc048266 Mon Sep 17 00:00:00 2001 From: Thegaram Date: Wed, 5 Mar 2025 09:59:19 +0000 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[bot?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- params/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/version.go b/params/version.go index 1e641d4b5722..6badac58f821 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 = 20 // Patch version component of the current release + VersionPatch = 21 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )