github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/sync/subscriber_beacon_blocks.go (about) 1 package sync 2 3 import ( 4 "context" 5 "errors" 6 7 "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" 8 "github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop" 9 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 10 "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper" 11 "github.com/prysmaticlabs/prysm/shared/featureconfig" 12 "google.golang.org/protobuf/proto" 13 ) 14 15 func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message) error { 16 rBlock, ok := msg.(*ethpb.SignedBeaconBlock) 17 if !ok { 18 return errors.New("message is not type *ethpb.SignedBeaconBlock") 19 } 20 signed := wrapper.WrappedPhase0SignedBeaconBlock(rBlock) 21 22 if signed.IsNil() || signed.Block().IsNil() { 23 return errors.New("nil block") 24 } 25 26 s.setSeenBlockIndexSlot(signed.Block().Slot(), signed.Block().ProposerIndex()) 27 28 block := signed.Block() 29 30 root, err := block.HashTreeRoot() 31 if err != nil { 32 return err 33 } 34 35 if err := s.cfg.Chain.ReceiveBlock(ctx, signed, root); err != nil { 36 interop.WriteBlockToDisk(signed, true /*failed*/) 37 s.setBadBlock(ctx, root) 38 return err 39 } 40 41 if !featureconfig.Get().CorrectlyPruneCanonicalAtts { 42 // Delete attestations from the block in the pool to avoid inclusion in future block. 43 if err := s.deleteAttsInPool(block.Body().Attestations()); err != nil { 44 log.Debugf("Could not delete attestations in pool: %v", err) 45 return nil 46 } 47 } 48 return err 49 } 50 51 // The input attestations are seen by the network, this deletes them from pool 52 // so proposers don't include them in a block for the future. 53 func (s *Service) deleteAttsInPool(atts []*ethpb.Attestation) error { 54 for _, att := range atts { 55 if helpers.IsAggregated(att) { 56 if err := s.cfg.AttPool.DeleteAggregatedAttestation(att); err != nil { 57 return err 58 } 59 } else { 60 // Ideally there's shouldn't be any unaggregated attestation in the block. 61 if err := s.cfg.AttPool.DeleteUnaggregatedAttestation(att); err != nil { 62 return err 63 } 64 } 65 } 66 return nil 67 }