@@ -149,6 +149,18 @@ var defaultCacheConfig = &CacheConfig{
149149 SnapshotWait : true ,
150150}
151151
152+ func updateHeadL1msgGauge (block * types.Block ) {
153+ for _ , tx := range block .Transactions () {
154+ if msg := tx .AsL1MessageTx (); msg != nil {
155+ // Queue index is guaranteed to fit into int64.
156+ headL1MessageGauge .Update (int64 (msg .QueueIndex ))
157+ } else {
158+ // No more L1 messages in this block.
159+ break
160+ }
161+ }
162+ }
163+
152164// BlockChain represents the canonical chain given a database with a genesis
153165// block. The Blockchain manages chain imports, reverts, chain reorganisations.
154166//
@@ -423,6 +435,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
423435 triedb .SaveCachePeriodically (bc .cacheConfig .TrieCleanJournal , bc .cacheConfig .TrieCleanRejournal , bc .quit )
424436 }()
425437 }
438+
439+ updateHeadL1msgGauge (bc .CurrentBlock ())
440+
426441 return bc , nil
427442}
428443
@@ -1255,15 +1270,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
12551270 }
12561271
12571272 // Note the latest relayed L1 message queue index (if any)
1258- for _ , tx := range block .Transactions () {
1259- if msg := tx .AsL1MessageTx (); msg != nil {
1260- // Queue index is guaranteed to fit into int64.
1261- headL1MessageGauge .Update (int64 (msg .QueueIndex ))
1262- } else {
1263- // No more L1 messages in this block.
1264- break
1265- }
1266- }
1273+ updateHeadL1msgGauge (block )
12671274
12681275 parent := bc .GetHeaderByHash (block .ParentHash ())
12691276 // block.Time is guaranteed to be larger than parent.Time,
0 commit comments