From 31c72672d7ed1cdd56f7df4cce504127a5ef1f8f Mon Sep 17 00:00:00 2001 From: Potuz Date: Wed, 3 Jan 2024 09:43:40 -0300 Subject: [PATCH] Remove the getPayloadAttribute call from updateForkchoiceWithExecution (#13402) * Remove the getPayloadAttribute call from updateForkchoiceWithExecution * Move log --- .../blockchain/forkchoice_update_execution.go | 15 +----- beacon-chain/blockchain/process_block.go | 47 ++++++++++--------- .../blockchain/receive_attestation.go | 13 +++-- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/beacon-chain/blockchain/forkchoice_update_execution.go b/beacon-chain/blockchain/forkchoice_update_execution.go index fec9ae4a23..4f51175b11 100644 --- a/beacon-chain/blockchain/forkchoice_update_execution.go +++ b/beacon-chain/blockchain/forkchoice_update_execution.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" doublylinkedtree "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/doubly-linked-tree" "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v4/config/features" "github.com/prysmaticlabs/prysm/v4/config/params" "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" payloadattribute "github.com/prysmaticlabs/prysm/v4/consensus-types/payload-attribute" @@ -59,19 +58,7 @@ func (s *Service) forkchoiceUpdateWithExecution(ctx context.Context, args *fcuCo 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) - fcuArgs := &fcuConfig{ - headState: args.headState, - headRoot: args.headRoot, - headBlock: args.headBlock, - } - _, tracked := s.trackedProposer(args.headState, args.proposingSlot) - if tracked && !features.Get().DisableReorgLateBlocks { - if s.shouldOverrideFCU(args.headRoot, args.proposingSlot) { - return nil - } - fcuArgs.attributes = s.getPayloadAttribute(ctx, args.headState, args.proposingSlot, args.headRoot[:]) - } - _, err := s.notifyForkchoiceUpdate(ctx, fcuArgs) + _, err := s.notifyForkchoiceUpdate(ctx, args) if err != nil { return errors.Wrap(err, "could not notify forkchoice update") } diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index ad20f91dff..cd563c9203 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -74,6 +74,8 @@ func (s *Service) postBlockProcess(ctx context.Context, signed interfaces.ReadOn log.WithError(err).Warn("Could not update head") } newBlockHeadElapsedTime.Observe(float64(time.Since(start).Milliseconds())) + proposingSlot := s.CurrentSlot() + 1 + var fcuArgs *fcuConfig if blockRoot != headRoot { receivedWeight, err := s.cfg.ForkChoiceStore.Weight(blockRoot) if err != nil { @@ -89,23 +91,16 @@ func (s *Service) postBlockProcess(ctx context.Context, signed interfaces.ReadOn "headRoot": fmt.Sprintf("%#x", headRoot), "headWeight": headWeight, }).Debug("Head block is not the received block") - if s.isNewHead(headRoot) { - headState, headBlock, err := s.getStateAndBlock(ctx, headRoot) - if err != nil { - log.WithError(err).Error("Could not get forkchoice update argument") - return nil - } - // verify conditions for FCU, notifies FCU, and saves the new head. - // This function also prunes attestations, other similar operations happen in prunePostBlockOperationPools. - args := &fcuConfig{ - headState: headState, - headBlock: headBlock, - headRoot: headRoot, - proposingSlot: s.CurrentSlot() + 1, - } - if err := s.forkchoiceUpdateWithExecution(ctx, args); err != nil { - return err - } + headState, headBlock, err := s.getStateAndBlock(ctx, headRoot) + if err != nil { + log.WithError(err).Error("Could not get forkchoice update argument") + return nil + } + fcuArgs = &fcuConfig{ + headState: headState, + headBlock: headBlock, + headRoot: headRoot, + proposingSlot: proposingSlot, } } else { // Updating next slot state cache can happen in the background @@ -132,14 +127,24 @@ func (s *Service) postBlockProcess(ctx context.Context, signed interfaces.ReadOn } // verify conditions for FCU, notifies FCU, and saves the new head. // This function also prunes attestations, other similar operations happen in prunePostBlockOperationPools. - args := &fcuConfig{ + fcuArgs = &fcuConfig{ headState: postState, headBlock: signed, headRoot: headRoot, - proposingSlot: s.CurrentSlot() + 1, + proposingSlot: proposingSlot, } - if err := s.forkchoiceUpdateWithExecution(ctx, args); err != nil { - return err + } + if s.isNewHead(headRoot) { + shouldOverrideFCU := false + _, tracked := s.trackedProposer(fcuArgs.headState, proposingSlot) + if tracked && !features.Get().DisableReorgLateBlocks { + shouldOverrideFCU = s.shouldOverrideFCU(headRoot, proposingSlot) + fcuArgs.attributes = s.getPayloadAttribute(ctx, fcuArgs.headState, proposingSlot, headRoot[:]) + } + if !shouldOverrideFCU { + if err := s.forkchoiceUpdateWithExecution(ctx, fcuArgs); err != nil { + return err + } } } optimistic, err := s.cfg.ForkChoiceStore.IsOptimistic(blockRoot) diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 961ea98a83..df5e448237 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -139,22 +139,29 @@ func (s *Service) UpdateHead(ctx context.Context, proposingSlot primitives.Slot) if !s.isNewHead(newHeadRoot) { return } + log.WithField("newHeadRoot", fmt.Sprintf("%#x", newHeadRoot)).Debug("Head changed due to attestations") headState, headBlock, err := s.getStateAndBlock(ctx, newHeadRoot) if err != nil { log.WithError(err).Error("could not get head block") return } newAttHeadElapsedTime.Observe(float64(time.Since(start).Milliseconds())) - args := &fcuConfig{ + fcuArgs := &fcuConfig{ headState: headState, headRoot: newHeadRoot, headBlock: headBlock, proposingSlot: proposingSlot, } - if err := s.forkchoiceUpdateWithExecution(s.ctx, args); err != nil { + _, tracked := s.trackedProposer(headState, proposingSlot) + if tracked && !features.Get().DisableReorgLateBlocks { + if s.shouldOverrideFCU(newHeadRoot, proposingSlot) { + return + } + fcuArgs.attributes = s.getPayloadAttribute(ctx, headState, proposingSlot, newHeadRoot[:]) + } + if err := s.forkchoiceUpdateWithExecution(s.ctx, fcuArgs); err != nil { log.WithError(err).Error("could not update forkchoice") } - log.WithField("newHeadRoot", fmt.Sprintf("%#x", newHeadRoot)).Debug("Head changed due to attestations") } // This processes fork choice attestations from the pool to account for validator votes and fork choice.