mirror of
https://github.com/luxfi/proto.git
synced 2026-10-30 15:21:09 +00:00
Salvages Wave 1A agent's incomplete work (27 files, 387+ lines) plus the test fixups needed to make the suite green after the migration. Changes: - x/state/state_test.go: register secp256k1fx-only ParseUTXO factory so utxo.GetUTXO can decode wire bytes back to *lux.UTXO (production uses node/vms/components/lux/utxo_parser.go; test environment needs the equivalent). - x/txs/executor/semantic_verifier_test.go: update one remaining NewCustomParser call site to the new 5-arg signature (xcodectest.New + xlog.Noop). The other 3 call sites were already migrated. All proto/x and proto/p test packages now pass: ok github.com/luxfi/proto/x/state ok github.com/luxfi/proto/x/txs/executor ok github.com/luxfi/proto/p/state ok github.com/luxfi/proto/p/block/executor ok github.com/luxfi/proto/p/txs/executor proto/x codec importer count: 19 → 4. Remaining 4 are utility shims (jsonrpc numerics, metrics) — Wave 1B continuation.
97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package metrics
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/luxfi/metric"
|
|
utilmetric "github.com/luxfi/metric"
|
|
|
|
"github.com/luxfi/proto/x/block"
|
|
"github.com/luxfi/proto/x/txs"
|
|
)
|
|
|
|
var _ Metrics = (*metricsImpl)(nil)
|
|
|
|
type Metrics interface {
|
|
utilmetric.APIInterceptor
|
|
|
|
IncTxRefreshes()
|
|
IncTxRefreshHits()
|
|
IncTxRefreshMisses()
|
|
|
|
// MarkBlockAccepted updates all metrics relating to the acceptance of a
|
|
// block, including the underlying acceptance of the contained transactions.
|
|
MarkBlockAccepted(b block.Block) error
|
|
// MarkTxAccepted updates all metrics relating to the acceptance of a
|
|
// transaction.
|
|
//
|
|
// Note: This is not intended to be called during the acceptance of a block,
|
|
// as MarkBlockAccepted already handles updating transaction related
|
|
// metric.
|
|
MarkTxAccepted(tx *txs.Tx) error
|
|
}
|
|
|
|
type metricsImpl struct {
|
|
txMetrics *txMetrics
|
|
|
|
numTxRefreshes, numTxRefreshHits, numTxRefreshMisses metric.Counter
|
|
|
|
utilmetric.APIInterceptor
|
|
}
|
|
|
|
func (m *metricsImpl) IncTxRefreshes() {
|
|
m.numTxRefreshes.Inc()
|
|
}
|
|
|
|
func (m *metricsImpl) IncTxRefreshHits() {
|
|
m.numTxRefreshHits.Inc()
|
|
}
|
|
|
|
func (m *metricsImpl) IncTxRefreshMisses() {
|
|
m.numTxRefreshMisses.Inc()
|
|
}
|
|
|
|
func (m *metricsImpl) MarkBlockAccepted(b block.Block) error {
|
|
for _, tx := range b.Txs() {
|
|
if err := tx.Unsigned.Visit(m.txMetrics); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *metricsImpl) MarkTxAccepted(tx *txs.Tx) error {
|
|
return tx.Unsigned.Visit(m.txMetrics)
|
|
}
|
|
|
|
func New(registerer metric.Registerer) (Metrics, error) {
|
|
registry, ok := registerer.(metric.Registry)
|
|
if !ok {
|
|
return nil, errors.New("registerer must implement metric.Registry")
|
|
}
|
|
txMetrics, txErr := newTxMetrics(registry)
|
|
|
|
m := &metricsImpl{txMetrics: txMetrics}
|
|
|
|
m.numTxRefreshes = metric.NewCounter(metric.CounterOpts{
|
|
Name: "tx_refreshes",
|
|
Help: "Number of times unique txs have been refreshed",
|
|
})
|
|
m.numTxRefreshHits = metric.NewCounter(metric.CounterOpts{
|
|
Name: "tx_refresh_hits",
|
|
Help: "Number of times unique txs have not been unique, but were cached",
|
|
})
|
|
m.numTxRefreshMisses = metric.NewCounter(metric.CounterOpts{
|
|
Name: "tx_refresh_misses",
|
|
Help: "Number of times unique txs have not been unique and weren't cached",
|
|
})
|
|
|
|
apiRequestMetric, apiErr := utilmetric.NewAPIInterceptor(registry)
|
|
m.APIInterceptor = apiRequestMetric
|
|
// Metrics are self-registering when created with NewCounter etc.
|
|
return m, errors.Join(txErr, apiErr)
|
|
}
|