Skip to content

Commit

Permalink
Merge branch 'master' of github.com:prysmaticlabs/prysm
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Apr 18, 2020
2 parents 927d8d9 + fb26177 commit 491c3e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
63 changes: 33 additions & 30 deletions beacon-chain/sync/validate_beacon_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/traceutil"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -89,36 +90,38 @@ func (r *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
return false
}

hasStateSummaryDB := r.db.HasStateSummary(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
hasStateSummaryCache := r.stateSummaryCache.Has(bytesutil.ToBytes32(blk.Block.ParentRoot))
if !hasStateSummaryDB && !hasStateSummaryCache {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("No access to parent state")
return false
}
parentState, err := r.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not get parent state")
return false
}

if err := blocks.VerifyBlockHeaderSignature(parentState, blk); err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not verify block signature")
return false
}

err = parentState.SetSlot(blk.Block.Slot)
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not set parent state slot")
return false
}
idx, err := helpers.BeaconProposerIndex(parentState)
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not get proposer index using parent state")
return false
}
if blk.Block.ProposerIndex != idx {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Incorrect proposer index")
return false
if !featureconfig.Get().DisableNewStateMgmt {
hasStateSummaryDB := r.db.HasStateSummary(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
hasStateSummaryCache := r.stateSummaryCache.Has(bytesutil.ToBytes32(blk.Block.ParentRoot))
if !hasStateSummaryDB && !hasStateSummaryCache {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("No access to parent state")
return false
}
parentState, err := r.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not get parent state")
return false
}

if err := blocks.VerifyBlockHeaderSignature(parentState, blk); err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not verify block signature")
return false
}

err = parentState.SetSlot(blk.Block.Slot)
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not set parent state slot")
return false
}
idx, err := helpers.BeaconProposerIndex(parentState)
if err != nil {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Could not get proposer index using parent state")
return false
}
if blk.Block.ProposerIndex != idx {
log.WithError(err).WithField("blockSlot", blk.Block.Slot).Warn("Incorrect proposer index")
return false
}
}

msg.ValidatorData = blk // Used in downstream subscriber
Expand Down
2 changes: 2 additions & 0 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ var (
Name: "disable-protect-proposer",
Usage: "Disables functionality to prevent the validator client from signing and " +
"broadcasting 2 different block proposals in the same epoch. Protects from slashing.",
Value: true,
}
disableProtectAttesterFlag = &cli.BoolFlag{
Name: "disable-protect-attester",
Usage: "Disables functionality to prevent the validator client from signing and " +
"broadcasting 2 any slashable attestations.",
Value: true,
}
disableStrictAttestationPubsubVerificationFlag = &cli.BoolFlag{
Name: "disable-strict-attestation-pubsub-verification",
Expand Down

0 comments on commit 491c3e6

Please sign in to comment.