Skip to content

fix: correctly initialize latest l1msg gauge #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
Loading