feat: add block time metric (#707)

* feat: add block time metric

* chore: auto version bump [bot]

* trigger ci

---------

Co-authored-by: Thegaram <Thegaram@users.noreply.github.com>
This commit is contained in:
Péter Garamvölgyi 2024-04-18 11:25:03 +08:00 committed by GitHub
parent 62926d4649
commit 0252f85816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -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)
@ -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 {

View file

@ -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
)