mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Improve validator set change event readability and error handling (#11797)
This commit is contained in:
@@ -59,7 +59,7 @@ type Validator interface {
|
||||
AllValidatorsAreExited(ctx context.Context) (bool, error)
|
||||
Keymanager() (keymanager.IKeymanager, error)
|
||||
ReceiveBlocks(ctx context.Context, connectionErrorChannel chan<- error)
|
||||
HandleKeyReload(ctx context.Context, newKeys [][fieldparams.BLSPubkeyLength]byte) (bool, error)
|
||||
HandleKeyReload(ctx context.Context, currentKeys [][fieldparams.BLSPubkeyLength]byte) (bool, error)
|
||||
CheckDoppelGanger(ctx context.Context) error
|
||||
PushProposerSettings(ctx context.Context, km keymanager.IKeymanager) error
|
||||
SignValidatorRegistrationRequest(ctx context.Context, signer SigningFunc, newValidatorRegistration *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error)
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
|
||||
// HandleKeyReload makes sure the validator keeps operating correctly after a change to the underlying keys.
|
||||
// It is also responsible for logging out information about the new state of keys.
|
||||
func (v *validator) HandleKeyReload(ctx context.Context, newKeys [][fieldparams.BLSPubkeyLength]byte) (anyActive bool, err error) {
|
||||
func (v *validator) HandleKeyReload(ctx context.Context, currentKeys [][fieldparams.BLSPubkeyLength]byte) (anyActive bool, err error) {
|
||||
ctx, span := trace.StartSpan(ctx, "validator.HandleKeyReload")
|
||||
defer span.End()
|
||||
|
||||
statusRequestKeys := make([][]byte, len(newKeys))
|
||||
for i := range newKeys {
|
||||
statusRequestKeys[i] = newKeys[i][:]
|
||||
statusRequestKeys := make([][]byte, len(currentKeys))
|
||||
for i := range currentKeys {
|
||||
statusRequestKeys[i] = currentKeys[i][:]
|
||||
}
|
||||
resp, err := v.validatorClient.MultipleValidatorStatus(ctx, ð.MultipleValidatorStatusRequest{
|
||||
PublicKeys: statusRequestKeys,
|
||||
|
||||
@@ -38,7 +38,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
cleanup := v.Done
|
||||
defer cleanup()
|
||||
|
||||
headSlot, err := waitForActivation(ctx, v)
|
||||
headSlot, err := initializeValidatorAndGetHeadSlot(ctx, v)
|
||||
if err != nil {
|
||||
return // Exit if context is canceled.
|
||||
}
|
||||
@@ -89,16 +89,16 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
go v.ReceiveBlocks(ctx, connectionErrorChannel)
|
||||
continue
|
||||
}
|
||||
case newKeys := <-accountsChangedChan:
|
||||
anyActive, err := v.HandleKeyReload(ctx, newKeys)
|
||||
case currentKeys := <-accountsChangedChan:
|
||||
anyActive, err := v.HandleKeyReload(ctx, currentKeys)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not properly handle reloaded keys")
|
||||
}
|
||||
if !anyActive {
|
||||
log.Info("No active keys found. Waiting for activation...")
|
||||
log.Warn("No active keys found. Waiting for activation...")
|
||||
err := v.WaitForActivation(ctx, accountsChangedChan)
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Could not wait for validator activation")
|
||||
log.WithError(err).Warn("Could not wait for validator activation")
|
||||
}
|
||||
}
|
||||
case slot := <-v.NextSlot():
|
||||
@@ -165,7 +165,7 @@ func reloadRemoteKeys(ctx context.Context, km keymanager.IKeymanager) {
|
||||
}
|
||||
}
|
||||
|
||||
func waitForActivation(ctx context.Context, v iface.Validator) (types.Slot, error) {
|
||||
func initializeValidatorAndGetHeadSlot(ctx context.Context, v iface.Validator) (types.Slot, error) {
|
||||
ticker := time.NewTicker(backOffPeriod)
|
||||
defer ticker.Stop()
|
||||
|
||||
@@ -206,10 +206,6 @@ func waitForActivation(ctx context.Context, v iface.Validator) (types.Slot, erro
|
||||
log.WithError(err).Fatal("Could not determine if beacon node synced")
|
||||
}
|
||||
err = v.WaitForActivation(ctx, nil /* accountsChangedChan */)
|
||||
if isConnectionError(err) {
|
||||
log.WithError(err).Warn("Could not wait for validator activation")
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Could not wait for validator activation")
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ func TestRetry_On_ConnectionError(t *testing.T) {
|
||||
time.Sleep(time.Duration(retry*6) * backOffPeriod)
|
||||
cancel()
|
||||
// every call will fail retry=10 times so first one will be called 4 * retry=10.
|
||||
assert.Equal(t, retry*4, v.WaitForChainStartCalled, "Expected WaitForChainStart() to be called")
|
||||
assert.Equal(t, retry*3, v.WaitForSyncCalled, "Expected WaitForSync() to be called")
|
||||
assert.Equal(t, retry*2, v.WaitForActivationCalled, "Expected WaitForActivation() to be called")
|
||||
assert.Equal(t, retry*3, v.WaitForChainStartCalled, "Expected WaitForChainStart() to be called")
|
||||
assert.Equal(t, retry*2, v.WaitForSyncCalled, "Expected WaitForSync() to be called")
|
||||
assert.Equal(t, retry, v.WaitForActivationCalled, "Expected WaitForActivation() to be called")
|
||||
assert.Equal(t, retry, v.CanonicalHeadSlotCalled, "Expected WaitForActivation() to be called")
|
||||
assert.Equal(t, retry, v.ReceiveBlocksCalled, "Expected WaitForActivation() to be called")
|
||||
}
|
||||
|
||||
@@ -85,8 +85,11 @@ func (fv *FakeValidator) WaitForChainStart(_ context.Context) error {
|
||||
}
|
||||
|
||||
// WaitForActivation for mocking.
|
||||
func (fv *FakeValidator) WaitForActivation(_ context.Context, _ chan [][fieldparams.BLSPubkeyLength]byte) error {
|
||||
func (fv *FakeValidator) WaitForActivation(_ context.Context, accountChan chan [][fieldparams.BLSPubkeyLength]byte) error {
|
||||
fv.WaitForActivationCalled++
|
||||
if accountChan == nil {
|
||||
return nil
|
||||
}
|
||||
if fv.RetryTillSuccess >= fv.WaitForActivationCalled {
|
||||
return iface.ErrConnectionIssue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user