2021-03-12 17:23:56 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-16 18:05:56 +00:00
|
|
|
"github.com/pkg/errors"
|
2022-08-16 12:20:13 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
|
|
|
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
2021-03-12 17:23:56 +00:00
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2022-12-19 21:12:09 +00:00
|
|
|
func (v *validator) HandleKeyReload(ctx context.Context, currentKeys [][fieldparams.BLSPubkeyLength]byte) (anyActive bool, err error) {
|
2021-03-12 17:23:56 +00:00
|
|
|
ctx, span := trace.StartSpan(ctx, "validator.HandleKeyReload")
|
|
|
|
defer span.End()
|
|
|
|
|
2022-12-19 21:12:09 +00:00
|
|
|
statusRequestKeys := make([][]byte, len(currentKeys))
|
|
|
|
for i := range currentKeys {
|
|
|
|
statusRequestKeys[i] = currentKeys[i][:]
|
2021-03-12 17:23:56 +00:00
|
|
|
}
|
|
|
|
resp, err := v.validatorClient.MultipleValidatorStatus(ctx, ð.MultipleValidatorStatusRequest{
|
|
|
|
PublicKeys: statusRequestKeys,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
statuses := make([]*validatorStatus, len(resp.Statuses))
|
|
|
|
for i, s := range resp.Statuses {
|
|
|
|
statuses[i] = &validatorStatus{
|
|
|
|
publicKey: resp.PublicKeys[i],
|
|
|
|
status: s,
|
|
|
|
index: resp.Indices[i],
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 18:05:56 +00:00
|
|
|
vals, err := v.beaconClient.ListValidators(ctx, ð.ListValidatorsRequest{Active: true, PageSize: 0})
|
|
|
|
if err != nil {
|
|
|
|
return false, errors.Wrap(err, "could not get active validator count")
|
|
|
|
}
|
|
|
|
anyActive = v.checkAndLogValidatorStatus(statuses, uint64(vals.TotalSize))
|
2021-03-12 17:23:56 +00:00
|
|
|
if anyActive {
|
|
|
|
logActiveValidatorStatus(statuses)
|
|
|
|
}
|
|
|
|
|
|
|
|
return anyActive, nil
|
|
|
|
}
|