mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
49a0d3caf0
* Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
87 lines
2.5 KiB
Go
87 lines
2.5 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/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// Clients who receive a voluntary exit on this topic MUST validate the conditions within process_voluntary_exit before
|
|
// forwarding it across the network.
|
|
func (r *Service) validateVoluntaryExit(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
|
|
// Validation runs on publish (not just subscriptions), so we should approve any message from
|
|
// ourselves.
|
|
if pid == r.p2p.PeerID() {
|
|
return pubsub.ValidationAccept
|
|
}
|
|
|
|
// The head state will be too far away to validate any voluntary exit.
|
|
if r.initialSync.Syncing() {
|
|
return pubsub.ValidationIgnore
|
|
}
|
|
|
|
ctx, span := trace.StartSpan(ctx, "sync.validateVoluntaryExit")
|
|
defer span.End()
|
|
|
|
m, err := r.decodePubsubMessage(msg)
|
|
if err != nil {
|
|
log.WithError(err).Error("Failed to decode message")
|
|
traceutil.AnnotateError(span, err)
|
|
return pubsub.ValidationReject
|
|
}
|
|
|
|
exit, ok := m.(*ethpb.SignedVoluntaryExit)
|
|
if !ok {
|
|
return pubsub.ValidationReject
|
|
}
|
|
|
|
if exit.Exit == nil {
|
|
return pubsub.ValidationReject
|
|
}
|
|
if r.hasSeenExitIndex(exit.Exit.ValidatorIndex) {
|
|
return pubsub.ValidationIgnore
|
|
}
|
|
|
|
s, err := r.chain.HeadState(ctx)
|
|
if err != nil {
|
|
return pubsub.ValidationIgnore
|
|
}
|
|
|
|
exitedEpochSlot := exit.Exit.Epoch * params.BeaconConfig().SlotsPerEpoch
|
|
if int(exit.Exit.ValidatorIndex) >= s.NumValidators() {
|
|
return pubsub.ValidationReject
|
|
}
|
|
val, err := s.ValidatorAtIndexReadOnly(exit.Exit.ValidatorIndex)
|
|
if err != nil {
|
|
return pubsub.ValidationIgnore
|
|
}
|
|
if err := blocks.VerifyExit(val, exitedEpochSlot, s.Fork(), exit, s.GenesisValidatorRoot()); err != nil {
|
|
return pubsub.ValidationReject
|
|
}
|
|
|
|
msg.ValidatorData = exit // Used in downstream subscriber
|
|
|
|
return pubsub.ValidationAccept
|
|
}
|
|
|
|
// Returns true if the node has already received a valid exit request for the validator with index `i`.
|
|
func (r *Service) hasSeenExitIndex(i uint64) bool {
|
|
r.seenExitLock.RLock()
|
|
defer r.seenExitLock.RUnlock()
|
|
_, seen := r.seenExitCache.Get(i)
|
|
return seen
|
|
}
|
|
|
|
// Set exit request index `i` in seen exit request cache.
|
|
func (r *Service) setExitIndexSeen(i uint64) {
|
|
r.seenExitLock.Lock()
|
|
defer r.seenExitLock.Unlock()
|
|
r.seenExitCache.Add(i, true)
|
|
}
|