From 0252f85816e363078e9aa25bf6102f542ef5fe1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Thu, 18 Apr 2024 11:25:03 +0800 Subject: [PATCH] feat: add block time metric (#707) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add block time metric * chore: auto version bump [bot] * trigger ci --------- Co-authored-by: Thegaram --- core/blockchain.go | 7 +++++++ params/version.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index add957a944..61809163af 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 { diff --git a/params/version.go b/params/version.go index 312f2dae31..1d7d525e3a 100644 --- a/params/version.go +++ b/params/version.go @@ -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 )