Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee Recipient : ux log fixes and prevent validator from calling beacon node if flags are not provided. #10406

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion validator/accounts/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (_ MockValidator) CheckDoppelGanger(_ context.Context) error {
panic("implement me")
}

// PrepareBeaconProposer for mocking
// UpdateFeeRecipient for mocking
func (_ MockValidator) UpdateFeeRecipient(_ context.Context, _ keymanager.IKeymanager) error {
panic("implement me")
}
Expand Down
132 changes: 66 additions & 66 deletions validator/client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,82 +48,82 @@ type GenesisFetcher interface {
// ValidatorService represents a service to manage the validator client
// routine.
type ValidatorService struct {
useWeb bool
emitAccountMetrics bool
logValidatorBalances bool
logDutyCountDown bool
interopKeysConfig *local.InteropKeymanagerConfig
conn *grpc.ClientConn
grpcRetryDelay time.Duration
grpcRetries uint
maxCallRecvMsgSize int
cancel context.CancelFunc
walletInitializedFeed *event.Feed
wallet *wallet.Wallet
graffitiStruct *graffiti.Graffiti
dataDir string
withCert string
endpoint string
ctx context.Context
validator iface.Validator
db db.Database
grpcHeaders []string
graffiti []byte
web3SignerConfig *remote_web3signer.SetupConfig
prepareBeaconProposalConfig *validator_service_config.FeeRecipientConfig
useWeb bool
emitAccountMetrics bool
logValidatorBalances bool
logDutyCountDown bool
interopKeysConfig *local.InteropKeymanagerConfig
conn *grpc.ClientConn
grpcRetryDelay time.Duration
grpcRetries uint
maxCallRecvMsgSize int
cancel context.CancelFunc
walletInitializedFeed *event.Feed
wallet *wallet.Wallet
graffitiStruct *graffiti.Graffiti
dataDir string
withCert string
endpoint string
ctx context.Context
validator iface.Validator
db db.Database
grpcHeaders []string
graffiti []byte
web3SignerConfig *remote_web3signer.SetupConfig
feeRecipientConfig *validator_service_config.FeeRecipientConfig
}

// Config for the validator service.
type Config struct {
UseWeb bool
LogValidatorBalances bool
EmitAccountMetrics bool
LogDutyCountDown bool
InteropKeysConfig *local.InteropKeymanagerConfig
Wallet *wallet.Wallet
WalletInitializedFeed *event.Feed
GrpcRetriesFlag uint
GrpcMaxCallRecvMsgSizeFlag int
GrpcRetryDelay time.Duration
GraffitiStruct *graffiti.Graffiti
Validator iface.Validator
ValDB db.Database
CertFlag string
DataDir string
GrpcHeadersFlag string
GraffitiFlag string
Endpoint string
Web3SignerConfig *remote_web3signer.SetupConfig
PrepareBeaconProposalConfig *validator_service_config.FeeRecipientConfig
UseWeb bool
LogValidatorBalances bool
EmitAccountMetrics bool
LogDutyCountDown bool
InteropKeysConfig *local.InteropKeymanagerConfig
Wallet *wallet.Wallet
WalletInitializedFeed *event.Feed
GrpcRetriesFlag uint
GrpcMaxCallRecvMsgSizeFlag int
GrpcRetryDelay time.Duration
GraffitiStruct *graffiti.Graffiti
Validator iface.Validator
ValDB db.Database
CertFlag string
DataDir string
GrpcHeadersFlag string
GraffitiFlag string
Endpoint string
Web3SignerConfig *remote_web3signer.SetupConfig
FeeRecipientConfig *validator_service_config.FeeRecipientConfig
}

// NewValidatorService creates a new validator service for the service
// registry.
func NewValidatorService(ctx context.Context, cfg *Config) (*ValidatorService, error) {
ctx, cancel := context.WithCancel(ctx)
return &ValidatorService{
ctx: ctx,
cancel: cancel,
endpoint: cfg.Endpoint,
withCert: cfg.CertFlag,
dataDir: cfg.DataDir,
graffiti: []byte(cfg.GraffitiFlag),
logValidatorBalances: cfg.LogValidatorBalances,
emitAccountMetrics: cfg.EmitAccountMetrics,
maxCallRecvMsgSize: cfg.GrpcMaxCallRecvMsgSizeFlag,
grpcRetries: cfg.GrpcRetriesFlag,
grpcRetryDelay: cfg.GrpcRetryDelay,
grpcHeaders: strings.Split(cfg.GrpcHeadersFlag, ","),
validator: cfg.Validator,
db: cfg.ValDB,
wallet: cfg.Wallet,
walletInitializedFeed: cfg.WalletInitializedFeed,
useWeb: cfg.UseWeb,
interopKeysConfig: cfg.InteropKeysConfig,
graffitiStruct: cfg.GraffitiStruct,
logDutyCountDown: cfg.LogDutyCountDown,
web3SignerConfig: cfg.Web3SignerConfig,
prepareBeaconProposalConfig: cfg.PrepareBeaconProposalConfig,
ctx: ctx,
cancel: cancel,
endpoint: cfg.Endpoint,
withCert: cfg.CertFlag,
dataDir: cfg.DataDir,
graffiti: []byte(cfg.GraffitiFlag),
logValidatorBalances: cfg.LogValidatorBalances,
emitAccountMetrics: cfg.EmitAccountMetrics,
maxCallRecvMsgSize: cfg.GrpcMaxCallRecvMsgSizeFlag,
grpcRetries: cfg.GrpcRetriesFlag,
grpcRetryDelay: cfg.GrpcRetryDelay,
grpcHeaders: strings.Split(cfg.GrpcHeadersFlag, ","),
validator: cfg.Validator,
db: cfg.ValDB,
wallet: cfg.Wallet,
walletInitializedFeed: cfg.WalletInitializedFeed,
useWeb: cfg.UseWeb,
interopKeysConfig: cfg.InteropKeysConfig,
graffitiStruct: cfg.GraffitiStruct,
logDutyCountDown: cfg.LogDutyCountDown,
web3SignerConfig: cfg.Web3SignerConfig,
feeRecipientConfig: cfg.FeeRecipientConfig,
}, nil
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func (v *ValidatorService) Start() {
eipImportBlacklistedPublicKeys: slashablePublicKeys,
logDutyCountDown: v.logDutyCountDown,
Web3SignerConfig: v.web3SignerConfig,
prepareBeaconProposalConfig: v.prepareBeaconProposalConfig,
feeRecipientConfig: v.feeRecipientConfig,
walletIntializedChannel: make(chan *wallet.Wallet, 1),
}
// To resolve a race condition at startup due to the interface
Expand Down
2 changes: 1 addition & 1 deletion validator/client/testutil/mock_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (fv *FakeValidator) HandleKeyReload(_ context.Context, newKeys [][fieldpara
func (_ *FakeValidator) SubmitSignedContributionAndProof(_ context.Context, _ types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
}

// PrepareBeaconProposer for mocking
// UpdateFeeRecipient for mocking
func (_ *FakeValidator) UpdateFeeRecipient(_ context.Context, _ keymanager.IKeymanager) error {
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type validator struct {
graffiti []byte
voteStats voteStats
Web3SignerConfig *remote_web3signer.SetupConfig
prepareBeaconProposalConfig *validator_service_config.FeeRecipientConfig
feeRecipientConfig *validator_service_config.FeeRecipientConfig
walletIntializedChannel chan *wallet.Wallet
}

Expand Down Expand Up @@ -938,6 +938,10 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du

// UpdateFeeRecipient calls the prepareBeaconProposer RPC to set the fee recipient.
func (v *validator) UpdateFeeRecipient(ctx context.Context, km keymanager.IKeymanager) error {
if v.feeRecipientConfig == nil {
log.Warnln("Fee recipient config not set, skipping fee recipient update. Validator will continue proposing using beacon node specified fee recipient.")
return nil
}
if km == nil {
return errors.New("keymanager is nil when calling PrepareBeaconProposer")
}
Expand Down Expand Up @@ -981,12 +985,12 @@ func (v *validator) feeRecipients(ctx context.Context, pubkeys [][fieldparams.BL
validatorIndex = ind
v.pubkeyToValidatorIndex[key] = validatorIndex
}
if v.prepareBeaconProposalConfig.ProposeConfig != nil {
option, ok := v.prepareBeaconProposalConfig.ProposeConfig[key]
if v.feeRecipientConfig.ProposeConfig != nil {
option, ok := v.feeRecipientConfig.ProposeConfig[key]
if option != nil && ok {
feeRecipient = option.FeeRecipient
} else {
feeRecipient = v.prepareBeaconProposalConfig.DefaultConfig.FeeRecipient
feeRecipient = v.feeRecipientConfig.DefaultConfig.FeeRecipient
}
}
validatorToFeeRecipientArray = append(validatorToFeeRecipientArray, &ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
Expand Down
33 changes: 26 additions & 7 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) {
keyManager: km,
genesisTime: 1,
pubkeyToValidatorIndex: map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex{pubKey: 1},
prepareBeaconProposalConfig: &validator_service_config.FeeRecipientConfig{
feeRecipientConfig: &validator_service_config.FeeRecipientConfig{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) {
keyManager: km,
genesisTime: 1,
pubkeyToValidatorIndex: map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex{pubKey: 1},
prepareBeaconProposalConfig: &validator_service_config.FeeRecipientConfig{
feeRecipientConfig: &validator_service_config.FeeRecipientConfig{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
Expand Down Expand Up @@ -1477,7 +1477,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
require.NoError(t, err)
v.prepareBeaconProposalConfig = &validator_service_config.FeeRecipientConfig{
v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
Expand All @@ -1493,6 +1493,25 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
return &v
},
},
{
name: " Skip if no config",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 1,
Offset: 1,
},
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
return &v
},
},
{
name: " Happy Path validator index not found in cache",
validatorSetter: func(t *testing.T) *validator {
Expand All @@ -1509,7 +1528,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
v.prepareBeaconProposalConfig = &validator_service_config.FeeRecipientConfig{
v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{
ProposeConfig: nil,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
Expand Down Expand Up @@ -1558,7 +1577,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
config[keys[0]] = &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
}
v.prepareBeaconProposalConfig = &validator_service_config.FeeRecipientConfig{
v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{
ProposeConfig: config,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
Expand Down Expand Up @@ -1597,7 +1616,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
config[keys[0]] = &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.Address{},
}
v.prepareBeaconProposalConfig = &validator_service_config.FeeRecipientConfig{
v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{
ProposeConfig: config,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
Expand Down Expand Up @@ -1634,7 +1653,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) {
config[keys[0]] = &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
}
v.prepareBeaconProposalConfig = &validator_service_config.FeeRecipientConfig{
v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{
ProposeConfig: config,
DefaultConfig: &validator_service_config.FeeRecipientOptions{
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
Expand Down
4 changes: 2 additions & 2 deletions validator/client/wait_for_activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func (v *validator) waitForActivation(ctx context.Context, accountsChangedChan <

valActivated := v.checkAndLogValidatorStatus(statuses)
if valActivated {
logActiveValidatorStatus(statuses)
// Set properties on the beacon node like the fee recipient for validators that are being used & active.
if err := v.UpdateFeeRecipient(ctx, remoteKm); err != nil {
return err
}
logActiveValidatorStatus(statuses)
} else {
continue
}
Expand Down Expand Up @@ -179,11 +179,11 @@ func (v *validator) waitForActivation(ctx context.Context, accountsChangedChan <

valActivated := v.checkAndLogValidatorStatus(statuses)
if valActivated {
logActiveValidatorStatus(statuses)
// Set properties on the beacon node like the fee recipient for validators that are being used & active.
if err := v.UpdateFeeRecipient(ctx, v.keyManager); err != nil {
return err
}
logActiveValidatorStatus(statuses)
} else {
continue
}
Expand Down
Loading