Skip to content

Commit

Permalink
feat: traces block height and timestamp for InfluxDB (#1062)
Browse files Browse the repository at this point in the history
## 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
#1056
  • Loading branch information
staheri14 authored Aug 17, 2023
1 parent f0446b2 commit 76145bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions pkg/trace/schema/consensus.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,6 +14,7 @@ func ConsensusTables() []string {
return []string{
RoundStateTable,
BlockPartsTable,
BlockTable,
}
}

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

0 comments on commit 76145bc

Please sign in to comment.