diff --git a/beacon-chain/blockchain/error.go b/beacon-chain/blockchain/error.go index 50f535f38730..ce113f7b1f5f 100644 --- a/beacon-chain/blockchain/error.go +++ b/beacon-chain/blockchain/error.go @@ -2,8 +2,10 @@ package blockchain import ( stderrors "errors" + "fmt" "github.com/OffchainLabs/prysm/v6/beacon-chain/verification" + fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams" "github.com/pkg/errors" ) @@ -29,8 +31,6 @@ var ( errWSBlockNotFound = errors.New("weak subjectivity root not found in db") // errWSBlockNotFoundInEpoch is returned when a block is not found in the WS cache or DB within epoch. errWSBlockNotFoundInEpoch = errors.New("weak subjectivity root not found in db within epoch") - // ErrNotDescendantOfFinalized is returned when a block is not a descendant of the finalized checkpoint - ErrNotDescendantOfFinalized = invalidBlock{error: errors.New("not descendant of finalized checkpoint")} // ErrNotCheckpoint is returned when a given checkpoint is not a // checkpoint in any chain known to forkchoice ErrNotCheckpoint = errors.New("not a checkpoint in forkchoice") @@ -48,6 +48,11 @@ var ( errBlockBeingSynced = errors.New("block is being synced") ) +// ErrRootNotInForkchoice is returned when a root cannot be found in forkchoice. +func ErrRootNotInForkchoice(root [fieldparams.RootLength]byte) invalidBlock { + return invalidBlock{error: fmt.Errorf("root %#x not in forkchoice", root), root: root} +} + // An invalid block is the block that fails state transition based on the core protocol rules. // The beacon node shall not be accepting nor building blocks that branch off from an invalid block. // Some examples of invalid blocks are: diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index 9e15c5671982..2bf235f905f2 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -401,7 +401,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, signed inte return nil } if root != s.ensureRootNotZeros(finalized.Root) && !s.cfg.ForkChoiceStore.HasNode(root) { - return ErrNotDescendantOfFinalized + return ErrRootNotInForkchoice(root) } slices.Reverse(pendingNodes) return s.cfg.ForkChoiceStore.InsertChain(ctx, pendingNodes) diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index bebfb576bc4a..bfba072155ef 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -374,7 +374,7 @@ func TestFillForkChoiceMissingBlocks_FinalizedSibling(t *testing.T) { err = service.fillInForkChoiceMissingBlocks( t.Context(), wsb, beaconState.FinalizedCheckpoint(), beaconState.CurrentJustifiedCheckpoint()) - require.Equal(t, ErrNotDescendantOfFinalized.Error(), err.Error()) + require.Equal(t, ErrRootNotInForkchoice(bytesutil.ToBytes32(roots[8])), err.Error()) } func TestFillForkChoiceMissingBlocks_ErrorCases(t *testing.T) { @@ -3302,7 +3302,6 @@ func Test_postBlockProcess_EventSending(t *testing.T) { } } - func setupLightClientTestRequirements(ctx context.Context, t *testing.T, s *Service, v int, options ...util.LightClientOption) (*util.TestLightClient, *postBlockProcessConfig) { var l *util.TestLightClient switch v { diff --git a/beacon-chain/blockchain/receive_block.go b/beacon-chain/blockchain/receive_block.go index 9326812295d6..f5aa351f9e84 100644 --- a/beacon-chain/blockchain/receive_block.go +++ b/beacon-chain/blockchain/receive_block.go @@ -504,7 +504,7 @@ func (s *Service) validateStateTransition(ctx context.Context, preState state.Be // Verify that the parent block is in forkchoice parentRoot := b.ParentRoot() if !s.InForkchoice(parentRoot) { - return nil, ErrNotDescendantOfFinalized + return nil, ErrRootNotInForkchoice(parentRoot) } stateTransitionStartTime := time.Now() postState, err := transition.ExecuteStateTransition(ctx, preState, signed) diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index 7073a058aaef..e192cab26705 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -117,7 +117,7 @@ func (s *Service) processAttestationBucket(ctx context.Context, bucket *attestat // Shared validations for the entire bucket. if !s.cfg.chain.InForkchoice(bytesutil.ToBytes32(data.BeaconBlockRoot)) { - log.WithError(blockchain.ErrNotDescendantOfFinalized).WithField("root", fmt.Sprintf("%#x", data.BeaconBlockRoot)).Debug("Failed forkchoice check for bucket") + log.WithError(blockchain.ErrRootNotInForkchoice(bytesutil.ToBytes32(data.BeaconBlockRoot))).Debug("Failed forkchoice check for bucket") return } diff --git a/beacon-chain/sync/validate_aggregate_proof.go b/beacon-chain/sync/validate_aggregate_proof.go index 4ecfd9d12363..a636a32afb3d 100644 --- a/beacon-chain/sync/validate_aggregate_proof.go +++ b/beacon-chain/sync/validate_aggregate_proof.go @@ -166,8 +166,8 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed ethpb.Signed // Verify current finalized checkpoint is an ancestor of the block defined by the attestation's beacon block root. if !s.cfg.chain.InForkchoice(bytesutil.ToBytes32(data.BeaconBlockRoot)) { - tracing.AnnotateError(span, blockchain.ErrNotDescendantOfFinalized) - return pubsub.ValidationIgnore, blockchain.ErrNotDescendantOfFinalized + tracing.AnnotateError(span, blockchain.ErrRootNotInForkchoice(bytesutil.ToBytes32(data.BeaconBlockRoot))) + return pubsub.ValidationIgnore, blockchain.ErrRootNotInForkchoice(bytesutil.ToBytes32(data.BeaconBlockRoot)) } bs, err := s.cfg.chain.AttestationTargetState(ctx, data.Target) diff --git a/beacon-chain/sync/validate_beacon_attestation.go b/beacon-chain/sync/validate_beacon_attestation.go index 4d351f09ce9c..1d5048228ec5 100644 --- a/beacon-chain/sync/validate_beacon_attestation.go +++ b/beacon-chain/sync/validate_beacon_attestation.go @@ -115,8 +115,8 @@ func (s *Service) validateCommitteeIndexBeaconAttestation( s.savePendingAtt(att) } if !s.cfg.chain.InForkchoice(blockRoot) { - tracing.AnnotateError(span, blockchain.ErrNotDescendantOfFinalized) - return pubsub.ValidationIgnore, blockchain.ErrNotDescendantOfFinalized + tracing.AnnotateError(span, blockchain.ErrRootNotInForkchoice(blockRoot)) + return pubsub.ValidationIgnore, blockchain.ErrRootNotInForkchoice(blockRoot) } if err = s.cfg.chain.VerifyLmdFfgConsistency(ctx, att); err != nil { tracing.AnnotateError(span, err) diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 49d101cb175c..8471cd0e84f0 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -285,7 +285,7 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.ReadOn func (s *Service) validatePhase0Block(ctx context.Context, blk interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte) (state.BeaconState, error) { if !s.cfg.chain.InForkchoice(blk.Block().ParentRoot()) { s.setBadBlock(ctx, blockRoot) - return nil, blockchain.ErrNotDescendantOfFinalized + return nil, blockchain.ErrRootNotInForkchoice(blk.Block().ParentRoot()) } parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot()) diff --git a/changelog/james-prysm_change-p2p-forkchoice-error.md b/changelog/james-prysm_change-p2p-forkchoice-error.md new file mode 100644 index 000000000000..d5be66cdce55 --- /dev/null +++ b/changelog/james-prysm_change-p2p-forkchoice-error.md @@ -0,0 +1,3 @@ +### Changed + +- changed ErrNotDescendantOfFinalized to ErrRootNotInForkChoice. \ No newline at end of file