Skip to content

Commit

Permalink
feat: add block time metric (#707)
Browse files Browse the repository at this point in the history
* feat: add block time metric

* chore: auto version bump [bot]

* trigger ci

---------

Co-authored-by: Thegaram <[email protected]>
  • Loading branch information
Thegaram and Thegaram authored Apr 18, 2024
1 parent 62926d4 commit 0252f85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (
headBlockGauge = metrics.NewRegisteredGauge("chain/head/block", nil)
headHeaderGauge = metrics.NewRegisteredGauge("chain/head/header", nil)
headFastBlockGauge = metrics.NewRegisteredGauge("chain/head/receipt", nil)
headTimeGapGauge = metrics.NewRegisteredGauge("chain/head/timegap", nil)

l2BaseFeeGauge = metrics.NewRegisteredGauge("chain/fees/l2basefee", nil)

Expand Down Expand Up @@ -1255,6 +1256,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
l2BaseFeeGauge.Update(0)
}

parent := bc.GetHeaderByHash(block.ParentHash())
// block.Time is guaranteed to be larger than parent.Time,
// and the time gap should fit into int64.
gap := int64(block.Time() - parent.Time)
headTimeGapGauge.Update(gap)

// Calculate the total difficulty of the block
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
if ptd == nil {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 2 // Minor version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionPatch = 6 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down

0 comments on commit 0252f85

Please sign in to comment.