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

Validator Registration- proposer settings renaming #11057

Merged
merged 13 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
8 changes: 4 additions & 4 deletions cmd/validator/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ var (
Value: params.BeaconConfig().EthBurnAddressHex,
}

// EnableValidatorRegistrationFlag enables the periodic validator registration API calls that will update the custom builder with validator settings.
EnableValidatorRegistrationFlag = &cli.BoolFlag{
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",
// EnableBuilderFlag enables the periodic validator registration API calls that will update the custom builder with validator settings.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is a breaking change so we'll need to give @Taranpreet26311 and wonderful develop team a heads up

EnableBuilderFlag = &cli.BoolFlag{
Name: "enable-builder",
Usage: "Enables MEV Builder validator registration APIs for the validator client to update settings such as fee recipient and gas limit. Note* this flag is not required if using proposer settings config file",
Value: false,
}
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var appFlags = []cli.Flag{
flags.SuggestedFeeRecipientFlag,
flags.ProposerSettingsURLFlag,
flags.ProposerSettingsFlag,
flags.EnableValidatorRegistrationFlag,
flags.EnableBuilderFlag,
////////////////////
cmd.DisableMonitoringFlag,
cmd.MonitoringHostFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/validator/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var appHelpFlagGroups = []flagGroup{
flags.ProposerSettingsFlag,
flags.ProposerSettingsURLFlag,
flags.SuggestedFeeRecipientFlag,
flags.EnableValidatorRegistrationFlag,
flags.EnableBuilderFlag,
},
},
{
Expand Down
21 changes: 11 additions & 10 deletions config/validator/service/proposer-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,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.
type ProposerOptionPayload struct {
FeeRecipient string `json:"fee_recipient" yaml:"fee_recipient"`
ValidatorRegistration *ValidatorRegistration `json:"validator_registration" yaml:"validator_registration"`
FeeRecipient string `json:"fee_recipient" yaml:"fee_recipient"`
BuilderConfig *BuilderConfig `json:"builder" yaml:"builder"`
}

// ValidatorRegistration is the struct representation of the JSON config file set in the validator through the CLI.
// BuilderConfig 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"`
type BuilderConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
GasLimit uint64 `json:"gas_limit,omitempty" yaml:"gas_limit,omitempty"`
Relays []string `json:"relays" yaml:"relays"`
}

// ProposerSettings is a Prysm internal representation of the fee recipient config on the validator client.
Expand All @@ -37,14 +38,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
ValidatorRegistration *ValidatorRegistration
FeeRecipient common.Address
BuilderConfig *BuilderConfig
}

// DefaultProposerOption returns a Proposer Option with defaults filled
func DefaultProposerOption() ProposerOption {
return ProposerOption{
FeeRecipient: params.BeaconConfig().DefaultFeeRecipient,
ValidatorRegistration: nil,
FeeRecipient: params.BeaconConfig().DefaultFeeRecipient,
BuilderConfig: nil,
}
}
40 changes: 23 additions & 17 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,22 +980,13 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
log.Warnf("No valid validator indices were found, prepare beacon proposer request fee recipients array is empty")
return nil
}
if len(feeRecipients) != len(pubkeys) {
log.WithFields(logrus.Fields{
"activePubkeys": len(pubkeys) - len(feeRecipients),
}).Warnln("will not prepare beacon proposer and update fee recipient until a validator index is assigned")
}
if _, err := v.validatorClient.PrepareBeaconProposer(ctx, &ethpb.PrepareBeaconProposerRequest{
Recipients: feeRecipients,
}); err != nil {
return err
}
log.Infoln("Prepared beacon proposer with fee recipient to validator index mapping")
if len(signedRegisterValidatorRequests) != len(pubkeys) {
log.WithFields(logrus.Fields{
"activePubkeys": len(pubkeys) - len(signedRegisterValidatorRequests),
}).Warnln("will not be included in validator registration until a validator index is assigned")
}

if err := SubmitValidatorRegistration(ctx, v.validatorClient, signedRegisterValidatorRequests); err != nil {
return err
}
Expand All @@ -1004,8 +995,9 @@ func (v *validator) PushProposerSettings(ctx context.Context, km keymanager.IKey
}

func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [][fieldparams.BLSPubkeyLength]byte, signer iface.SigningFunc) ([]*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer, []*ethpb.SignedValidatorRegistrationV1, error) {
var validatorToFeeRecipients []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer
var proposerFeeRecipientRequests []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer
var signedRegisterValidatorRequests []*ethpb.SignedValidatorRegistrationV1
anyValidatorRegistrationEnabled := false
// need to check for pubkey to validator index mappings
for i, key := range pubkeys {
var enableValidatorRegistration bool
Expand All @@ -1028,8 +1020,8 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
}
if v.ProposerSettings.DefaultConfig != nil {
feeRecipient = v.ProposerSettings.DefaultConfig.FeeRecipient
vr := v.ProposerSettings.DefaultConfig.ValidatorRegistration
if vr != nil && vr.Enable {
vr := v.ProposerSettings.DefaultConfig.BuilderConfig
if vr != nil && vr.Enabled {
gasLimit = vr.GasLimit
enableValidatorRegistration = true
}
Expand All @@ -1040,8 +1032,8 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
if ok && option != nil {
// override the default if a proposeconfig is set
feeRecipient = option.FeeRecipient
vr := option.ValidatorRegistration
if vr != nil && vr.Enable {
vr := option.BuilderConfig
if vr != nil && vr.Enabled {
gasLimit = vr.GasLimit
enableValidatorRegistration = true
} else {
Expand All @@ -1055,12 +1047,13 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [

// Only include requests with assigned validator index
if !skipAppendToFeeRecipientArray {
validatorToFeeRecipients = append(validatorToFeeRecipients, &ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
proposerFeeRecipientRequests = append(proposerFeeRecipientRequests, &ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
ValidatorIndex: validatorIndex,
FeeRecipient: feeRecipient[:],
})
}
if !skipAppendToFeeRecipientArray && enableValidatorRegistration {
anyValidatorRegistrationEnabled = true
unsignedRequest := &ethpb.ValidatorRegistrationV1{
FeeRecipient: feeRecipient[:],
GasLimit: gasLimit,
Expand All @@ -1075,7 +1068,20 @@ func (v *validator) buildProposerSettingsRequests(ctx context.Context, pubkeys [
signedRegisterValidatorRequests = append(signedRegisterValidatorRequests, request)
}
}
return validatorToFeeRecipients, signedRegisterValidatorRequests, nil

if len(proposerFeeRecipientRequests) != len(pubkeys) {
log.WithFields(logrus.Fields{
"totalNonActivePubkeys": len(pubkeys) - len(proposerFeeRecipientRequests),
}).Warnln("will not prepare beacon proposer and update fee recipient until a validator index is assigned")
}

if len(signedRegisterValidatorRequests) != len(pubkeys) && anyValidatorRegistrationEnabled {
log.WithFields(logrus.Fields{
"totalNonActivePubkeys": len(pubkeys) - len(signedRegisterValidatorRequests),
}).Warnln("will not be included in MEV builder validator registration until a validator index is assigned")
}

return proposerFeeRecipientRequests, signedRegisterValidatorRequests, nil
}

func (v *validator) cacheValidatorPubkeyHexToValidatorIndex(ctx context.Context, pubkey [fieldparams.BLSPubkeyLength]byte) (types.ValidatorIndex, bool, error) {
Expand Down
105 changes: 85 additions & 20 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
mockExpectedRequests []ExpectedValidatorRegistration
err string
logMessages []string
doesntContainLogs bool
}{
{
name: " Happy Path proposer config not nil",
Expand Down Expand Up @@ -1505,17 +1506,17 @@ func TestValidator_PushProposerSettings(t *testing.T) {
}).Return(nil, nil)
config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(35000000),
},
},
Expand Down Expand Up @@ -1585,17 +1586,17 @@ func TestValidator_PushProposerSettings(t *testing.T) {
}).Return(nil, nil)
config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: false,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: false,
GasLimit: uint64(35000000),
},
},
Expand All @@ -1617,6 +1618,66 @@ func TestValidator_PushProposerSettings(t *testing.T) {
GasLimit: uint64(40000000),
},
},
logMessages: []string{"will not be included in MEV builder validator registration"},
},
{
name: " Happy Path default doesn't send any validator registrations",
validatorSetter: func(t *testing.T) *validator {

v := validator{
validatorClient: client,
node: nodeClient,
db: db,
pubkeyToValidatorIndex: make(map[[fieldparams.BLSPubkeyLength]byte]types.ValidatorIndex),
signedValidatorRegistrations: make(map[[fieldparams.BLSPubkeyLength]byte]*ethpb.SignedValidatorRegistrationV1),
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"),
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
},
}
return &v
},
feeRecipientMap: map[types.ValidatorIndex]string{
1: "0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9",
2: defaultFeeHex,
},
logMessages: []string{"will not be included in MEV builder validator registration"},
doesntContainLogs: true,
},
{
name: " Happy Path",
Expand Down Expand Up @@ -1647,8 +1708,8 @@ func TestValidator_PushProposerSettings(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
},
Expand Down Expand Up @@ -1703,8 +1764,8 @@ func TestValidator_PushProposerSettings(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
},
},
Expand Down Expand Up @@ -1895,17 +1956,17 @@ func TestValidator_PushProposerSettings(t *testing.T) {

config[keys[0]] = &validatorserviceconfig.ProposerOption{
FeeRecipient: common.Address{},
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
},
}
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
ProposeConfig: config,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: uint64(40000000),
},
},
Expand Down Expand Up @@ -1952,8 +2013,8 @@ func TestValidator_PushProposerSettings(t *testing.T) {
ProposeConfig: nil,
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipient: common.HexToAddress(defaultFeeHex),
ValidatorRegistration: &validatorserviceconfig.ValidatorRegistration{
Enable: true,
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
},
},
Expand Down Expand Up @@ -1992,7 +2053,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
},
logMessages: []string{
"prepare beacon proposer and update fee recipient until a validator index is assigned",
"not be included in validator registration until a validator index is assigned",
"will not be included in MEV builder validator registration until a validator index is assigned",
},
},
}
Expand Down Expand Up @@ -2029,7 +2090,11 @@ func TestValidator_PushProposerSettings(t *testing.T) {
}
if len(tt.logMessages) > 0 {
for _, message := range tt.logMessages {
assert.LogsContain(t, hook, message)
if tt.doesntContainLogs {
assert.LogsDoNotContain(t, hook, message)
} else {
assert.LogsContain(t, hook, message)
}
}

}
Expand Down
Loading