mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-29 06:37:17 +00:00
961dd21554
* add reject all pubsub validator to stop automatic propagation of messages * gaz * Merge branch 'master' of github.com:prysmaticlabs/prysm into pubsub-validator * refactor p2p validator pipeline * add sanity check * Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator * fixed up test * rem * gaz * Merge refs/heads/master into pubsub-validator * fix from self test * ensure validator data is set * resolve todo * Merge refs/heads/master into pubsub-validator * gaz * Merge refs/heads/master into pubsub-validator * Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator * Merge refs/heads/master into pubsub-validator * remove all of the 'from self' logic. filed https://github.com/libp2p/go-libp2p-pubsub/issues/250 * Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator * gaz * update comment * Merge refs/heads/master into pubsub-validator * rename "VaidatorData" * Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator * refactor * one more bit of refactoring * Update beacon-chain/sync/validate_beacon_attestation.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * skip validation on self messages, add @nisdas feedback to increment failure counter * Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator * remove flakey
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package sync
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// Clients who receive an attester slashing on this topic MUST validate the conditions within VerifyAttesterSlashing before
|
|
// forwarding it across the network.
|
|
func (r *Service) validateAttesterSlashing(ctx context.Context, pid peer.ID, msg *pubsub.Message) bool {
|
|
// Validation runs on publish (not just subscriptions), so we should approve any message from
|
|
// ourselves.
|
|
if pid == r.p2p.PeerID() {
|
|
return true
|
|
}
|
|
|
|
// The head state will be too far away to validate any slashing.
|
|
if r.initialSync.Syncing() {
|
|
return false
|
|
}
|
|
|
|
ctx, span := trace.StartSpan(ctx, "sync.validateAttesterSlashing")
|
|
defer span.End()
|
|
|
|
m, err := r.decodePubsubMessage(msg)
|
|
if err != nil {
|
|
log.WithError(err).Error("Failed to decode message")
|
|
traceutil.AnnotateError(span, err)
|
|
return false
|
|
}
|
|
slashing, ok := m.(*ethpb.AttesterSlashing)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
// Retrieve head state, advance state to the epoch slot used specified in slashing message.
|
|
s, err := r.chain.HeadState(ctx)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
slashSlot := slashing.Attestation_1.Data.Target.Epoch * params.BeaconConfig().SlotsPerEpoch
|
|
if s.Slot < slashSlot {
|
|
if ctx.Err() != nil {
|
|
return false
|
|
}
|
|
|
|
var err error
|
|
s, err = state.ProcessSlots(ctx, s, slashSlot)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
}
|
|
|
|
if err := blocks.VerifyAttesterSlashing(ctx, s, slashing); err != nil {
|
|
return false
|
|
}
|
|
|
|
msg.ValidatorData = slashing // Used in downstream subscriber
|
|
return true
|
|
}
|