From eea53eb6dc1031ae4a987569b3273eb10f230256 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 13 May 2025 16:50:12 -0500 Subject: [PATCH] tracing: Add spans to various methods related to GetDuties (#15271) * Adding spans for troubleshooting GetDuties latency * Changelog fragment --- beacon-chain/cache/committee.go | 11 ++++++++++- beacon-chain/core/helpers/beacon_committee.go | 9 +++++++++ beacon-chain/core/helpers/validators.go | 3 +++ changelog/pvl-spans.md | 3 +++ .../beacon-api/propose_beacon_block_capella_test.go | 2 +- 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 changelog/pvl-spans.md diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 514fe792b2..680f24340a 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -14,6 +14,7 @@ import ( "github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/container/slice" mathutil "github.com/OffchainLabs/prysm/v6/math" + "github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace" lru "github.com/hashicorp/golang-lru" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -104,11 +105,16 @@ func (c *CommitteeCache) CompressCommitteeCache() { // Committee fetches the shuffled indices by slot and committee index. Every list of indices // represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil. func (c *CommitteeCache) Committee(ctx context.Context, slot primitives.Slot, seed [32]byte, index primitives.CommitteeIndex) ([]primitives.ValidatorIndex, error) { + ctx, span := trace.StartSpan(ctx, "committeeCache.Committee") + defer span.End() + span.SetAttributes(trace.Int64Attribute("slot", int64(slot)), trace.Int64Attribute("index", int64(index))) // lint:ignore uintcast -- OK for tracing. + if err := c.checkInProgress(ctx, seed); err != nil { return nil, err } obj, exists := c.CommitteeCache.Get(key(seed)) + span.SetAttributes(trace.BoolAttribute("cache_hit", exists)) if exists { CommitteeCacheHit.Inc() } else { @@ -157,11 +163,14 @@ func (c *CommitteeCache) AddCommitteeShuffledList(ctx context.Context, committee // ActiveIndices returns the active indices of a given seed stored in cache. func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]primitives.ValidatorIndex, error) { + ctx, span := trace.StartSpan(ctx, "committeeCache.ActiveIndices") + defer span.End() + if err := c.checkInProgress(ctx, seed); err != nil { return nil, err } obj, exists := c.CommitteeCache.Get(key(seed)) - + span.SetAttributes(trace.BoolAttribute("cache_hit", exists)) if exists { CommitteeCacheHit.Inc() } else { diff --git a/beacon-chain/core/helpers/beacon_committee.go b/beacon-chain/core/helpers/beacon_committee.go index bc7f07b476..e1e8df25e5 100644 --- a/beacon-chain/core/helpers/beacon_committee.go +++ b/beacon-chain/core/helpers/beacon_committee.go @@ -119,6 +119,9 @@ func attestationCommittees( // BeaconCommittees returns the list of all beacon committees for a given state at a given slot. func BeaconCommittees(ctx context.Context, state state.ReadOnlyBeaconState, slot primitives.Slot) ([][]primitives.ValidatorIndex, error) { + ctx, span := trace.StartSpan(ctx, "helpers.BeaconCommittees") + defer span.End() + epoch := slots.ToEpoch(slot) activeCount, err := ActiveValidatorCount(ctx, state, epoch) if err != nil { @@ -245,6 +248,9 @@ func BeaconCommittee( slot primitives.Slot, committeeIndex primitives.CommitteeIndex, ) ([]primitives.ValidatorIndex, error) { + ctx, span := trace.StartSpan(ctx, "helpers.BeaconCommittee") + defer span.End() + committee, err := committeeCache.Committee(ctx, slot, seed, committeeIndex) if err != nil { return nil, errors.Wrap(err, "could not interface with committee cache") @@ -439,6 +445,9 @@ func CommitteeIndices(committeeBits bitfield.Bitfield) []primitives.CommitteeInd // UpdateCommitteeCache gets called at the beginning of every epoch to cache the committee shuffled indices // list with committee index and epoch number. It caches the shuffled indices for the input epoch. func UpdateCommitteeCache(ctx context.Context, state state.ReadOnlyBeaconState, e primitives.Epoch) error { + ctx, span := trace.StartSpan(ctx, "committeeCache.UpdateCommitteeCache") + defer span.End() + seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconAttester) if err != nil { return err diff --git a/beacon-chain/core/helpers/validators.go b/beacon-chain/core/helpers/validators.go index 2942ee431b..d86539d38a 100644 --- a/beacon-chain/core/helpers/validators.go +++ b/beacon-chain/core/helpers/validators.go @@ -102,6 +102,9 @@ func checkValidatorSlashable(activationEpoch, withdrawableEpoch primitives.Epoch // """ // return [ValidatorIndex(i) for i, v in enumerate(state.validators) if is_active_validator(v, epoch)] func ActiveValidatorIndices(ctx context.Context, s state.ReadOnlyBeaconState, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error) { + ctx, span := trace.StartSpan(ctx, "helpers.ActiveValidatorIndices") + defer span.End() + seed, err := Seed(s, epoch, params.BeaconConfig().DomainBeaconAttester) if err != nil { return nil, errors.Wrap(err, "could not get seed") diff --git a/changelog/pvl-spans.md b/changelog/pvl-spans.md new file mode 100644 index 0000000000..fe32b5b045 --- /dev/null +++ b/changelog/pvl-spans.md @@ -0,0 +1,3 @@ +### Changed + +- Added more tracing spans to various helpers related to GetDuties diff --git a/validator/client/beacon-api/propose_beacon_block_capella_test.go b/validator/client/beacon-api/propose_beacon_block_capella_test.go index a26108bf5d..c81354b126 100644 --- a/validator/client/beacon-api/propose_beacon_block_capella_test.go +++ b/validator/client/beacon-api/propose_beacon_block_capella_test.go @@ -27,7 +27,7 @@ func TestProposeBeaconBlock_Capella(t *testing.T) { jsonCapellaBlock, err := structs.SignedBeaconBlockCapellaFromConsensus(capellaBlock.Capella) require.NoError(t, err) - + marshalledBlock, err := json.Marshal(jsonCapellaBlock) require.NoError(t, err)