Compare commits

...

5 Commits

Author SHA1 Message Date
james-prysm
462cc74b47 Merge branch 'develop' into change-p2p-forkchoice-error 2025-11-03 09:55:30 -08:00
james-prysm
959bfef56e gofmt 2025-10-10 12:01:24 -05:00
james-prysm
f7ceb346d0 fixing test and changelog 2025-10-10 11:55:03 -05:00
james-prysm
571e4593e0 Merge branch 'develop' into change-p2p-forkchoice-error 2025-10-09 16:52:40 -05:00
james-prysm
9aa01e2cfc changeing ErrNotDescendantOfFinalized to ErrRootNotInForkChoice 2025-10-09 16:51:20 -05:00
9 changed files with 19 additions and 9 deletions

View File

@@ -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"
)
@@ -48,6 +50,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:

View File

@@ -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)

View File

@@ -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) {

View File

@@ -507,7 +507,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)

View File

@@ -118,7 +118,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
}

View File

@@ -167,8 +167,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)

View File

@@ -121,8 +121,8 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(
}
// Block exists - verify it's in forkchoice (i.e., it's a descendant of the finalized checkpoint)
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)

View File

@@ -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())

View File

@@ -0,0 +1,3 @@
### Changed
- changed ErrNotDescendantOfFinalized to ErrRootNotInForkChoice.