From 6451c80d5506c542587c7e0ced59fbb35c8aa94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 24 Mar 2025 19:23:08 +0100 Subject: [PATCH] fix: correctly initialize latest l1msg gauge (#1155) --- core/blockchain.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index f3b150c4cb..2b881ceed2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -149,6 +149,18 @@ var defaultCacheConfig = &CacheConfig{ SnapshotWait: true, } +func updateHeadL1msgGauge(block *types.Block) { + for _, tx := range block.Transactions() { + if msg := tx.AsL1MessageTx(); msg != nil { + // Queue index is guaranteed to fit into int64. + headL1MessageGauge.Update(int64(msg.QueueIndex)) + } else { + // No more L1 messages in this block. + break + } + } +} + // BlockChain represents the canonical chain given a database with a genesis // block. The Blockchain manages chain imports, reverts, chain reorganisations. // @@ -423,6 +435,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par triedb.SaveCachePeriodically(bc.cacheConfig.TrieCleanJournal, bc.cacheConfig.TrieCleanRejournal, bc.quit) }() } + + updateHeadL1msgGauge(bc.CurrentBlock()) + return bc, nil } @@ -1255,15 +1270,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. } // Note the latest relayed L1 message queue index (if any) - for _, tx := range block.Transactions() { - if msg := tx.AsL1MessageTx(); msg != nil { - // Queue index is guaranteed to fit into int64. - headL1MessageGauge.Update(int64(msg.QueueIndex)) - } else { - // No more L1 messages in this block. - break - } - } + updateHeadL1msgGauge(block) parent := bc.GetHeaderByHash(block.ParentHash()) // block.Time is guaranteed to be larger than parent.Time,