diff --git a/validator/client/validator.go b/validator/client/validator.go index bc5c14d5096c..5c7f2db3d6ae 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -986,14 +986,19 @@ func (v *validator) feeRecipients(ctx context.Context, pubkeys [][fieldparams.BL validatorIndex = ind v.pubkeyToValidatorIndex[key] = validatorIndex } + if v.feeRecipientConfig.DefaultConfig != nil { + feeRecipient = v.feeRecipientConfig.DefaultConfig.FeeRecipient + } if v.feeRecipientConfig.ProposeConfig != nil { option, ok := v.feeRecipientConfig.ProposeConfig[key] - if option != nil && ok { + if ok && option != nil { + // override the default if a proposeconfig is set feeRecipient = option.FeeRecipient - } else { - feeRecipient = v.feeRecipientConfig.DefaultConfig.FeeRecipient } } + if hexutil.Encode(feeRecipient.Bytes()) == fieldparams.EthBurnAddressHex { + log.Warnln("Fee recipient is set to the burn address. You will not be rewarded transaction fees on this setting. Please set a different fee recipient.") + } validatorToFeeRecipientArray = append(validatorToFeeRecipientArray, ðpb.PrepareBeaconProposerRequest_FeeRecipientContainer{ ValidatorIndex: validatorIndex, FeeRecipient: feeRecipient[:], diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index 6d5738af8bcf..6762502db223 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "math" + "strings" "sync" "testing" "time" @@ -1457,9 +1458,11 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { ctx := context.Background() db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + defaultFeeHex := "0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9" tests := []struct { name string validatorSetter func(t *testing.T) *validator + feeRecipientMap map[types.ValidatorIndex]string err string }{ { @@ -1486,7 +1489,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{ ProposeConfig: nil, DefaultConfig: &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress(defaultFeeHex), }, } client.EXPECT().ValidatorIndex( @@ -1498,6 +1501,9 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { return &v }, + feeRecipientMap: map[types.ValidatorIndex]string{ + 1: defaultFeeHex, + }, }, { name: " Skip if no config", @@ -1537,7 +1543,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{ ProposeConfig: nil, DefaultConfig: &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress(defaultFeeHex), }, } km, err := v.Keymanager() @@ -1552,6 +1558,9 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { }, nil) return &v }, + feeRecipientMap: map[types.ValidatorIndex]string{ + 1: defaultFeeHex, + }, }, { name: " Happy Path proposer config not nil", @@ -1563,7 +1572,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex), useWeb: false, interopKeysConfig: &local.InteropKeymanagerConfig{ - NumValidatorKeys: 1, + NumValidatorKeys: 2, Offset: 1, }, } @@ -1580,17 +1589,27 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { ).Return(ðpb.ValidatorIndexResponse{ Index: 1, }, nil) + client.EXPECT().ValidatorIndex( + ctx, // ctx + ðpb.ValidatorIndexRequest{PublicKey: keys[1][:]}, + ).Return(ðpb.ValidatorIndexResponse{ + Index: 2, + }, nil) config[keys[0]] = &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"), } v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{ ProposeConfig: config, DefaultConfig: &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress(defaultFeeHex), }, } return &v }, + feeRecipientMap: map[types.ValidatorIndex]string{ + 1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9", + 2: defaultFeeHex, + }, }, { name: " proposer config not nil but fee recipient empty ", @@ -1625,9 +1644,10 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{ ProposeConfig: config, DefaultConfig: &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress(defaultFeeHex), }, } + return &v }, }, @@ -1662,7 +1682,7 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { v.feeRecipientConfig = &validator_service_config.FeeRecipientConfig{ ProposeConfig: config, DefaultConfig: &validator_service_config.FeeRecipientOptions{ - FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"), + FeeRecipient: common.HexToAddress(defaultFeeHex), }, } return &v @@ -1674,9 +1694,21 @@ func TestValidator_UdpateFeeRecipient(t *testing.T) { v := tt.validatorSetter(t) km, err := v.Keymanager() require.NoError(t, err) + pubkeys, err := km.FetchValidatingPublicKeys(ctx) + require.NoError(t, err) + if tt.feeRecipientMap != nil { + feeRecipients, err := v.feeRecipients(ctx, pubkeys) + require.NoError(t, err) + for _, recipient := range feeRecipients { + require.Equal(t, strings.ToLower(tt.feeRecipientMap[recipient.ValidatorIndex]), strings.ToLower(hexutil.Encode(recipient.FeeRecipient))) + } + require.Equal(t, len(tt.feeRecipientMap), len(feeRecipients)) + } + if err := v.UpdateFeeRecipient(ctx, km); tt.err != "" { assert.ErrorContains(t, tt.err, err) } + }) } }