Files
proto/p/metrics/block_metrics.go
zeekay f480e48e39 run on the native fleet
Adds .hanzo/workflows/cicd.yml calling the canonical pipeline and drops the
GitHub-hosted workflows it replaces. Lands here because this is where the repo
is written — git.hanzo.ai is upstream and github.com is its push mirror, so the
same change made on github.com never reaches the runner fleet.
2026-08-20 20:20:25 -07:00

82 lines
1.6 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package metrics
import (
"github.com/luxfi/metric"
"github.com/luxfi/proto/p/block"
)
const blkLabel = "blk"
var (
_ block.Visitor = (*blockMetrics)(nil)
blkLabels = []string{blkLabel}
)
type blockMetrics struct {
txMetrics *txMetrics
numBlocks metric.CounterVec
}
func newBlockMetrics(registerer metric.Registerer) (*blockMetrics, error) {
txMetrics, err := newTxMetrics(registerer)
if err != nil {
return nil, err
}
m := &blockMetrics{
txMetrics: txMetrics,
numBlocks: metric.NewCounterVec(
metric.CounterOpts{
Name: "blks_accepted",
Help: "number of blocks accepted",
},
blkLabels,
),
}
return m, nil
}
func (m *blockMetrics) AbortBlock(*block.AbortBlock) error {
m.numBlocks.With(metric.Labels{
blkLabel: "abort",
}).Inc()
return nil
}
func (m *blockMetrics) CommitBlock(*block.CommitBlock) error {
m.numBlocks.With(metric.Labels{
blkLabel: "commit",
}).Inc()
return nil
}
func (m *blockMetrics) ProposalBlock(b *block.ProposalBlock) error {
m.numBlocks.With(metric.Labels{
blkLabel: "proposal",
}).Inc()
// Txs() returns the decision txs followed by the proposal tx (last).
for _, tx := range b.Txs() {
if err := tx.Unsigned.Visit(m.txMetrics); err != nil {
return err
}
}
return nil
}
func (m *blockMetrics) StandardBlock(b *block.StandardBlock) error {
m.numBlocks.With(metric.Labels{
blkLabel: "standard",
}).Inc()
for _, tx := range b.Txs() {
if err := tx.Unsigned.Visit(m.txMetrics); err != nil {
return err
}
}
return nil
}