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

changing gaslimit to validator registration #10992

Merged
merged 10 commits into from
Jul 6, 2022
7 changes: 7 additions & 0 deletions cmd/validator/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ var (
" For additional setting overrides use the --" + ProposerSettingsFlag.Name + " or --" + ProposerSettingsURLFlag.Name + " Flags. ",
Value: params.BeaconConfig().EthBurnAddressHex,
}

// EnableValidatorRegistrationFlag enables the periodic validator registration API calls that will update the custom builder with validator settings.
EnableValidatorRegistrationFlag = &cli.StringFlag{
Name: "enable-validator-registration",
Usage: "Enables validator registration APIs ( MEV Builder APIs) for the validator client to update settings such as fee recipient and gas limit",
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
Value: "",
}
)

// DefaultValidatorDir returns OS-specific default validator directory.
Expand Down
1 change: 1 addition & 0 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var appFlags = []cli.Flag{
flags.SuggestedFeeRecipientFlag,
flags.ProposerSettingsURLFlag,
flags.ProposerSettingsFlag,
flags.EnableValidatorRegistrationFlag,
////////////////////
cmd.DisableMonitoringFlag,
cmd.MonitoringHostFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/validator/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var appHelpFlagGroups = []flagGroup{
flags.ProposerSettingsFlag,
flags.ProposerSettingsURLFlag,
flags.SuggestedFeeRecipientFlag,
flags.EnableValidatorRegistrationFlag,
},
},
{
Expand Down
20 changes: 13 additions & 7 deletions config/validator/service/proposer-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ type ProposerSettingsPayload struct {

// ProposerOptionPayload is the struct representation of the JSON config file set in the validator through the CLI.
// FeeRecipient is set to an eth address in hex string format with 0x prefix.
// GasLimit is a number set to help the network decide on the maximum gas in each block.
type ProposerOptionPayload struct {
FeeRecipient string `json:"fee_recipient" yaml:"fee_recipient"`
GasLimit uint64 `json:"gas_limit,omitempty" yaml:"gas_limit,omitempty"`
FeeRecipient string `json:"fee_recipient" yaml:"fee_recipient"`
ValidatorRegistration *ValidatorRegistration `json:"validator_registration" yaml:"validator_registration"`
}

// ValidatorRegistration is the struct representation of the JSON config file set in the validator through the CLI.
// GasLimit is a number set to help the network decide on the maximum gas in each block.
type ValidatorRegistration struct {
Enable bool `json:"enable" yaml:"enable"`
GasLimit uint64 `json:"gas_limit,omitempty" yaml:"gas_limit,omitempty"`
}

// ProposerSettings is a Prysm internal representation of the fee recipient config on the validator client.
Expand All @@ -31,14 +37,14 @@ type ProposerSettings struct {

// ProposerOption is a Prysm internal representation of the ProposerOptionPayload on the validator client in bytes format instead of hex.
type ProposerOption struct {
FeeRecipient common.Address
GasLimit uint64
FeeRecipient common.Address
ValidatorRegistration *ValidatorRegistration
}

// DefaultProposerOption returns a Proposer Option with defaults filled
func DefaultProposerOption() ProposerOption {
return ProposerOption{
FeeRecipient: params.BeaconConfig().DefaultFeeRecipient,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
FeeRecipient: params.BeaconConfig().DefaultFeeRecipient,
ValidatorRegistration: nil,
}
}
31 changes: 22 additions & 9 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
var registerValidatorRequests []*ethpb.ValidatorRegistrationV1
// need to check for pubkey to validator index mappings
for i, key := range pubkeys {
var enableValidatorRegistration bool
skipAppendToFeeRecipientArray := false
feeRecipient := common.HexToAddress(params.BeaconConfig().EthBurnAddressHex)
gasLimit := params.BeaconConfig().DefaultBuilderGasLimit
Expand All @@ -1012,14 +1013,25 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
}
if v.ProposerSettings.DefaultConfig != nil {
feeRecipient = v.ProposerSettings.DefaultConfig.FeeRecipient
gasLimit = v.ProposerSettings.DefaultConfig.GasLimit
vr := v.ProposerSettings.DefaultConfig.ValidatorRegistration
if vr != nil && vr.Enable {
gasLimit = vr.GasLimit
enableValidatorRegistration = true
}

}
if v.ProposerSettings.ProposeConfig != nil {
option, ok := v.ProposerSettings.ProposeConfig[key]
if ok && option != nil {
// override the default if a proposeconfig is set
feeRecipient = option.FeeRecipient
gasLimit = option.GasLimit
vr := option.ValidatorRegistration
if vr != nil && vr.Enable {
gasLimit = vr.GasLimit
enableValidatorRegistration = true
} else {
enableValidatorRegistration = false
}
}
}
if hexutil.Encode(feeRecipient.Bytes()) == params.BeaconConfig().EthBurnAddressHex {
Expand All @@ -1031,13 +1043,14 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
FeeRecipient: feeRecipient[:],
})
}
registerValidatorRequests = append(registerValidatorRequests, &ethpb.ValidatorRegistrationV1{
FeeRecipient: feeRecipient[:],
GasLimit: gasLimit,
Timestamp: uint64(time.Now().UTC().Unix()),
Pubkey: pubkeys[i][:],
})

if enableValidatorRegistration {
registerValidatorRequests = append(registerValidatorRequests, &ethpb.ValidatorRegistrationV1{
FeeRecipient: feeRecipient[:],
GasLimit: gasLimit,
Timestamp: uint64(time.Now().UTC().Unix()),
Pubkey: pubkeys[i][:],
})
}
}
return validatorToFeeRecipients, registerValidatorRequests, nil
}
Expand Down
164 changes: 133 additions & 31 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
},
},
}
Expand Down Expand Up @@ -435,6 +439,10 @@ func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x6e35733c5af9B61374A128e6F85f553aF09ff89A"),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
},
},
}
Expand Down Expand Up @@ -1546,19 +1554,25 @@ func TestValidator_PushProposerSettings(t *testing.T) {
}).Return(nil, nil)
config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
GasLimit: uint64(40000000),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: uint64(35000000),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(35000000),
},
},
}
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Times(2).Return(&empty.Empty{}, nil)
).Return(&empty.Empty{}, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
Expand All @@ -1577,6 +1591,81 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
},
},
{
name: " Happy Path default doesn't send validator registration",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
node: nodeClient,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
useWeb: false,
interopKeysConfig: &local.InteropKeymanagerConfig{
NumValidatorKeys: 2,
Offset: 1,
},
}
err := v.WaitForKeymanagerInitialization(ctx)
require.NoError(t, err)
config := make(map[[fieldparams.BLSPubkeyLength]byte]*validatorserviceconfig.ProposerOption)
km, err := v.Keymanager()
require.NoError(t, err)
keys, err := km.FetchValidatingPublicKeys(ctx)
require.NoError(t, err)
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[0][:]},
).Return(&ethpb.ValidatorIndexResponse{
Index: 1,
}, nil)
client.EXPECT().ValidatorIndex(
ctx, // ctx
&ethpb.ValidatorIndexRequest{PublicKey: keys[1][:]},
).Return(&ethpb.ValidatorIndexResponse{
Index: 2,
}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(), ValidatorIndex: 1},
{FeeRecipient: common.HexToAddress(defaultFeeHex).Bytes(), ValidatorIndex: 2},
},
}).Return(nil, nil)
config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: false,
GasLimit: uint64(35000000),
},
},
}
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
).Return(&empty.Empty{}, nil)
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
},
mockExpectedRequests: []ExpectedValidatorRegistration{

{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9").Bytes(),
GasLimit: uint64(40000000),
},
},
},
{
name: " Happy Path",
validatorSetter: func(t *testing.T) *validator {
Expand Down Expand Up @@ -1605,7 +1694,10 @@ func TestValidator_PushProposerSettings(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
},
}
client.EXPECT().ValidatorIndex(
Expand Down Expand Up @@ -1636,25 +1728,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
},
},
{
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 @@ -1676,6 +1749,10 @@ func TestValidator_PushProposerSettings(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
},
}
km, err := v.Keymanager()
Expand All @@ -1688,7 +1765,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
).Return(&ethpb.ValidatorIndexResponse{
Index: 1,
}, nil)

client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
Expand All @@ -1710,6 +1786,25 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
},
},
{
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: " proposer config not nil but fee recipient empty",
validatorSetter: func(t *testing.T) *validator {
Expand Down Expand Up @@ -1814,7 +1909,6 @@ func TestValidator_PushProposerSettings(t *testing.T) {
{
name: "register validator batch failed",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
node: nodeClient,
Expand All @@ -1839,21 +1933,29 @@ func TestValidator_PushProposerSettings(t *testing.T) {
).Return(&ethpb.ValidatorIndexResponse{
Index: 1,
}, nil)
client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress("0x0").Bytes(), ValidatorIndex: 1},
},
}).Return(nil, nil)

config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.Address{},
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
GasLimit: uint64(40000000),
},
},
}

client.EXPECT().PrepareBeaconProposer(gomock.Any(), &ethpb.PrepareBeaconProposerRequest{
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
{FeeRecipient: common.HexToAddress("0x0").Bytes(), ValidatorIndex: 1},
},
}).Return(nil, nil)
client.EXPECT().SubmitValidatorRegistration(
gomock.Any(),
gomock.Any(),
Expand Down
Loading