From 054af81725291c16902ec217f41881c8fcb2a537 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 04:54:26 +0100 Subject: [PATCH] feat: wire Metrics into service + add metrics.snapshot action Every synced block increments blocks_processed counter. Alias registrations increment aliases_found counter. Sync errors tracked separately. blockchain.metrics.snapshot returns all counters atomically. 43 total Core actions. Co-Authored-By: Charon --- actions.go | 7 +++++++ service.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/actions.go b/actions.go index 94c1cec..4b40797 100644 --- a/actions.go +++ b/actions.go @@ -667,3 +667,10 @@ func makeEstHeightAtTime(ch *chain.Chain) core.ActionHandler { return core.Result{Value: est, OK: true} } } + +// RegisterMetricsActions registers operational metrics actions. +func RegisterMetricsActions(c *core.Core, m *Metrics) { + c.Action("blockchain.metrics.snapshot", func(ctx context.Context, opts core.Options) core.Result { + return core.Result{Value: m.Snapshot(), OK: true} + }) +} diff --git a/service.go b/service.go index 17b5920..2ff9e19 100644 --- a/service.go +++ b/service.go @@ -37,6 +37,7 @@ type BlockchainService struct { store *store.Store daemon *daemon.Server events *EventBus + metrics *Metrics cancel context.CancelFunc } @@ -78,11 +79,14 @@ func (s *BlockchainService) start() core.Result { s.store = st s.chain = chain.New(st) s.events = NewEventBus() + s.metrics = NewMetrics(s.chain) - // Wire block events + // Wire block events + metrics s.chain.SetBlockCallback(func(height uint64, hash string, aliasName string) { + s.metrics.RecordBlock() s.events.Emit(Event{Type: EventBlockNew, Height: height, Data: hash}) if aliasName != "" { + s.metrics.RecordAlias() s.events.Emit(Event{Type: EventAlias, Height: height, Data: aliasName}) } })