Skip to content

Commit

Permalink
feat: add more block stats to the block trace table (#1064)
Browse files Browse the repository at this point in the history
## Description

adds more things to the block table, see
#1062 (comment)
for further context.

part of #1056

---------

Co-authored-by: Sanaz Taheri <35961250+staheri14@users.noreply.github.com>
  • Loading branch information
evan-forbes and staheri14 committed Nov 21, 2023
1 parent f70cee2 commit 142e747
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
10 changes: 6 additions & 4 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,9 +1712,6 @@ 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 Expand Up @@ -1833,9 +1830,14 @@ func (cs *State) recordMetrics(height int64, block *types.Block) {
}
}

blockSize := block.Size()

// trace some metadata about the block
schema.WriteBlock(cs.traceClient, block, blockSize)

cs.metrics.NumTxs.Set(float64(len(block.Data.Txs)))
cs.metrics.TotalTxs.Add(float64(len(block.Data.Txs)))
cs.metrics.BlockSizeBytes.Set(float64(block.Size()))
cs.metrics.BlockSizeBytes.Set(float64(blockSize))
cs.metrics.CommittedHeight.Set(float64(block.Height))
}

Expand Down
43 changes: 34 additions & 9 deletions pkg/trace/schema/consensus.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package schema

import (
"time"

cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/pkg/trace"
"github.com/tendermint/tendermint/types"
)

// ConsensusTables returns the list of tables that are used for consensus
Expand Down Expand Up @@ -90,16 +89,42 @@ const (
// following schema:
//
// | time | height | timestamp |
BlockTable = "consensus_block_time"
BlockTable = "consensus_block"

// UnixMillisecondTimestampFieldKey is the name of the field that stores the timestamp in
// the last commit in unix milliseconds.
UnixMillisecondTimestampFieldKey = "unix_millisecond_timestamp"

// TxCountFieldKey is the name of the field that stores the number of
// transactions in the block.
TxCountFieldKey = "tx_count"

// SquareSizeFieldKey is the name of the field that stores the square size
// of the block. SquareSize is the number of shares in a single row or
// column of the origianl data square.
SquareSizeFieldKey = "square_size"

// BlockSizeFieldKey is the name of the field that stores the size of
// the block data in bytes.
BlockSizeFieldKey = "block_size"

// ProposerFieldKey is the name of the field that stores the proposer of
// the block.
ProposerFieldKey = "proposer"

// TimestampFieldKey is the name of the field that stores the time at which
// the block is proposed.
TimestampFieldKey = "timestamp"
// LastCommitRoundFieldKey is the name of the field that stores the round
// of the last commit.
LastCommitRoundFieldKey = "last_commit_round"
)

func WriteBlock(client *trace.Client, height int64, blockTimestamp time.Time) {
func WriteBlock(client *trace.Client, block *types.Block, size int) {
client.WritePoint(BlockTable, map[string]interface{}{
HeightFieldKey: height,
TimestampFieldKey: blockTimestamp,
HeightFieldKey: block.Height,
UnixMillisecondTimestampFieldKey: block.Time.UnixMilli(),
TxCountFieldKey: len(block.Data.Txs),
SquareSizeFieldKey: block.SquareSize,
BlockSizeFieldKey: size,
ProposerFieldKey: block.ProposerAddress.String(),
LastCommitRoundFieldKey: block.LastCommit.Round,
})
}

0 comments on commit 142e747

Please sign in to comment.