mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
migrating code from PR#12343 (#12371)
This commit is contained in:
@@ -192,7 +192,7 @@ func (MockValidator) HasProposerSettings() bool {
|
||||
}
|
||||
|
||||
// PushProposerSettings for mocking
|
||||
func (_ MockValidator) PushProposerSettings(_ context.Context, _ keymanager.IKeymanager, _ time.Time) error {
|
||||
func (_ MockValidator) PushProposerSettings(_ context.Context, _ keymanager.IKeymanager, _ primitives.Slot, _ time.Time) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ type Validator interface {
|
||||
ReceiveBlocks(ctx context.Context, connectionErrorChannel chan<- error)
|
||||
HandleKeyReload(ctx context.Context, currentKeys [][fieldparams.BLSPubkeyLength]byte) (bool, error)
|
||||
CheckDoppelGanger(ctx context.Context) error
|
||||
PushProposerSettings(ctx context.Context, km keymanager.IKeymanager, deadline time.Time) error
|
||||
PushProposerSettings(ctx context.Context, km keymanager.IKeymanager, slot primitives.Slot, deadline time.Time) error
|
||||
SignValidatorRegistrationRequest(ctx context.Context, signer SigningFunc, newValidatorRegistration *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error)
|
||||
ProposerSettings() *validatorserviceconfig.ProposerSettings
|
||||
SetProposerSettings(*validatorserviceconfig.ProposerSettings)
|
||||
|
||||
@@ -58,7 +58,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
log.Infof("Validator client started with provided proposer settings that sets options such as fee recipient"+
|
||||
" and will periodically update the beacon node and custom builder (if --%s)", flags.EnableBuilderFlag.Name)
|
||||
deadline := time.Now().Add(time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)
|
||||
if err := v.PushProposerSettings(ctx, km, deadline); err != nil {
|
||||
if err := v.PushProposerSettings(ctx, km, headSlot, deadline); err != nil {
|
||||
if errors.Is(err, ErrBuilderValidatorRegistration) {
|
||||
log.WithError(err).Warn("Push proposer settings error")
|
||||
} else {
|
||||
@@ -119,7 +119,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
go func() {
|
||||
//deadline set for end of epoch
|
||||
epochDeadline := v.SlotDeadline(slot + params.BeaconConfig().SlotsPerEpoch - 1)
|
||||
if err := v.PushProposerSettings(ctx, km, epochDeadline); err != nil {
|
||||
if err := v.PushProposerSettings(ctx, km, slot, epochDeadline); err != nil {
|
||||
log.WithError(err).Warn("Failed to update proposer settings")
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -259,7 +259,7 @@ func (*FakeValidator) HasProposerSettings() bool {
|
||||
}
|
||||
|
||||
// PushProposerSettings for mocking
|
||||
func (fv *FakeValidator) PushProposerSettings(ctx context.Context, _ keymanager.IKeymanager, deadline time.Time) error {
|
||||
func (fv *FakeValidator) PushProposerSettings(ctx context.Context, km keymanager.IKeymanager, slot primitives.Slot, deadline time.Time) error {
|
||||
nctx, cancel := context.WithDeadline(ctx, deadline)
|
||||
ctx = nctx
|
||||
defer cancel()
|
||||
|
||||
@@ -984,7 +984,7 @@ func (v *validator) SetProposerSettings(settings *validatorserviceconfig.Propose
|
||||
}
|
||||
|
||||
// PushProposerSettings calls the prepareBeaconProposer RPC to set the fee recipient and also the register validator API if using a custom builder.
|
||||
func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKeymanager, deadline time.Time) error {
|
||||
func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKeymanager, slot primitives.Slot, deadline time.Time) error {
|
||||
if km == nil {
|
||||
return errors.New("keymanager is nil when calling PrepareBeaconProposer")
|
||||
}
|
||||
@@ -1000,7 +1000,7 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
|
||||
log.Info("No imported public keys. Skipping prepare proposer routine")
|
||||
return nil
|
||||
}
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys)
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys, slot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1034,7 +1034,7 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
|
||||
|
||||
return nil
|
||||
}
|
||||
func (v *validator) filterAndCacheActiveKeys(ctx context.Context, pubkeys [][fieldparams.BLSPubkeyLength]byte) ([][fieldparams.BLSPubkeyLength]byte, error) {
|
||||
func (v *validator) filterAndCacheActiveKeys(ctx context.Context, pubkeys [][fieldparams.BLSPubkeyLength]byte, slot primitives.Slot) ([][fieldparams.BLSPubkeyLength]byte, error) {
|
||||
filteredKeys := make([][fieldparams.BLSPubkeyLength]byte, 0)
|
||||
statusRequestKeys := make([][]byte, 0)
|
||||
for _, k := range pubkeys {
|
||||
@@ -1061,7 +1061,11 @@ func (v *validator) filterAndCacheActiveKeys(ctx context.Context, pubkeys [][fie
|
||||
}
|
||||
for i, status := range resp.Statuses {
|
||||
// skip registration creation if validator is not active status
|
||||
if status.Status != ethpb.ValidatorStatus_ACTIVE {
|
||||
nonActive := status.Status != ethpb.ValidatorStatus_ACTIVE
|
||||
// Handle edge case at the start of the epoch with newly activated validators
|
||||
currEpoch := primitives.Epoch(slot / params.BeaconConfig().SlotsPerEpoch)
|
||||
currActivated := status.Status == ethpb.ValidatorStatus_PENDING && currEpoch >= status.ActivationEpoch
|
||||
if nonActive && !currActivated {
|
||||
log.WithFields(logrus.Fields{
|
||||
"publickey": hexutil.Encode(resp.PublicKeys[i]),
|
||||
"status": status.Status.String(),
|
||||
|
||||
@@ -1960,7 +1960,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
require.Equal(t, len(signedRegisterValidatorRequests), len(v.signedValidatorRegistrations))
|
||||
}
|
||||
deadline := time.Now().Add(time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)
|
||||
if err := v.PushProposerSettings(ctx, km, deadline); tt.err != "" {
|
||||
if err := v.PushProposerSettings(ctx, km, 0, deadline); tt.err != "" {
|
||||
assert.ErrorContains(t, tt.err, err)
|
||||
}
|
||||
if len(tt.logMessages) > 0 {
|
||||
@@ -2082,7 +2082,7 @@ func TestValidator_buildPrepProposerReqs_WithoutDefaultConfig(t *testing.T) {
|
||||
FeeRecipient: feeRecipient2[:],
|
||||
},
|
||||
}
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys)
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys, 0)
|
||||
require.NoError(t, err)
|
||||
actual, err := v.buildPrepProposerReqs(ctx, filteredKeys)
|
||||
require.NoError(t, err)
|
||||
@@ -2196,7 +2196,7 @@ func TestValidator_buildPrepProposerReqs_WithDefaultConfig(t *testing.T) {
|
||||
FeeRecipient: defaultFeeRecipient[:],
|
||||
},
|
||||
}
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys)
|
||||
filteredKeys, err := v.filterAndCacheActiveKeys(ctx, pubkeys, 0)
|
||||
require.NoError(t, err)
|
||||
actual, err := v.buildPrepProposerReqs(ctx, filteredKeys)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user