mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d17996f8b0
* Update V3 from V4 * Fix build v3 -> v4 * Update ssz * Update beacon_chain.pb.go * Fix formatter import * Update update-mockgen.sh comment to v4 * Fix conflicts. Pass build and tests * Fix test
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain"
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition/interop"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message) error {
|
|
signed, err := blocks.NewSignedBeaconBlock(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := blocks.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) {
|
|
r := blockchain.InvalidBlockRoot(err)
|
|
if r != [32]byte{} {
|
|
s.setBadBlock(ctx, r) // Setting head block as bad.
|
|
} else {
|
|
interop.WriteBlockToDisk(signed, true /*failed*/)
|
|
s.setBadBlock(ctx, root)
|
|
}
|
|
}
|
|
// Set the returned invalid ancestors as bad.
|
|
for _, root := range blockchain.InvalidAncestorRoots(err) {
|
|
s.setBadBlock(ctx, root)
|
|
}
|
|
return err
|
|
}
|
|
return err
|
|
}
|