mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
e19920aec1
* fatal if impossible to receive chainstart * fix tests * fix * custom delay * completed custom delay * errors * better logs, nothing at genesis * use demo in val * add gazelle * log * starting to log stuff * pass in ops * avoid printing the large #s for debug, still working on tests.. * all around better logging * fixed build error in epoch process * fixed state transiton tests * fixed block tests * lint * verify sigs in randao * ready for inclusion falg * only print waiting when slot is not valid * fix build * mod config * fixed last justified slot issue * fix inclusion * fixed attestation issue * using zero hash from params instead * fix tests * update balance * removed swp * more `- genesis_slot` for logs * rem unused log * fix broken tests * account for skip slots in state root computation * fixes done * validator guide bug fixes - 671 * epoch boundary at the last slot of the epoch * fix epoch issue * more balance cal logs for debugging * greater balance * attestaton fixes * fixes * addressed testrun * fixed ejection balance * fix tests with far future epoch * revert sync change * revert initial sync change * fix changes * off by one att fix * revert the att fix * address comments * format * fix build * rem file
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Validator interface defines the primary methods of a validator client.
|
|
type Validator interface {
|
|
Done()
|
|
WaitForChainStart(ctx context.Context) error
|
|
WaitForActivation(ctx context.Context)
|
|
NextSlot() <-chan uint64
|
|
UpdateAssignments(ctx context.Context, slot uint64) error
|
|
RoleAt(slot uint64) pb.ValidatorRole
|
|
AttestToBlockHead(ctx context.Context, slot uint64)
|
|
ProposeBlock(ctx context.Context, slot uint64)
|
|
}
|
|
|
|
// Run the main validator routine. This routine exits if the context is
|
|
// cancelled.
|
|
//
|
|
// Order of operations:
|
|
// 1 - Initialize validator data
|
|
// 2 - Wait for validator activation
|
|
// 3 - Wait for the next slot start
|
|
// 4 - Update assignments
|
|
// 5 - Determine role at current slot
|
|
// 6 - Perform assigned role, if any
|
|
func run(ctx context.Context, v Validator) {
|
|
defer v.Done()
|
|
if err := v.WaitForChainStart(ctx); err != nil {
|
|
log.Fatalf("Could not determine if beacon chain started: %v", err)
|
|
}
|
|
v.WaitForActivation(ctx)
|
|
if err := v.UpdateAssignments(ctx, params.BeaconConfig().GenesisSlot); err != nil {
|
|
log.WithField("error", err).Error("Failed to update assignments")
|
|
}
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "processSlot")
|
|
defer span.Finish()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
log.Info("Context cancelled, stopping validator")
|
|
return // Exit if context is cancelled.
|
|
case slot := <-v.NextSlot():
|
|
if err := v.UpdateAssignments(ctx, slot); err != nil {
|
|
log.WithField("error", err).Error("Failed to update assignments")
|
|
continue
|
|
}
|
|
role := v.RoleAt(slot)
|
|
|
|
switch role {
|
|
case pb.ValidatorRole_BOTH:
|
|
v.ProposeBlock(ctx, slot)
|
|
v.AttestToBlockHead(ctx, slot)
|
|
case pb.ValidatorRole_ATTESTER:
|
|
v.AttestToBlockHead(ctx, slot)
|
|
case pb.ValidatorRole_PROPOSER:
|
|
v.ProposeBlock(ctx, slot)
|
|
case pb.ValidatorRole_UNKNOWN:
|
|
// This shouldn't happen normally, so it is considered a warning.
|
|
log.WithFields(logrus.Fields{
|
|
"slot": slot - params.BeaconConfig().GenesisSlot,
|
|
"role": role,
|
|
}).Warn("Unknown role, doing nothing")
|
|
default:
|
|
// Do nothing :)
|
|
}
|
|
}
|
|
}
|
|
}
|