diff --git a/beacon-chain/blockchain/forkchoice_update_execution.go b/beacon-chain/blockchain/forkchoice_update_execution.go index 4eb597cab..aa94631ec 100644 --- a/beacon-chain/blockchain/forkchoice_update_execution.go +++ b/beacon-chain/blockchain/forkchoice_update_execution.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v4/time/slots" "github.com/sirupsen/logrus" + "go.opencensus.io/trace" ) func (s *Service) isNewProposer(slot primitives.Slot) bool { @@ -50,6 +51,11 @@ func (s *Service) getStateAndBlock(ctx context.Context, r [32]byte) (state.Beaco // fockchoiceUpdateWithExecution is a wrapper around notifyForkchoiceUpdate. It decides whether a new call to FCU should be made. func (s *Service) forkchoiceUpdateWithExecution(ctx context.Context, newHeadRoot [32]byte, proposingSlot primitives.Slot) error { + _, span := trace.StartSpan(ctx, "beacon-chain.blockchain.forkchoiceUpdateWithExecution") + defer span.End() + // Note: Use the service context here to avoid the parent context being ended during a forkchoice update. + ctx = trace.NewContext(s.ctx, span) + isNewHead := s.isNewHead(newHeadRoot) if !isNewHead { return nil diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 828c3c105..d2bfe7b9a 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -117,6 +117,9 @@ func (s *Service) spawnProcessAttestationsRoutine(stateFeed *event.Feed) { // UpdateHead updates the canonical head of the chain based on information from fork-choice attestations and votes. // The caller of this function MUST hold a lock in forkchoice func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot) { + ctx, span := trace.StartSpan(ctx, "beacon-chain.blockchain.UpdateHead") + defer span.End() + start := time.Now() s.cfg.ForkChoiceStore.Lock() defer s.cfg.ForkChoiceStore.Unlock() @@ -148,7 +151,7 @@ func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot) }).Debug("Head changed due to attestations") } s.headLock.RUnlock() - if err := s.forkchoiceUpdateWithExecution(s.ctx, newHeadRoot, proposingSlot); err != nil { + if err := s.forkchoiceUpdateWithExecution(ctx, newHeadRoot, proposingSlot); err != nil { log.WithError(err).Error("could not update forkchoice") } }