From 3117d7403b8710e5e38a3f9ce8f0ba6c093f8a7f Mon Sep 17 00:00:00 2001 From: Shota Date: Sat, 5 Oct 2024 00:59:48 +0400 Subject: [PATCH] add shuffling indices metrics (#12216) Co-authored-by: shota.silagadze --- .../shuffling_metrics/shuffling_metrics.go | 17 +++++++++++++++++ .../attesting_indicies.go | 4 ++++ cl/phase1/core/state/cache_accessors.go | 4 ++++ cl/phase1/forkchoice/checkpoint_state.go | 4 ++++ 4 files changed, 29 insertions(+) create mode 100644 cl/monitor/shuffling_metrics/shuffling_metrics.go diff --git a/cl/monitor/shuffling_metrics/shuffling_metrics.go b/cl/monitor/shuffling_metrics/shuffling_metrics.go new file mode 100644 index 00000000000..cfc5b74219b --- /dev/null +++ b/cl/monitor/shuffling_metrics/shuffling_metrics.go @@ -0,0 +1,17 @@ +package shuffling_metrics + +import ( + "time" + + "github.com/erigontech/erigon-lib/metrics" +) + +var ( + // shuffling metrics + computeShuffledIndicies = metrics.GetOrCreateGauge("compute_shuffled_indices") +) + +// ObserveComputeShuffledIndiciesTime sets computeShuffledIndicies time +func ObserveComputeShuffledIndiciesTime(startTime time.Time) { + computeShuffledIndicies.Set(float64(time.Since(startTime).Microseconds())) +} diff --git a/cl/persistence/state/historical_states_reader/attesting_indicies.go b/cl/persistence/state/historical_states_reader/attesting_indicies.go index 4ac8ded610a..e38f556d4f5 100644 --- a/cl/persistence/state/historical_states_reader/attesting_indicies.go +++ b/cl/persistence/state/historical_states_reader/attesting_indicies.go @@ -19,11 +19,13 @@ package historical_states_reader import ( "errors" "fmt" + "time" libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon/cl/clparams" "github.com/erigontech/erigon/cl/cltypes/solid" + "github.com/erigontech/erigon/cl/monitor/shuffling_metrics" "github.com/erigontech/erigon/cl/persistence/base_encoding" state_accessors "github.com/erigontech/erigon/cl/persistence/state" "github.com/erigontech/erigon/cl/phase1/core/state/shuffling" @@ -76,7 +78,9 @@ func (r *HistoricalStatesReader) ComputeCommittee(mix libcommon.Hash, indicies [ shuffledIndicies = shuffledIndicesInterface } else { shuffledIndicies = make([]uint64, lenIndicies) + start := time.Now() shuffledIndicies = shuffling.ComputeShuffledIndicies(cfg, mix, shuffledIndicies, indicies, slot) + shuffling_metrics.ObserveComputeShuffledIndiciesTime(start) r.shuffledSetsCache.Add(epoch, shuffledIndicies) } diff --git a/cl/phase1/core/state/cache_accessors.go b/cl/phase1/core/state/cache_accessors.go index c152954292d..6550190e2b0 100644 --- a/cl/phase1/core/state/cache_accessors.go +++ b/cl/phase1/core/state/cache_accessors.go @@ -22,8 +22,10 @@ import ( "errors" "fmt" "math" + "time" "github.com/erigontech/erigon/cl/cltypes/solid" + "github.com/erigontech/erigon/cl/monitor/shuffling_metrics" "github.com/erigontech/erigon/cl/phase1/core/state/shuffling" shuffling2 "github.com/erigontech/erigon/cl/phase1/core/state/shuffling" @@ -87,7 +89,9 @@ func (b *CachingBeaconState) ComputeCommittee( shuffledIndicies = shuffledIndicesInterface } else { shuffledIndicies = make([]uint64, lenIndicies) + start := time.Now() shuffledIndicies = shuffling.ComputeShuffledIndicies(b.BeaconConfig(), mix, shuffledIndicies, indicies, slot) + shuffling_metrics.ObserveComputeShuffledIndiciesTime(start) b.shuffledSetsCache.Add(seed, shuffledIndicies) } diff --git a/cl/phase1/forkchoice/checkpoint_state.go b/cl/phase1/forkchoice/checkpoint_state.go index 3c56027875e..3dd9b86a73c 100644 --- a/cl/phase1/forkchoice/checkpoint_state.go +++ b/cl/phase1/forkchoice/checkpoint_state.go @@ -19,9 +19,11 @@ package forkchoice import ( "errors" "fmt" + "time" "github.com/erigontech/erigon/cl/cltypes/solid" "github.com/erigontech/erigon/cl/monitor" + "github.com/erigontech/erigon/cl/monitor/shuffling_metrics" "github.com/erigontech/erigon/cl/phase1/core/state/shuffling" "github.com/Giulio2002/bls" @@ -114,7 +116,9 @@ func newCheckpointState(beaconConfig *clparams.BeaconChainConfig, anchorPublicKe activeIndicies := c.getActiveIndicies(epoch) monitor.ObserveActiveValidatorsCount(len(activeIndicies)) c.shuffledSet = make([]uint64, len(activeIndicies)) + start := time.Now() c.shuffledSet = shuffling.ComputeShuffledIndicies(c.beaconConfig, c.randaoMixes.Get(int(mixPosition)), c.shuffledSet, activeIndicies, epoch*beaconConfig.SlotsPerEpoch) + shuffling_metrics.ObserveComputeShuffledIndiciesTime(start) return c }