mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 00:27:38 +00:00
clean up validate beacon block (#13517)
This commit is contained in:
parent
f4ab2ca79f
commit
a2892b1ed5
@ -241,36 +241,11 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.ReadOn
|
||||
return err
|
||||
}
|
||||
|
||||
if !s.cfg.chain.InForkchoice(blk.Block().ParentRoot()) {
|
||||
s.setBadBlock(ctx, blockRoot)
|
||||
return blockchain.ErrNotDescendantOfFinalized
|
||||
}
|
||||
|
||||
parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot())
|
||||
parentState, err := s.validatePhase0Block(ctx, blk, blockRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := blocks.VerifyBlockSignatureUsingCurrentFork(parentState, blk); err != nil {
|
||||
s.setBadBlock(ctx, blockRoot)
|
||||
return err
|
||||
}
|
||||
// In the event the block is more than an epoch ahead from its
|
||||
// parent state, we have to advance the state forward.
|
||||
parentRoot := blk.Block().ParentRoot()
|
||||
parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, parentRoot[:], blk.Block().Slot())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
idx, err := helpers.BeaconProposerIndex(ctx, parentState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if blk.Block().ProposerIndex() != idx {
|
||||
s.setBadBlock(ctx, blockRoot)
|
||||
return errors.New("incorrect proposer index")
|
||||
}
|
||||
|
||||
if err = s.validateBellatrixBeaconBlock(ctx, parentState, blk.Block()); err != nil {
|
||||
if errors.Is(err, ErrOptimisticParent) {
|
||||
return err
|
||||
@ -282,6 +257,42 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.ReadOn
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validates beacon block according to phase 0 validity conditions.
|
||||
// - Checks that the parent is in our forkchoice tree.
|
||||
// - Validates that the proposer signature is valid.
|
||||
// - Validates that the proposer index is valid.
|
||||
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
|
||||
}
|
||||
|
||||
parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := blocks.VerifyBlockSignatureUsingCurrentFork(parentState, blk); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// In the event the block is more than an epoch ahead from its
|
||||
// parent state, we have to advance the state forward.
|
||||
parentRoot := blk.Block().ParentRoot()
|
||||
parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, parentRoot[:], blk.Block().Slot())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
idx, err := helpers.BeaconProposerIndex(ctx, parentState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if blk.Block().ProposerIndex() != idx {
|
||||
s.setBadBlock(ctx, blockRoot)
|
||||
return nil, errors.New("incorrect proposer index")
|
||||
}
|
||||
return parentState, nil
|
||||
}
|
||||
|
||||
func validateDenebBeaconBlock(blk interfaces.ReadOnlyBeaconBlock) error {
|
||||
if blk.Version() < version.Deneb {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user