prysm-pulse/beacon-chain/sync/subscriber_beacon_blocks.go
Nishant Das 7010e8dec8
Graduate Prune Canonical Attestations Feature (#10623)
* graduate canonical prune feat

* fix test

* fix tests

Co-authored-by: prestonvanloon <preston@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-06-15 09:05:19 +00:00

59 lines
1.6 KiB
Go

package sync
import (
"context"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop"
"github.com/prysmaticlabs/prysm/consensus-types/wrapper"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"google.golang.org/protobuf/proto"
)
func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message) error {
signed, err := wrapper.WrappedSignedBeaconBlock(msg)
if err != nil {
return err
}
if err := wrapper.BeaconBlockIsNil(signed); err != nil {
return err
}
s.setSeenBlockIndexSlot(signed.Block().Slot(), signed.Block().ProposerIndex())
block := signed.Block()
root, err := block.HashTreeRoot()
if err != nil {
return err
}
if err := s.cfg.chain.ReceiveBlock(ctx, signed, root); err != nil {
if blockchain.IsInvalidBlock(err) {
interop.WriteBlockToDisk(signed, true /*failed*/)
s.setBadBlock(ctx, root)
}
return err
}
return err
}
// The input attestations are seen by the network, this deletes them from pool
// so proposers don't include them in a block for the future.
func (s *Service) deleteAttsInPool(atts []*ethpb.Attestation) error {
for _, att := range atts {
if helpers.IsAggregated(att) {
if err := s.cfg.attPool.DeleteAggregatedAttestation(att); err != nil {
return err
}
} else {
// Ideally there's shouldn't be any unaggregated attestation in the block.
if err := s.cfg.attPool.DeleteUnaggregatedAttestation(att); err != nil {
return err
}
}
}
return nil
}