Skip to content

Commit

Permalink
add shuffling indices metrics (#12216)
Browse files Browse the repository at this point in the history
Co-authored-by: shota.silagadze <shota.silagadze@taal.com>
  • Loading branch information
shotasilagadze and shotasilagadzetaal authored Oct 4, 2024
1 parent 8ef8ca2 commit 3117d74
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cl/monitor/shuffling_metrics/shuffling_metrics.go
Original file line number Diff line number Diff line change
@@ -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()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions cl/phase1/core/state/cache_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions cl/phase1/forkchoice/checkpoint_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 3117d74

Please sign in to comment.