From 8167e2a22cfc9f32a08a59a28dd72d4f658d15c3 Mon Sep 17 00:00:00 2001 From: satushh Date: Thu, 27 Nov 2025 17:59:19 +0000 Subject: [PATCH 01/11] eas metric + GetCustodyInfo for restarts --- beacon-chain/custody/BUILD.bazel | 13 ++++++++ beacon-chain/custody/metrics.go | 32 +++++++++++++++++++ beacon-chain/db/iface/interface.go | 1 + beacon-chain/db/kv/BUILD.bazel | 1 + beacon-chain/db/kv/custody.go | 46 ++++++++++++++++++++++++++++ beacon-chain/p2p/BUILD.bazel | 1 + beacon-chain/p2p/custody.go | 15 +++++++++ beacon-chain/p2p/testing/BUILD.bazel | 1 + beacon-chain/p2p/testing/p2p.go | 3 ++ beacon-chain/sync/BUILD.bazel | 6 ++++ beacon-chain/sync/custody.go | 39 ++++++++++++++++++++--- beacon-chain/sync/metrics.go | 11 ------- 12 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 beacon-chain/custody/BUILD.bazel create mode 100644 beacon-chain/custody/metrics.go diff --git a/beacon-chain/custody/BUILD.bazel b/beacon-chain/custody/BUILD.bazel new file mode 100644 index 000000000000..88b7fb81bd76 --- /dev/null +++ b/beacon-chain/custody/BUILD.bazel @@ -0,0 +1,13 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["metrics.go"], + importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/custody", + visibility = ["//visibility:public"], + deps = [ + "//consensus-types/primitives:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", + ], +) diff --git a/beacon-chain/custody/metrics.go b/beacon-chain/custody/metrics.go new file mode 100644 index 000000000000..cf61ae2fa53c --- /dev/null +++ b/beacon-chain/custody/metrics.go @@ -0,0 +1,32 @@ +// Package custody provides common custody-related metrics +package custody + +import ( + "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + // EarliestAvailableSlotP2P tracks the earliest available slot in the p2p service + EarliestAvailableSlotP2P = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "custody_earliest_available_slot_p2p", + Help: "The earliest available slot tracked by the p2p service for custody purposes", + }) + + // EarliestAvailableSlotDB tracks the earliest available slot in the database + EarliestAvailableSlotDB = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "custody_earliest_available_slot_db", + Help: "The earliest available slot tracked by the database for custody purposes", + }) +) + +// UpdateP2PMetric updates the P2P earliest available slot metric +func UpdateP2PMetric(slot primitives.Slot) { + EarliestAvailableSlotP2P.Set(float64(slot)) +} + +// UpdateDBMetric updates the DB earliest available slot metric +func UpdateDBMetric(slot primitives.Slot) { + EarliestAvailableSlotDB.Set(float64(slot)) +} \ No newline at end of file diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index 179e9b46f287..8ab5905b6f2a 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -129,6 +129,7 @@ type NoHeadAccessDatabase interface { // Custody operations. UpdateSubscribedToAllDataSubnets(ctx context.Context, subscribed bool) (bool, error) + GetCustodyInfo(ctx context.Context) (primitives.Slot, uint64, error) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot primitives.Slot, custodyGroupCount uint64) (primitives.Slot, uint64, error) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailableSlot primitives.Slot) error diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 503682265773..901c4acb2a4d 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -40,6 +40,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/core/blocks:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/iface:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/db/kv/custody.go b/beacon-chain/db/kv/custody.go index 3655b632d10d..3e2098f2db42 100644 --- a/beacon-chain/db/kv/custody.go +++ b/beacon-chain/db/kv/custody.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" @@ -14,6 +15,44 @@ import ( bolt "go.etcd.io/bbolt" ) +// GetCustodyInfo retrieves the current custody info without updating it. +// This is a read-only operation that also updates the DB metric. +func (s *Store) GetCustodyInfo(ctx context.Context) (primitives.Slot, uint64, error) { + _, span := trace.StartSpan(ctx, "BeaconDB.GetCustodyInfo") + defer span.End() + + var storedGroupCount uint64 + var storedEarliestAvailableSlot primitives.Slot + + if err := s.db.View(func(tx *bolt.Tx) error { + bucket := tx.Bucket(custodyBucket) + if bucket == nil { + return nil + } + + // Retrieve the stored custody group count. + storedGroupCountBytes := bucket.Get(groupCountKey) + if len(storedGroupCountBytes) != 0 { + storedGroupCount = bytesutil.BytesToUint64BigEndian(storedGroupCountBytes) + } + + // Retrieve the stored earliest available slot. + storedEarliestAvailableSlotBytes := bucket.Get(earliestAvailableSlotKey) + if len(storedEarliestAvailableSlotBytes) != 0 { + storedEarliestAvailableSlot = primitives.Slot(bytesutil.BytesToUint64BigEndian(storedEarliestAvailableSlotBytes)) + } + + return nil + }); err != nil { + return 0, 0, err + } + + // Update the DB metric with the current value + custody.UpdateDBMetric(storedEarliestAvailableSlot) + + return storedEarliestAvailableSlot, storedGroupCount, nil +} + // UpdateCustodyInfo atomically updates the custody group count only if it is greater than the stored one. // In this case, it also updates the earliest available slot with the provided value. // It returns the (potentially updated) custody group count and earliest available slot. @@ -70,6 +109,10 @@ func (s *Store) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot pri "groupCount": storedGroupCount, }).Debug("Custody info") + // Update the DB metric whenever we log the custody info + // This ensures the metric is always in sync with what we log + custody.UpdateDBMetric(storedEarliestAvailableSlot) + return storedEarliestAvailableSlot, storedGroupCount, nil } @@ -143,6 +186,9 @@ func (s *Store) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailab log.WithField("earliestAvailableSlot", storedEarliestAvailableSlot).Debug("Updated earliest available slot") + // Update DB metric after successfully updating the earliest available slot + custody.UpdateDBMetric(storedEarliestAvailableSlot) + return nil } diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 5f7866fad472..63f43c52017d 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -48,6 +48,7 @@ go_library( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/peerdas:go_default_library", "//beacon-chain/core/time:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/kv:go_default_library", "//beacon-chain/p2p/encoder:go_default_library", diff --git a/beacon-chain/p2p/custody.go b/beacon-chain/p2p/custody.go index fe4c9ffeb709..5bfc2a68f876 100644 --- a/beacon-chain/p2p/custody.go +++ b/beacon-chain/p2p/custody.go @@ -4,6 +4,7 @@ import ( "context" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" + "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" "github.com/OffchainLabs/prysm/v7/time/slots" @@ -22,6 +23,9 @@ func (s *Service) EarliestAvailableSlot(ctx context.Context) (primitives.Slot, e return 0, errors.Wrap(err, "wait for custody info") } + // Update metric whenever the value is accessed + custody.UpdateP2PMetric(custodyInfo.earliestAvailableSlot) + return custodyInfo.earliestAvailableSlot, nil } @@ -80,11 +84,15 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo close(s.custodyInfoSet) + // Update P2P metric when initializing custody info + custody.UpdateP2PMetric(earliestAvailableSlot) + return earliestAvailableSlot, custodyGroupCount, nil } inMemory := s.custodyInfo if custodyGroupCount <= inMemory.groupCount { + custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) return inMemory.earliestAvailableSlot, inMemory.groupCount, nil } @@ -97,6 +105,7 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if custodyGroupCount <= samplesPerSlot { inMemory.groupCount = custodyGroupCount + custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } @@ -107,11 +116,15 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if earliestAvailableSlot < fuluForkSlot { inMemory.groupCount = custodyGroupCount + custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } inMemory.earliestAvailableSlot = earliestAvailableSlot inMemory.groupCount = custodyGroupCount + + custody.UpdateP2PMetric(earliestAvailableSlot) + return earliestAvailableSlot, custodyGroupCount, nil } @@ -133,6 +146,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S // Allow decrease (for backfill scenarios) if earliestAvailableSlot < s.custodyInfo.earliestAvailableSlot { s.custodyInfo.earliestAvailableSlot = earliestAvailableSlot + custody.UpdateP2PMetric(earliestAvailableSlot) return nil } @@ -163,6 +177,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S } s.custodyInfo.earliestAvailableSlot = earliestAvailableSlot + custody.UpdateP2PMetric(earliestAvailableSlot) return nil } diff --git a/beacon-chain/p2p/testing/BUILD.bazel b/beacon-chain/p2p/testing/BUILD.bazel index 2aee33be0cd5..0f1f76c74cbb 100644 --- a/beacon-chain/p2p/testing/BUILD.bazel +++ b/beacon-chain/p2p/testing/BUILD.bazel @@ -20,6 +20,7 @@ go_library( ], deps = [ "//beacon-chain/core/peerdas:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/p2p/encoder:go_default_library", "//beacon-chain/p2p/peers:go_default_library", "//beacon-chain/p2p/peers/scorers:go_default_library", diff --git a/beacon-chain/p2p/testing/p2p.go b/beacon-chain/p2p/testing/p2p.go index f31fb31f3042..bca1ee795a92 100644 --- a/beacon-chain/p2p/testing/p2p.go +++ b/beacon-chain/p2p/testing/p2p.go @@ -12,6 +12,7 @@ import ( "time" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" + "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/encoder" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/peers" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/peers/scorers" @@ -496,6 +497,8 @@ func (s *TestP2P) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo s.earliestAvailableSlot = earliestAvailableSlot s.custodyGroupCount = custodyGroupCount + custody.UpdateP2PMetric(earliestAvailableSlot) + return s.earliestAvailableSlot, s.custodyGroupCount, nil } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index b97bc91850ba..c6bddd31f07f 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -85,6 +85,7 @@ go_library( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/interop:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", "//beacon-chain/db/filters:go_default_library", @@ -166,6 +167,8 @@ go_test( "blobs_test.go", "block_batcher_test.go", "context_test.go", + "custody_metrics_bug_test.go", + "custody_metrics_test.go", "custody_test.go", "data_column_sidecars_test.go", "data_columns_reconstruct_test.go", @@ -231,6 +234,7 @@ go_test( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", "//beacon-chain/db/kv:go_default_library", @@ -296,6 +300,8 @@ go_test( "@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_model//go:go_default_library", "@com_github_prysmaticlabs_fastssz//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/beacon-chain/sync/custody.go b/beacon-chain/sync/custody.go index 473b0a2ce992..5ee8cff8c855 100644 --- a/beacon-chain/sync/custody.go +++ b/beacon-chain/sync/custody.go @@ -7,6 +7,7 @@ import ( "github.com/OffchainLabs/prysm/v7/async" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" + "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p" "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/flags" "github.com/OffchainLabs/prysm/v7/config/params" @@ -43,6 +44,22 @@ func (s *Service) updateCustodyInfoIfNeeded() error { // If the actual custody group count is already equal to the target, skip the update. if actualCustodyGrounpCount >= targetCustodyGroupCount { + // Refresh metrics when no update is needed (e.g., after restart) + // This ensures metrics are populated even when custody info doesn't need updating + ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) + defer cancel() + + // Refresh P2P metric + if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { + custody.UpdateP2PMetric(slot) + } + + // Refresh DB metric using read-only operation + if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { + // GetCustodyInfo already updates the metric internally + log.WithError(err).Debug("Failed to get custody info for metrics") + } + return nil } @@ -66,6 +83,22 @@ func (s *Service) updateCustodyInfoIfNeeded() error { } if !enoughPeers { + // Refresh metrics when insufficient peers (e.g., after restart) + // This ensures metrics are populated even when we can't update due to peer constraints + ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) + defer cancel() + + // Refresh P2P metric + if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { + custody.UpdateP2PMetric(slot) + } + + // Refresh DB metric using read-only operation + if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { + // GetCustodyInfo already updates the metric internally + log.WithError(err).Debug("Failed to get custody info for metrics") + } + return nil } @@ -80,16 +113,12 @@ func (s *Service) updateCustodyInfoIfNeeded() error { return errors.Wrap(err, "p2p update custody info") } - // Update the p2p earliest available slot metric - earliestAvailableSlotP2P.Set(float64(storedEarliestSlot)) - dbEarliestSlot, _, err := s.cfg.beaconDB.UpdateCustodyInfo(s.ctx, storedEarliestSlot, storedGroupCount) + _, _, err = s.cfg.beaconDB.UpdateCustodyInfo(s.ctx, storedEarliestSlot, storedGroupCount) if err != nil { return errors.Wrap(err, "beacon db update custody info") } - // Update the DB earliest available slot metric - earliestAvailableSlotDB.Set(float64(dbEarliestSlot)) return nil } diff --git a/beacon-chain/sync/metrics.go b/beacon-chain/sync/metrics.go index bce143e7929d..666bd65346b8 100644 --- a/beacon-chain/sync/metrics.go +++ b/beacon-chain/sync/metrics.go @@ -236,17 +236,6 @@ var ( Buckets: []float64{100, 250, 500, 750, 1000, 1500, 2000, 4000, 8000, 12000, 16000}, }, ) - - // Custody earliest available slot metrics - earliestAvailableSlotP2P = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_p2p", - Help: "The earliest available slot tracked by the p2p service for custody purposes", - }) - - earliestAvailableSlotDB = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_db", - Help: "The earliest available slot tracked by the database for custody purposes", - }) ) func (s *Service) updateMetrics() { From 730f31d346c6a3e36ad0481b54d624c077a7d03b Mon Sep 17 00:00:00 2001 From: satushh Date: Thu, 27 Nov 2025 18:07:17 +0000 Subject: [PATCH 02/11] bazel run //:gazelle -- fix --- beacon-chain/sync/BUILD.bazel | 5 ----- 1 file changed, 5 deletions(-) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index c6bddd31f07f..1eaf8c5776b4 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -167,8 +167,6 @@ go_test( "blobs_test.go", "block_batcher_test.go", "context_test.go", - "custody_metrics_bug_test.go", - "custody_metrics_test.go", "custody_test.go", "data_column_sidecars_test.go", "data_columns_reconstruct_test.go", @@ -234,7 +232,6 @@ go_test( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", "//beacon-chain/db/kv:go_default_library", @@ -300,8 +297,6 @@ go_test( "@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", "@com_github_pkg_errors//:go_default_library", - "@com_github_prometheus_client_golang//prometheus:go_default_library", - "@com_github_prometheus_client_model//go:go_default_library", "@com_github_prysmaticlabs_fastssz//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", From 37764704fed3197c0bbfbef2879ad713319b3681 Mon Sep 17 00:00:00 2001 From: satushh Date: Thu, 27 Nov 2025 18:09:06 +0000 Subject: [PATCH 03/11] format --- beacon-chain/custody/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon-chain/custody/metrics.go b/beacon-chain/custody/metrics.go index cf61ae2fa53c..e55a75827b84 100644 --- a/beacon-chain/custody/metrics.go +++ b/beacon-chain/custody/metrics.go @@ -29,4 +29,4 @@ func UpdateP2PMetric(slot primitives.Slot) { // UpdateDBMetric updates the DB earliest available slot metric func UpdateDBMetric(slot primitives.Slot) { EarliestAvailableSlotDB.Set(float64(slot)) -} \ No newline at end of file +} From 72c75bce8375cb30b393dfef9678f8563b856809 Mon Sep 17 00:00:00 2001 From: satushh Date: Thu, 27 Nov 2025 18:10:39 +0000 Subject: [PATCH 04/11] changelog --- changelog/satushh-eas-metric-2.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/satushh-eas-metric-2.md diff --git a/changelog/satushh-eas-metric-2.md b/changelog/satushh-eas-metric-2.md new file mode 100644 index 000000000000..c1ec725ebc41 --- /dev/null +++ b/changelog/satushh-eas-metric-2.md @@ -0,0 +1,3 @@ +### Added + +- Metric for earliest available slot. \ No newline at end of file From d4f5dc982378bf4b96084be46ab4f87e46f38503 Mon Sep 17 00:00:00 2001 From: satushh Date: Thu, 27 Nov 2025 18:42:23 +0000 Subject: [PATCH 05/11] tidy up --- beacon-chain/sync/custody.go | 50 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/beacon-chain/sync/custody.go b/beacon-chain/sync/custody.go index 29fcb01dbf3e..ee64d8da2571 100644 --- a/beacon-chain/sync/custody.go +++ b/beacon-chain/sync/custody.go @@ -27,6 +27,24 @@ func (s *Service) maintainCustodyInfo() { }) } +// refreshCustodyMetrics refreshes both P2P and DB custody metrics with current values. +// This is used in early return paths to ensure metrics are populated even when no update occurs. +func (s *Service) refreshCustodyMetrics() { + ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) + defer cancel() + + // Refresh P2P metric + if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { + custody.UpdateP2PMetric(slot) + } + + // Refresh DB metric using read-only operation + if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { + // GetCustodyInfo already updates the metric internally + log.WithError(err).Debug("Failed to get custody info for metrics") + } +} + func (s *Service) updateCustodyInfoIfNeeded() error { const minimumPeerCount = 1 @@ -45,21 +63,7 @@ func (s *Service) updateCustodyInfoIfNeeded() error { // If the actual custody group count is already equal to the target, skip the update. if actualCustodyGrounpCount >= targetCustodyGroupCount { // Refresh metrics when no update is needed (e.g., after restart) - // This ensures metrics are populated even when custody info doesn't need updating - ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) - defer cancel() - - // Refresh P2P metric - if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { - custody.UpdateP2PMetric(slot) - } - - // Refresh DB metric using read-only operation - if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { - // GetCustodyInfo already updates the metric internally - log.WithError(err).Debug("Failed to get custody info for metrics") - } - + s.refreshCustodyMetrics() return nil } @@ -84,21 +88,7 @@ func (s *Service) updateCustodyInfoIfNeeded() error { if !enoughPeers { // Refresh metrics when insufficient peers (e.g., after restart) - // This ensures metrics are populated even when we can't update due to peer constraints - ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) - defer cancel() - - // Refresh P2P metric - if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { - custody.UpdateP2PMetric(slot) - } - - // Refresh DB metric using read-only operation - if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { - // GetCustodyInfo already updates the metric internally - log.WithError(err).Debug("Failed to get custody info for metrics") - } - + s.refreshCustodyMetrics() return nil } From 2cfce7265e403903ff4c0b059a83ec51cde9642c Mon Sep 17 00:00:00 2001 From: satushh Date: Fri, 28 Nov 2025 13:50:31 +0000 Subject: [PATCH 06/11] remove unwanted refreshCustodyMetrics and update db metric during startup --- beacon-chain/blockchain/BUILD.bazel | 1 + beacon-chain/blockchain/service.go | 3 +++ beacon-chain/sync/BUILD.bazel | 1 - beacon-chain/sync/custody.go | 23 ----------------------- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 7f89e64c277f..cb3f5222b589 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -54,6 +54,7 @@ go_library( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", + "//beacon-chain/custody:go_default_library", "//beacon-chain/das:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 71d7c20b8494..46becc6bfef0 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -12,6 +12,7 @@ import ( "github.com/OffchainLabs/prysm/v7/async/event" "github.com/OffchainLabs/prysm/v7/beacon-chain/blockchain/kzg" "github.com/OffchainLabs/prysm/v7/beacon-chain/cache" + "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" statefeed "github.com/OffchainLabs/prysm/v7/beacon-chain/core/feed/state" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" @@ -300,6 +301,8 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error { return errors.Wrap(err, "could not get and save custody group count") } + custody.UpdateDBMetric(earliestAvailableSlot) + if _, _, err := s.cfg.P2P.UpdateCustodyInfo(earliestAvailableSlot, custodySubnetCount); err != nil { return errors.Wrap(err, "update custody info") } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 1eaf8c5776b4..b97bc91850ba 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -85,7 +85,6 @@ go_library( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/interop:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", "//beacon-chain/db/filters:go_default_library", diff --git a/beacon-chain/sync/custody.go b/beacon-chain/sync/custody.go index ee64d8da2571..3b7767243f12 100644 --- a/beacon-chain/sync/custody.go +++ b/beacon-chain/sync/custody.go @@ -7,7 +7,6 @@ import ( "github.com/OffchainLabs/prysm/v7/async" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" - "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p" "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/flags" "github.com/OffchainLabs/prysm/v7/config/params" @@ -27,24 +26,6 @@ func (s *Service) maintainCustodyInfo() { }) } -// refreshCustodyMetrics refreshes both P2P and DB custody metrics with current values. -// This is used in early return paths to ensure metrics are populated even when no update occurs. -func (s *Service) refreshCustodyMetrics() { - ctx, cancel := context.WithTimeout(s.ctx, 1*time.Second) - defer cancel() - - // Refresh P2P metric - if slot, err := s.cfg.p2p.EarliestAvailableSlot(ctx); err == nil { - custody.UpdateP2PMetric(slot) - } - - // Refresh DB metric using read-only operation - if _, _, err := s.cfg.beaconDB.GetCustodyInfo(ctx); err != nil { - // GetCustodyInfo already updates the metric internally - log.WithError(err).Debug("Failed to get custody info for metrics") - } -} - func (s *Service) updateCustodyInfoIfNeeded() error { const minimumPeerCount = 1 @@ -62,8 +43,6 @@ func (s *Service) updateCustodyInfoIfNeeded() error { // If the actual custody group count is already equal to the target, skip the update. if actualCustodyGrounpCount >= targetCustodyGroupCount { - // Refresh metrics when no update is needed (e.g., after restart) - s.refreshCustodyMetrics() return nil } @@ -87,8 +66,6 @@ func (s *Service) updateCustodyInfoIfNeeded() error { } if !enoughPeers { - // Refresh metrics when insufficient peers (e.g., after restart) - s.refreshCustodyMetrics() return nil } From e5ab8495b0d34b5a6bd91c7150f5f1abd77de4a2 Mon Sep 17 00:00:00 2001 From: satushh Date: Fri, 28 Nov 2025 18:39:54 +0000 Subject: [PATCH 07/11] remove common package and keep metrics in respective packages --- beacon-chain/blockchain/BUILD.bazel | 2 +- beacon-chain/blockchain/service.go | 4 ++-- beacon-chain/custody/BUILD.bazel | 13 ----------- beacon-chain/custody/metrics.go | 32 ---------------------------- beacon-chain/db/kv/BUILD.bazel | 2 +- beacon-chain/db/kv/custody.go | 7 +++--- beacon-chain/db/kv/metrics.go | 14 ++++++++++++ beacon-chain/p2p/BUILD.bazel | 2 +- beacon-chain/p2p/custody.go | 17 +++++++-------- beacon-chain/p2p/metrics.go | 14 ++++++++++++ beacon-chain/p2p/testing/BUILD.bazel | 1 - beacon-chain/p2p/testing/p2p.go | 2 -- 12 files changed, 44 insertions(+), 66 deletions(-) delete mode 100644 beacon-chain/custody/metrics.go create mode 100644 beacon-chain/db/kv/metrics.go create mode 100644 beacon-chain/p2p/metrics.go diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index cb3f5222b589..cb3ceff21114 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -54,11 +54,11 @@ go_library( "//beacon-chain/core/signing:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/das:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filesystem:go_default_library", "//beacon-chain/db/filters:go_default_library", + "//beacon-chain/db/kv:go_default_library", "//beacon-chain/execution:go_default_library", "//beacon-chain/forkchoice:go_default_library", "//beacon-chain/forkchoice/doubly-linked-tree:go_default_library", diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 46becc6bfef0..361a0c897d68 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -12,7 +12,6 @@ import ( "github.com/OffchainLabs/prysm/v7/async/event" "github.com/OffchainLabs/prysm/v7/beacon-chain/blockchain/kzg" "github.com/OffchainLabs/prysm/v7/beacon-chain/cache" - "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" statefeed "github.com/OffchainLabs/prysm/v7/beacon-chain/core/feed/state" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" @@ -20,6 +19,7 @@ import ( "github.com/OffchainLabs/prysm/v7/beacon-chain/core/transition" "github.com/OffchainLabs/prysm/v7/beacon-chain/db" "github.com/OffchainLabs/prysm/v7/beacon-chain/db/filesystem" + "github.com/OffchainLabs/prysm/v7/beacon-chain/db/kv" "github.com/OffchainLabs/prysm/v7/beacon-chain/execution" f "github.com/OffchainLabs/prysm/v7/beacon-chain/forkchoice" lightClient "github.com/OffchainLabs/prysm/v7/beacon-chain/light-client" @@ -301,7 +301,7 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error { return errors.Wrap(err, "could not get and save custody group count") } - custody.UpdateDBMetric(earliestAvailableSlot) + kv.EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) if _, _, err := s.cfg.P2P.UpdateCustodyInfo(earliestAvailableSlot, custodySubnetCount); err != nil { return errors.Wrap(err, "update custody info") diff --git a/beacon-chain/custody/BUILD.bazel b/beacon-chain/custody/BUILD.bazel index 88b7fb81bd76..e69de29bb2d1 100644 --- a/beacon-chain/custody/BUILD.bazel +++ b/beacon-chain/custody/BUILD.bazel @@ -1,13 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["metrics.go"], - importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/custody", - visibility = ["//visibility:public"], - deps = [ - "//consensus-types/primitives:go_default_library", - "@com_github_prometheus_client_golang//prometheus:go_default_library", - "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", - ], -) diff --git a/beacon-chain/custody/metrics.go b/beacon-chain/custody/metrics.go deleted file mode 100644 index e55a75827b84..000000000000 --- a/beacon-chain/custody/metrics.go +++ /dev/null @@ -1,32 +0,0 @@ -// Package custody provides common custody-related metrics -package custody - -import ( - "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promauto" -) - -var ( - // EarliestAvailableSlotP2P tracks the earliest available slot in the p2p service - EarliestAvailableSlotP2P = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_p2p", - Help: "The earliest available slot tracked by the p2p service for custody purposes", - }) - - // EarliestAvailableSlotDB tracks the earliest available slot in the database - EarliestAvailableSlotDB = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_db", - Help: "The earliest available slot tracked by the database for custody purposes", - }) -) - -// UpdateP2PMetric updates the P2P earliest available slot metric -func UpdateP2PMetric(slot primitives.Slot) { - EarliestAvailableSlotP2P.Set(float64(slot)) -} - -// UpdateDBMetric updates the DB earliest available slot metric -func UpdateDBMetric(slot primitives.Slot) { - EarliestAvailableSlotDB.Set(float64(slot)) -} diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 00e100305cb4..01f07c4d13eb 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "kv.go", "lightclient.go", "log.go", + "metrics.go", "migration.go", "migration_archived_index.go", "migration_block_slot_index.go", @@ -40,7 +41,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/core/blocks:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/iface:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/db/kv/custody.go b/beacon-chain/db/kv/custody.go index 80520370eb73..d09ec9846019 100644 --- a/beacon-chain/db/kv/custody.go +++ b/beacon-chain/db/kv/custody.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" @@ -48,7 +47,7 @@ func (s *Store) GetCustodyInfo(ctx context.Context) (primitives.Slot, uint64, er } // Update the DB metric with the current value - custody.UpdateDBMetric(storedEarliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) return storedEarliestAvailableSlot, storedGroupCount, nil } @@ -111,7 +110,7 @@ func (s *Store) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot pri // Update the DB metric whenever we log the custody info // This ensures the metric is always in sync with what we log - custody.UpdateDBMetric(storedEarliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) return storedEarliestAvailableSlot, storedGroupCount, nil } @@ -187,7 +186,7 @@ func (s *Store) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailab log.WithField("earliestAvailableSlot", storedEarliestAvailableSlot).Debug("Updated earliest available slot") // Update DB metric after successfully updating the earliest available slot - custody.UpdateDBMetric(storedEarliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) return nil } diff --git a/beacon-chain/db/kv/metrics.go b/beacon-chain/db/kv/metrics.go new file mode 100644 index 000000000000..088f5f68abf0 --- /dev/null +++ b/beacon-chain/db/kv/metrics.go @@ -0,0 +1,14 @@ +package kv + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + // EarliestAvailableSlotMetric tracks the earliest available slot in the database + EarliestAvailableSlotMetric = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "custody_earliest_available_slot_db", + Help: "The earliest available slot tracked by the database for custody purposes", + }) +) \ No newline at end of file diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 63f43c52017d..d60d88c50406 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -20,6 +20,7 @@ go_library( "interfaces.go", "log.go", "message_id.go", + "metrics.go", "monitoring.go", "options.go", "pubsub.go", @@ -48,7 +49,6 @@ go_library( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/peerdas:go_default_library", "//beacon-chain/core/time:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/kv:go_default_library", "//beacon-chain/p2p/encoder:go_default_library", diff --git a/beacon-chain/p2p/custody.go b/beacon-chain/p2p/custody.go index 5bfc2a68f876..56663371c014 100644 --- a/beacon-chain/p2p/custody.go +++ b/beacon-chain/p2p/custody.go @@ -4,7 +4,6 @@ import ( "context" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" - "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" "github.com/OffchainLabs/prysm/v7/time/slots" @@ -24,7 +23,7 @@ func (s *Service) EarliestAvailableSlot(ctx context.Context) (primitives.Slot, e } // Update metric whenever the value is accessed - custody.UpdateP2PMetric(custodyInfo.earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(custodyInfo.earliestAvailableSlot)) return custodyInfo.earliestAvailableSlot, nil } @@ -85,14 +84,14 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo close(s.custodyInfoSet) // Update P2P metric when initializing custody info - custody.UpdateP2PMetric(earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) return earliestAvailableSlot, custodyGroupCount, nil } inMemory := s.custodyInfo if custodyGroupCount <= inMemory.groupCount { - custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, inMemory.groupCount, nil } @@ -105,7 +104,7 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if custodyGroupCount <= samplesPerSlot { inMemory.groupCount = custodyGroupCount - custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } @@ -116,14 +115,14 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if earliestAvailableSlot < fuluForkSlot { inMemory.groupCount = custodyGroupCount - custody.UpdateP2PMetric(inMemory.earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } inMemory.earliestAvailableSlot = earliestAvailableSlot inMemory.groupCount = custodyGroupCount - custody.UpdateP2PMetric(earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) return earliestAvailableSlot, custodyGroupCount, nil } @@ -146,7 +145,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S // Allow decrease (for backfill scenarios) if earliestAvailableSlot < s.custodyInfo.earliestAvailableSlot { s.custodyInfo.earliestAvailableSlot = earliestAvailableSlot - custody.UpdateP2PMetric(earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) return nil } @@ -177,7 +176,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S } s.custodyInfo.earliestAvailableSlot = earliestAvailableSlot - custody.UpdateP2PMetric(earliestAvailableSlot) + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) return nil } diff --git a/beacon-chain/p2p/metrics.go b/beacon-chain/p2p/metrics.go new file mode 100644 index 000000000000..4c88b0c8af78 --- /dev/null +++ b/beacon-chain/p2p/metrics.go @@ -0,0 +1,14 @@ +package p2p + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + // EarliestAvailableSlotMetric tracks the earliest available slot in the p2p service + EarliestAvailableSlotMetric = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "custody_earliest_available_slot_p2p", + Help: "The earliest available slot tracked by the p2p service for custody purposes", + }) +) \ No newline at end of file diff --git a/beacon-chain/p2p/testing/BUILD.bazel b/beacon-chain/p2p/testing/BUILD.bazel index 0f1f76c74cbb..2aee33be0cd5 100644 --- a/beacon-chain/p2p/testing/BUILD.bazel +++ b/beacon-chain/p2p/testing/BUILD.bazel @@ -20,7 +20,6 @@ go_library( ], deps = [ "//beacon-chain/core/peerdas:go_default_library", - "//beacon-chain/custody:go_default_library", "//beacon-chain/p2p/encoder:go_default_library", "//beacon-chain/p2p/peers:go_default_library", "//beacon-chain/p2p/peers/scorers:go_default_library", diff --git a/beacon-chain/p2p/testing/p2p.go b/beacon-chain/p2p/testing/p2p.go index bca1ee795a92..dd0da8dc3547 100644 --- a/beacon-chain/p2p/testing/p2p.go +++ b/beacon-chain/p2p/testing/p2p.go @@ -12,7 +12,6 @@ import ( "time" "github.com/OffchainLabs/prysm/v7/beacon-chain/core/peerdas" - "github.com/OffchainLabs/prysm/v7/beacon-chain/custody" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/encoder" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/peers" "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/peers/scorers" @@ -497,7 +496,6 @@ func (s *TestP2P) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo s.earliestAvailableSlot = earliestAvailableSlot s.custodyGroupCount = custodyGroupCount - custody.UpdateP2PMetric(earliestAvailableSlot) return s.earliestAvailableSlot, s.custodyGroupCount, nil } From b4dadc35bf00dbe667efbcb4492376bb835f4438 Mon Sep 17 00:00:00 2001 From: satushh Date: Fri, 28 Nov 2025 18:42:02 +0000 Subject: [PATCH 08/11] naming and description changes --- beacon-chain/db/kv/metrics.go | 4 ++-- beacon-chain/p2p/metrics.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beacon-chain/db/kv/metrics.go b/beacon-chain/db/kv/metrics.go index 088f5f68abf0..d9ae32e6099b 100644 --- a/beacon-chain/db/kv/metrics.go +++ b/beacon-chain/db/kv/metrics.go @@ -8,7 +8,7 @@ import ( var ( // EarliestAvailableSlotMetric tracks the earliest available slot in the database EarliestAvailableSlotMetric = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_db", - Help: "The earliest available slot tracked by the database for custody purposes", + Name: "earliest_available_slot_db", + Help: "The earliest available slot tracked by the database", }) ) \ No newline at end of file diff --git a/beacon-chain/p2p/metrics.go b/beacon-chain/p2p/metrics.go index 4c88b0c8af78..2859572022f8 100644 --- a/beacon-chain/p2p/metrics.go +++ b/beacon-chain/p2p/metrics.go @@ -8,7 +8,7 @@ import ( var ( // EarliestAvailableSlotMetric tracks the earliest available slot in the p2p service EarliestAvailableSlotMetric = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "custody_earliest_available_slot_p2p", - Help: "The earliest available slot tracked by the p2p service for custody purposes", + Name: "earliest_available_slot_p2p", + Help: "The earliest available slot tracked by the p2p service", }) ) \ No newline at end of file From c0c825d69e4758ea46f7e25533af9dbab7fa2a6f Mon Sep 17 00:00:00 2001 From: satushh Date: Mon, 1 Dec 2025 11:49:33 +0000 Subject: [PATCH 09/11] remove unwanted GetCustodyInfo --- beacon-chain/db/iface/interface.go | 1 - beacon-chain/db/kv/custody.go | 38 ------------------------------ 2 files changed, 39 deletions(-) diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index 252a50a0d5f7..d895057f9e9e 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -128,7 +128,6 @@ type NoHeadAccessDatabase interface { BackfillFinalizedIndex(ctx context.Context, blocks []blocks.ROBlock, finalizedChildRoot [32]byte) error // Custody operations. - GetCustodyInfo(ctx context.Context) (primitives.Slot, uint64, error) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot primitives.Slot, custodyGroupCount uint64) (primitives.Slot, uint64, error) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailableSlot primitives.Slot) error UpdateSubscribedToAllDataSubnets(ctx context.Context, subscribed bool) (bool, error) diff --git a/beacon-chain/db/kv/custody.go b/beacon-chain/db/kv/custody.go index d09ec9846019..99315861d8d5 100644 --- a/beacon-chain/db/kv/custody.go +++ b/beacon-chain/db/kv/custody.go @@ -14,44 +14,6 @@ import ( bolt "go.etcd.io/bbolt" ) -// GetCustodyInfo retrieves the current custody info without updating it. -// This is a read-only operation that also updates the DB metric. -func (s *Store) GetCustodyInfo(ctx context.Context) (primitives.Slot, uint64, error) { - _, span := trace.StartSpan(ctx, "BeaconDB.GetCustodyInfo") - defer span.End() - - var storedGroupCount uint64 - var storedEarliestAvailableSlot primitives.Slot - - if err := s.db.View(func(tx *bolt.Tx) error { - bucket := tx.Bucket(custodyBucket) - if bucket == nil { - return nil - } - - // Retrieve the stored custody group count. - storedGroupCountBytes := bucket.Get(groupCountKey) - if len(storedGroupCountBytes) != 0 { - storedGroupCount = bytesutil.BytesToUint64BigEndian(storedGroupCountBytes) - } - - // Retrieve the stored earliest available slot. - storedEarliestAvailableSlotBytes := bucket.Get(earliestAvailableSlotKey) - if len(storedEarliestAvailableSlotBytes) != 0 { - storedEarliestAvailableSlot = primitives.Slot(bytesutil.BytesToUint64BigEndian(storedEarliestAvailableSlotBytes)) - } - - return nil - }); err != nil { - return 0, 0, err - } - - // Update the DB metric with the current value - EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) - - return storedEarliestAvailableSlot, storedGroupCount, nil -} - // UpdateCustodyInfo atomically updates the custody group count only if it is greater than the stored one. // In this case, it also updates the earliest available slot with the provided value. // It returns the (potentially updated) custody group count and earliest available slot. From 391c20f2bac3ffdd2b4b17307377210163715a71 Mon Sep 17 00:00:00 2001 From: satushh Date: Mon, 1 Dec 2025 12:04:02 +0000 Subject: [PATCH 10/11] fmt --- beacon-chain/db/kv/metrics.go | 2 +- beacon-chain/p2p/metrics.go | 2 +- beacon-chain/p2p/testing/p2p.go | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/beacon-chain/db/kv/metrics.go b/beacon-chain/db/kv/metrics.go index d9ae32e6099b..c486286ed4e0 100644 --- a/beacon-chain/db/kv/metrics.go +++ b/beacon-chain/db/kv/metrics.go @@ -11,4 +11,4 @@ var ( Name: "earliest_available_slot_db", Help: "The earliest available slot tracked by the database", }) -) \ No newline at end of file +) diff --git a/beacon-chain/p2p/metrics.go b/beacon-chain/p2p/metrics.go index 2859572022f8..ed0c434dd30c 100644 --- a/beacon-chain/p2p/metrics.go +++ b/beacon-chain/p2p/metrics.go @@ -11,4 +11,4 @@ var ( Name: "earliest_available_slot_p2p", Help: "The earliest available slot tracked by the p2p service", }) -) \ No newline at end of file +) diff --git a/beacon-chain/p2p/testing/p2p.go b/beacon-chain/p2p/testing/p2p.go index dd0da8dc3547..f31fb31f3042 100644 --- a/beacon-chain/p2p/testing/p2p.go +++ b/beacon-chain/p2p/testing/p2p.go @@ -496,7 +496,6 @@ func (s *TestP2P) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo s.earliestAvailableSlot = earliestAvailableSlot s.custodyGroupCount = custodyGroupCount - return s.earliestAvailableSlot, s.custodyGroupCount, nil } From ce55a55f305d2cd843363710fc4d67dc10491dea Mon Sep 17 00:00:00 2001 From: satushh Date: Mon, 1 Dec 2025 12:07:06 +0000 Subject: [PATCH 11/11] remove some unwanted logs --- beacon-chain/db/kv/custody.go | 3 --- beacon-chain/p2p/custody.go | 1 - 2 files changed, 4 deletions(-) diff --git a/beacon-chain/db/kv/custody.go b/beacon-chain/db/kv/custody.go index 99315861d8d5..a828e9e9817c 100644 --- a/beacon-chain/db/kv/custody.go +++ b/beacon-chain/db/kv/custody.go @@ -70,8 +70,6 @@ func (s *Store) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot pri "groupCount": storedGroupCount, }).Debug("Custody info") - // Update the DB metric whenever we log the custody info - // This ensures the metric is always in sync with what we log EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) return storedEarliestAvailableSlot, storedGroupCount, nil @@ -147,7 +145,6 @@ func (s *Store) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailab log.WithField("earliestAvailableSlot", storedEarliestAvailableSlot).Debug("Updated earliest available slot") - // Update DB metric after successfully updating the earliest available slot EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) return nil diff --git a/beacon-chain/p2p/custody.go b/beacon-chain/p2p/custody.go index 56663371c014..ba95ffaebc16 100644 --- a/beacon-chain/p2p/custody.go +++ b/beacon-chain/p2p/custody.go @@ -22,7 +22,6 @@ func (s *Service) EarliestAvailableSlot(ctx context.Context) (primitives.Slot, e return 0, errors.Wrap(err, "wait for custody info") } - // Update metric whenever the value is accessed EarliestAvailableSlotMetric.Set(float64(custodyInfo.earliestAvailableSlot)) return custodyInfo.earliestAvailableSlot, nil