diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 7f89e64c277f..cb3ceff21114 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -58,6 +58,7 @@ go_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 71d7c20b8494..361a0c897d68 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -19,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" @@ -300,6 +301,8 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error { return errors.Wrap(err, "could not get and save custody group count") } + 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 new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 93a4e1ad6691..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", diff --git a/beacon-chain/db/kv/custody.go b/beacon-chain/db/kv/custody.go index 67c66d65d3cb..a828e9e9817c 100644 --- a/beacon-chain/db/kv/custody.go +++ b/beacon-chain/db/kv/custody.go @@ -70,6 +70,8 @@ func (s *Store) UpdateCustodyInfo(ctx context.Context, earliestAvailableSlot pri "groupCount": storedGroupCount, }).Debug("Custody info") + EarliestAvailableSlotMetric.Set(float64(storedEarliestAvailableSlot)) + return storedEarliestAvailableSlot, storedGroupCount, nil } @@ -143,6 +145,8 @@ func (s *Store) UpdateEarliestAvailableSlot(ctx context.Context, earliestAvailab log.WithField("earliestAvailableSlot", storedEarliestAvailableSlot).Debug("Updated earliest available slot") + 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..c486286ed4e0 --- /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: "earliest_available_slot_db", + Help: "The earliest available slot tracked by the database", + }) +) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 5f7866fad472..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", diff --git a/beacon-chain/p2p/custody.go b/beacon-chain/p2p/custody.go index fe4c9ffeb709..ba95ffaebc16 100644 --- a/beacon-chain/p2p/custody.go +++ b/beacon-chain/p2p/custody.go @@ -22,6 +22,8 @@ func (s *Service) EarliestAvailableSlot(ctx context.Context) (primitives.Slot, e return 0, errors.Wrap(err, "wait for custody info") } + EarliestAvailableSlotMetric.Set(float64(custodyInfo.earliestAvailableSlot)) + return custodyInfo.earliestAvailableSlot, nil } @@ -80,11 +82,15 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo close(s.custodyInfoSet) + // Update P2P metric when initializing custody info + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) + return earliestAvailableSlot, custodyGroupCount, nil } inMemory := s.custodyInfo if custodyGroupCount <= inMemory.groupCount { + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, inMemory.groupCount, nil } @@ -97,6 +103,7 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if custodyGroupCount <= samplesPerSlot { inMemory.groupCount = custodyGroupCount + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } @@ -107,11 +114,15 @@ func (s *Service) UpdateCustodyInfo(earliestAvailableSlot primitives.Slot, custo if earliestAvailableSlot < fuluForkSlot { inMemory.groupCount = custodyGroupCount + EarliestAvailableSlotMetric.Set(float64(inMemory.earliestAvailableSlot)) return inMemory.earliestAvailableSlot, custodyGroupCount, nil } inMemory.earliestAvailableSlot = earliestAvailableSlot inMemory.groupCount = custodyGroupCount + + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) + return earliestAvailableSlot, custodyGroupCount, nil } @@ -133,6 +144,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S // Allow decrease (for backfill scenarios) if earliestAvailableSlot < s.custodyInfo.earliestAvailableSlot { s.custodyInfo.earliestAvailableSlot = earliestAvailableSlot + EarliestAvailableSlotMetric.Set(float64(earliestAvailableSlot)) return nil } @@ -163,6 +175,7 @@ func (s *Service) UpdateEarliestAvailableSlot(earliestAvailableSlot primitives.S } s.custodyInfo.earliestAvailableSlot = 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..ed0c434dd30c --- /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: "earliest_available_slot_p2p", + Help: "The earliest available slot tracked by the p2p service", + }) +) 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