From 76145bca3f5875bebff387663933be316753899e Mon Sep 17 00:00:00 2001 From: Sanaz Taheri <35961250+staheri14@users.noreply.github.com> Date: Thu, 17 Aug 2023 13:05:54 -0700 Subject: [PATCH] feat: traces block height and timestamp for InfluxDB (#1062) ## Description To accurately gauge block time, it's essential to track the timestamps of committed blocks. The modifications made in this PR incorporate this feature. Incremental work toward https://github.com/celestiaorg/celestia-core/issues/1056 --- consensus/state.go | 3 +++ pkg/trace/schema/consensus.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/consensus/state.go b/consensus/state.go index 5cdb99a875..7eb48593c5 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1712,6 +1712,9 @@ func (cs *State) finalizeCommit(height int64) { // must be called before we update state cs.recordMetrics(height, block) + // trace some metadata about the block + schema.WriteBlock(cs.traceClient, block.Header.Height, block.Header.Time) + // NewHeightStep! cs.updateToState(stateCopy) diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 726a53d262..dc8e1a93df 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -1,6 +1,8 @@ package schema import ( + "time" + cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/pkg/trace" @@ -12,6 +14,7 @@ func ConsensusTables() []string { return []string{ RoundStateTable, BlockPartsTable, + BlockTable, } } @@ -81,3 +84,22 @@ func WriteBlockPart( TransferTypeFieldKey: transferType, }) } + +const ( + // BlockTable is the name of the table that stores metadata about consensus blocks. + // following schema: + // + // | time | height | timestamp | + BlockTable = "consensus_block_time" + + // TimestampFieldKey is the name of the field that stores the time at which + // the block is proposed. + TimestampFieldKey = "timestamp" +) + +func WriteBlock(client *trace.Client, height int64, blockTimestamp time.Time) { + client.WritePoint(BlockTable, map[string]interface{}{ + HeightFieldKey: height, + TimestampFieldKey: blockTimestamp, + }) +}