mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Keymanager API: fix fee recipient API and add persistence (#11540)
* fixing bug with fee recipient api * fixing unit tests * clarifying logs
This commit is contained in:
@@ -10,6 +10,7 @@ go_library(
|
||||
"//validator:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//config/validator/service:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v3/config/validator/service"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/validator/accounts/iface"
|
||||
@@ -81,7 +82,8 @@ func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerC
|
||||
}
|
||||
|
||||
type MockValidator struct {
|
||||
Km keymanager.IKeymanager
|
||||
Km keymanager.IKeymanager
|
||||
proposerSettings *validatorserviceconfig.ProposerSettings
|
||||
}
|
||||
|
||||
func (_ MockValidator) LogSyncCommitteeMessagesSubmitted() {}
|
||||
@@ -197,3 +199,13 @@ func (_ MockValidator) SetPubKeyToValidatorIndexMap(_ context.Context, _ keymana
|
||||
func (_ MockValidator) SignValidatorRegistrationRequest(_ context.Context, _ iface2.SigningFunc, _ *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// ProposerSettings for mocking
|
||||
func (m *MockValidator) ProposerSettings() *validatorserviceconfig.ProposerSettings {
|
||||
return m.proposerSettings
|
||||
}
|
||||
|
||||
// SetProposerSettings for mocking
|
||||
func (m *MockValidator) SetProposerSettings(settings *validatorserviceconfig.ProposerSettings) {
|
||||
m.proposerSettings = settings
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ go_library(
|
||||
visibility = ["//validator:__subpackages__"],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/validator/service:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//crypto/bls:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v3/config/validator/service"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@@ -60,9 +61,10 @@ type Validator interface {
|
||||
ReceiveBlocks(ctx context.Context, connectionErrorChannel chan<- error)
|
||||
HandleKeyReload(ctx context.Context, newKeys [][fieldparams.BLSPubkeyLength]byte) (bool, error)
|
||||
CheckDoppelGanger(ctx context.Context) error
|
||||
HasProposerSettings() bool
|
||||
PushProposerSettings(ctx context.Context, km keymanager.IKeymanager) error
|
||||
SignValidatorRegistrationRequest(ctx context.Context, signer SigningFunc, newValidatorRegistration *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error)
|
||||
ProposerSettings() *validatorserviceconfig.ProposerSettings
|
||||
SetProposerSettings(*validatorserviceconfig.ProposerSettings)
|
||||
}
|
||||
|
||||
// SigningFunc interface defines a type for the a function that signs a message
|
||||
|
||||
@@ -56,9 +56,9 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
}
|
||||
sub := km.SubscribeAccountChanges(accountsChangedChan)
|
||||
// Set properties on the beacon node like the fee recipient for validators that are being used & active.
|
||||
if v.HasProposerSettings() {
|
||||
log.Infof("Provided proposer settings will periodically update settings such as fee recipient"+
|
||||
" in the beacon node and custom builder ( if --%s)", flags.EnableBuilderFlag.Name)
|
||||
if v.ProposerSettings() != nil {
|
||||
log.Infof("Validator client started with provided proposer settings that sets options such as fee recipient"+
|
||||
" and will periodically update the beacon node and custom builder ( if --%s)", flags.EnableBuilderFlag.Name)
|
||||
if err := v.PushProposerSettings(ctx, km); err != nil {
|
||||
if errors.Is(err, ErrBuilderValidatorRegistration) {
|
||||
log.WithError(err).Warn("Push proposer settings error")
|
||||
@@ -67,7 +67,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Info("Proposer settings such as fee recipient are not defined in the validator client" +
|
||||
log.Warnln("Validator client started without proposer settings such as fee recipient" +
|
||||
" and will continue to use settings provided in the beacon node.")
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
continue
|
||||
}
|
||||
|
||||
if slots.IsEpochStart(slot) && v.HasProposerSettings() {
|
||||
if slots.IsEpochStart(slot) && v.ProposerSettings() != nil {
|
||||
go func() {
|
||||
//deadline set for next epoch rounded up
|
||||
if err := v.PushProposerSettings(ctx, km); err != nil {
|
||||
|
||||
@@ -5,10 +5,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v3/async/event"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v3/config/validator/service"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -249,6 +251,11 @@ func TestKeyReload_RemoteKeymanager(t *testing.T) {
|
||||
|
||||
func TestUpdateProposerSettingsAt_EpochStart(t *testing.T) {
|
||||
v := &testutil.FakeValidator{Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}}
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455012BFEBf6177F1D2e9738D9"),
|
||||
},
|
||||
})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
hook := logTest.NewGlobal()
|
||||
slot := params.BeaconConfig().SlotsPerEpoch
|
||||
@@ -270,6 +277,11 @@ func TestUpdateProposerSettings_ContinuesAfterValidatorRegistrationFails(t *test
|
||||
ProposerSettingsErr: errors.Wrap(ErrBuilderValidatorRegistration, errSomeotherError.Error()),
|
||||
Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}},
|
||||
}
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455012BFEBf6177F1D2e9738D9"),
|
||||
},
|
||||
})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
hook := logTest.NewGlobal()
|
||||
slot := params.BeaconConfig().SlotsPerEpoch
|
||||
|
||||
@@ -69,7 +69,7 @@ type ValidatorService struct {
|
||||
grpcHeaders []string
|
||||
graffiti []byte
|
||||
Web3SignerConfig *remoteweb3signer.SetupConfig
|
||||
ProposerSettings *validatorserviceconfig.ProposerSettings
|
||||
proposerSettings *validatorserviceconfig.ProposerSettings
|
||||
}
|
||||
|
||||
// Config for the validator service.
|
||||
@@ -120,7 +120,7 @@ func NewValidatorService(ctx context.Context, cfg *Config) (*ValidatorService, e
|
||||
interopKeysConfig: cfg.InteropKeysConfig,
|
||||
graffitiStruct: cfg.GraffitiStruct,
|
||||
Web3SignerConfig: cfg.Web3SignerConfig,
|
||||
ProposerSettings: cfg.ProposerSettings,
|
||||
proposerSettings: cfg.ProposerSettings,
|
||||
}
|
||||
|
||||
dialOpts := ConstructDialOptions(
|
||||
@@ -204,7 +204,7 @@ func (v *ValidatorService) Start() {
|
||||
graffitiOrderedIndex: graffitiOrderedIndex,
|
||||
eipImportBlacklistedPublicKeys: slashablePublicKeys,
|
||||
Web3SignerConfig: v.Web3SignerConfig,
|
||||
ProposerSettings: v.ProposerSettings,
|
||||
proposerSettings: v.proposerSettings,
|
||||
walletInitializedChannel: make(chan *wallet.Wallet, 1),
|
||||
}
|
||||
// To resolve a race condition at startup due to the interface
|
||||
@@ -248,6 +248,15 @@ func (v *ValidatorService) Keymanager() (keymanager.IKeymanager, error) {
|
||||
return v.validator.Keymanager()
|
||||
}
|
||||
|
||||
func (v *ValidatorService) ProposerSettings() *validatorserviceconfig.ProposerSettings {
|
||||
return v.validator.ProposerSettings()
|
||||
}
|
||||
|
||||
func (v *ValidatorService) SetProposerSettings(settings *validatorserviceconfig.ProposerSettings) {
|
||||
v.proposerSettings = settings
|
||||
v.validator.SetProposerSettings(settings)
|
||||
}
|
||||
|
||||
// ConstructDialOptions constructs a list of grpc dial options
|
||||
func ConstructDialOptions(
|
||||
maxCallRecvMsgSize int,
|
||||
|
||||
@@ -11,6 +11,7 @@ go_library(
|
||||
visibility = ["//validator:__subpackages__"],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/validator/service:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v3/config/validator/service"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/v3/time"
|
||||
@@ -51,6 +52,7 @@ type FakeValidator struct {
|
||||
IndexToPubkeyMap map[uint64][fieldparams.BLSPubkeyLength]byte
|
||||
PubkeyToIndexMap map[[fieldparams.BLSPubkeyLength]byte]uint64
|
||||
PubkeysToStatusesMap map[[fieldparams.BLSPubkeyLength]byte]ethpb.ValidatorStatus
|
||||
proposerSettings *validatorserviceconfig.ProposerSettings
|
||||
Km keymanager.IKeymanager
|
||||
}
|
||||
|
||||
@@ -270,3 +272,13 @@ func (_ *FakeValidator) SetPubKeyToValidatorIndexMap(_ context.Context, _ keyman
|
||||
func (_ *FakeValidator) SignValidatorRegistrationRequest(_ context.Context, _ iface.SigningFunc, _ *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ProposerSettings for mocking
|
||||
func (f *FakeValidator) ProposerSettings() *validatorserviceconfig.ProposerSettings {
|
||||
return f.proposerSettings
|
||||
}
|
||||
|
||||
// SetProposerSettings for mocking
|
||||
func (f *FakeValidator) SetProposerSettings(settings *validatorserviceconfig.ProposerSettings) {
|
||||
f.proposerSettings = settings
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ type validator struct {
|
||||
voteStats voteStats
|
||||
syncCommitteeStats syncCommitteeStats
|
||||
Web3SignerConfig *remoteweb3signer.SetupConfig
|
||||
ProposerSettings *validatorserviceconfig.ProposerSettings
|
||||
proposerSettings *validatorserviceconfig.ProposerSettings
|
||||
walletInitializedChannel chan *wallet.Wallet
|
||||
}
|
||||
|
||||
@@ -964,8 +964,12 @@ func (v *validator) logDuties(slot types.Slot, duties []*ethpb.DutiesResponse_Du
|
||||
}
|
||||
}
|
||||
|
||||
func (v *validator) HasProposerSettings() bool {
|
||||
return v.ProposerSettings != nil
|
||||
func (v *validator) ProposerSettings() *validatorserviceconfig.ProposerSettings {
|
||||
return v.proposerSettings
|
||||
}
|
||||
|
||||
func (v *validator) SetProposerSettings(settings *validatorserviceconfig.ProposerSettings) {
|
||||
v.proposerSettings = settings
|
||||
}
|
||||
|
||||
// PushProposerSettings calls the prepareBeaconProposer RPC to set the fee recipient and also the register validator API if using a custom builder.
|
||||
@@ -1035,11 +1039,11 @@ func (v *validator) buildPrepProposerReqs(ctx context.Context, pubkeys [][fieldp
|
||||
v.pubkeyToValidatorIndex[k] = i
|
||||
}
|
||||
feeRecipient := common.HexToAddress(params.BeaconConfig().EthBurnAddressHex)
|
||||
if v.ProposerSettings.DefaultConfig != nil {
|
||||
feeRecipient = v.ProposerSettings.DefaultConfig.FeeRecipient // Use cli config for fee recipient.
|
||||
if v.ProposerSettings().DefaultConfig != nil {
|
||||
feeRecipient = v.ProposerSettings().DefaultConfig.FeeRecipient // Use cli config for fee recipient.
|
||||
}
|
||||
if v.ProposerSettings.ProposeConfig != nil {
|
||||
config, ok := v.ProposerSettings.ProposeConfig[k]
|
||||
if v.ProposerSettings().ProposeConfig != nil {
|
||||
config, ok := v.ProposerSettings().ProposeConfig[k]
|
||||
if ok && config != nil {
|
||||
feeRecipient = config.FeeRecipient // Use file config for fee recipient.
|
||||
}
|
||||
@@ -1065,16 +1069,16 @@ func (v *validator) buildSignedRegReqs(ctx context.Context, pubkeys [][fieldpara
|
||||
feeRecipient := common.HexToAddress(params.BeaconConfig().EthBurnAddressHex)
|
||||
gasLimit := params.BeaconConfig().DefaultBuilderGasLimit
|
||||
enabled := false
|
||||
if v.ProposerSettings.DefaultConfig != nil {
|
||||
feeRecipient = v.ProposerSettings.DefaultConfig.FeeRecipient // Use cli config for fee recipient.
|
||||
config := v.ProposerSettings.DefaultConfig.BuilderConfig
|
||||
if v.ProposerSettings().DefaultConfig != nil {
|
||||
feeRecipient = v.ProposerSettings().DefaultConfig.FeeRecipient // Use cli config for fee recipient.
|
||||
config := v.ProposerSettings().DefaultConfig.BuilderConfig
|
||||
if config != nil && config.Enabled {
|
||||
gasLimit = uint64(config.GasLimit) // Use cli config for gas limit.
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
if v.ProposerSettings.ProposeConfig != nil {
|
||||
config, ok := v.ProposerSettings.ProposeConfig[k]
|
||||
if v.ProposerSettings().ProposeConfig != nil {
|
||||
config, ok := v.ProposerSettings().ProposeConfig[k]
|
||||
if ok && config != nil {
|
||||
feeRecipient = config.FeeRecipient // Use file config for fee recipient.
|
||||
builderConfig := config.BuilderConfig
|
||||
|
||||
@@ -1517,7 +1517,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 40000000,
|
||||
},
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
@@ -1526,7 +1526,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 35000000,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
client.EXPECT().SubmitValidatorRegistrations(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@@ -1597,7 +1597,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 40000000,
|
||||
},
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
@@ -1606,7 +1606,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 35000000,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
client.EXPECT().SubmitValidatorRegistrations(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
@@ -1669,12 +1669,12 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
config[keys[0]] = &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress("0x055Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
},
|
||||
}
|
||||
})
|
||||
return &v
|
||||
},
|
||||
feeRecipientMap: map[types.ValidatorIndex]string{
|
||||
@@ -1709,7 +1709,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(ctx)
|
||||
require.NoError(t, err)
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: nil,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
@@ -1718,7 +1718,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: validatorserviceconfig.Uint64(params.BeaconConfig().DefaultBuilderGasLimit),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
client.EXPECT().ValidatorIndex(
|
||||
ctx, // ctx
|
||||
ðpb.ValidatorIndexRequest{PublicKey: keys[0][:]},
|
||||
@@ -1765,7 +1765,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
}
|
||||
err := v.WaitForKeymanagerInitialization(ctx)
|
||||
require.NoError(t, err)
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: nil,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
@@ -1774,7 +1774,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 40000000,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
km, err := v.Keymanager()
|
||||
require.NoError(t, err)
|
||||
keys, err := km.FetchValidatingPublicKeys(ctx)
|
||||
@@ -1843,12 +1843,12 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
config[keys[0]] = &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.Address{},
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
},
|
||||
}
|
||||
})
|
||||
return &v
|
||||
},
|
||||
},
|
||||
@@ -1881,12 +1881,12 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
config[keys[0]] = &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"),
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
},
|
||||
}
|
||||
})
|
||||
return &v
|
||||
},
|
||||
},
|
||||
@@ -1926,7 +1926,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 40000000,
|
||||
},
|
||||
}
|
||||
v.ProposerSettings = &validatorserviceconfig.ProposerSettings{
|
||||
v.SetProposerSettings(&validatorserviceconfig.ProposerSettings{
|
||||
ProposeConfig: config,
|
||||
DefaultConfig: &validatorserviceconfig.ProposerOption{
|
||||
FeeRecipient: common.HexToAddress(defaultFeeHex),
|
||||
@@ -1935,7 +1935,7 @@ func TestValidator_PushProposerSettings(t *testing.T) {
|
||||
GasLimit: 40000000,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
client.EXPECT().PrepareBeaconProposer(gomock.Any(), ðpb.PrepareBeaconProposerRequest{
|
||||
Recipients: []*ethpb.PrepareBeaconProposerRequest_FeeRecipientContainer{
|
||||
{FeeRecipient: common.HexToAddress("0x0").Bytes(), ValidatorIndex: 1},
|
||||
|
||||
@@ -405,15 +405,15 @@ func (s *Server) GetGasLimit(_ context.Context, req *ethpbservice.PubkeyRequest)
|
||||
Pubkey: validatorKey,
|
||||
},
|
||||
}
|
||||
if s.validatorService.ProposerSettings != nil {
|
||||
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if s.validatorService.ProposerSettings() != nil {
|
||||
proposerOption, found := s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found {
|
||||
if proposerOption.BuilderConfig != nil {
|
||||
resp.Data.GasLimit = uint64(proposerOption.BuilderConfig.GasLimit)
|
||||
return resp, nil
|
||||
}
|
||||
} else if s.validatorService.ProposerSettings.DefaultConfig != nil && s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig != nil {
|
||||
resp.Data.GasLimit = uint64(s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig.GasLimit)
|
||||
} else if s.validatorService.ProposerSettings().DefaultConfig != nil && s.validatorService.ProposerSettings().DefaultConfig.BuilderConfig != nil {
|
||||
resp.Data.GasLimit = uint64(s.validatorService.ProposerSettings().DefaultConfig.BuilderConfig.GasLimit)
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
@@ -433,12 +433,12 @@ func (s *Server) SetGasLimit(ctx context.Context, req *ethpbservice.SetGasLimitR
|
||||
|
||||
defaultOption := validatorServiceConfig.DefaultProposerOption()
|
||||
var pBuilderConfig *validatorServiceConfig.BuilderConfig
|
||||
if s.validatorService.ProposerSettings != nil &&
|
||||
s.validatorService.ProposerSettings.DefaultConfig != nil &&
|
||||
s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig != nil {
|
||||
if s.validatorService.ProposerSettings() != nil &&
|
||||
s.validatorService.ProposerSettings().DefaultConfig != nil &&
|
||||
s.validatorService.ProposerSettings().DefaultConfig.BuilderConfig != nil {
|
||||
// Make a copy of BuildConfig from DefaultConfig (thus "*" then "&"), so when we change GasLimit, we do not mess up with
|
||||
// "DefaultConfig.BuilderConfig".
|
||||
bo := *s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig
|
||||
bo := *s.validatorService.ProposerSettings().DefaultConfig.BuilderConfig
|
||||
pBuilderConfig = &bo
|
||||
pBuilderConfig.GasLimit = validatorServiceConfig.Uint64(req.GasLimit)
|
||||
} else {
|
||||
@@ -450,33 +450,35 @@ func (s *Server) SetGasLimit(ctx context.Context, req *ethpbservice.SetGasLimitR
|
||||
// "pOption.BuildConfig" is nil from "validatorServiceConfig.DefaultProposerOption()", so set it.
|
||||
pOption.BuilderConfig = pBuilderConfig
|
||||
|
||||
if s.validatorService.ProposerSettings == nil {
|
||||
if s.validatorService.ProposerSettings() == nil {
|
||||
// get the default fee recipient defined with an invalid public key from beacon node
|
||||
resp, err := s.beaconNodeValidatorClient.GetFeeRecipientByPubKey(ctx, ð.FeeRecipientByPubKeyRequest{
|
||||
PublicKey: []byte(nonExistantPublicKey),
|
||||
})
|
||||
if resp == nil || len(resp.FeeRecipient) == 0 || err != nil {
|
||||
s.validatorService.ProposerSettings = &validatorServiceConfig.ProposerSettings{
|
||||
s.validatorService.SetProposerSettings(&validatorServiceConfig.ProposerSettings{
|
||||
ProposeConfig: map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption{
|
||||
bytesutil.ToBytes48(validatorKey): &pOption,
|
||||
},
|
||||
DefaultConfig: &defaultOption,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
s.validatorService.ProposerSettings = &validatorServiceConfig.ProposerSettings{
|
||||
s.validatorService.SetProposerSettings(&validatorServiceConfig.ProposerSettings{
|
||||
ProposeConfig: map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption{
|
||||
bytesutil.ToBytes48(validatorKey): &pOption,
|
||||
},
|
||||
DefaultConfig: &validatorServiceConfig.ProposerOption{
|
||||
FeeRecipient: common.BytesToAddress(resp.FeeRecipient),
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
} else if s.validatorService.ProposerSettings.ProposeConfig == nil {
|
||||
s.validatorService.ProposerSettings.ProposeConfig = make(map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption)
|
||||
s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
} else if s.validatorService.ProposerSettings().ProposeConfig == nil {
|
||||
settings := s.validatorService.ProposerSettings()
|
||||
settings.ProposeConfig = make(map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption)
|
||||
settings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
s.validatorService.SetProposerSettings(settings)
|
||||
} else {
|
||||
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
proposerOption, found := s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found {
|
||||
if proposerOption.BuilderConfig == nil {
|
||||
proposerOption.BuilderConfig = pBuilderConfig
|
||||
@@ -484,7 +486,7 @@ func (s *Server) SetGasLimit(ctx context.Context, req *ethpbservice.SetGasLimitR
|
||||
proposerOption.BuilderConfig.GasLimit = validatorServiceConfig.Uint64(req.GasLimit)
|
||||
}
|
||||
} else {
|
||||
s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
}
|
||||
}
|
||||
// override the 200 success with 202 according to the specs
|
||||
@@ -503,7 +505,7 @@ func (s *Server) DeleteGasLimit(ctx context.Context, req *ethpbservice.DeleteGas
|
||||
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
||||
}
|
||||
|
||||
proposerSettings := s.validatorService.ProposerSettings
|
||||
proposerSettings := s.validatorService.ProposerSettings()
|
||||
if proposerSettings != nil && proposerSettings.ProposeConfig != nil {
|
||||
proposerOption, found := proposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found && proposerOption.BuilderConfig != nil {
|
||||
@@ -543,7 +545,7 @@ func (s *Server) ListFeeRecipientByPubkey(ctx context.Context, req *ethpbservice
|
||||
Ethaddress: defaultFeeRecipient,
|
||||
},
|
||||
}
|
||||
if s.validatorService.ProposerSettings == nil {
|
||||
if s.validatorService.ProposerSettings() == nil {
|
||||
resp, err := s.beaconNodeValidatorClient.GetFeeRecipientByPubKey(ctx, ð.FeeRecipientByPubKeyRequest{
|
||||
PublicKey: validatorKey,
|
||||
})
|
||||
@@ -552,17 +554,17 @@ func (s *Server) ListFeeRecipientByPubkey(ctx context.Context, req *ethpbservice
|
||||
}
|
||||
return finalResp, nil
|
||||
}
|
||||
if s.validatorService.ProposerSettings.ProposeConfig != nil {
|
||||
if s.validatorService.ProposerSettings().ProposeConfig != nil {
|
||||
hexv := hexutil.Encode(validatorKey)
|
||||
fmt.Println(hexv)
|
||||
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
proposerOption, found := s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found {
|
||||
finalResp.Data.Ethaddress = proposerOption.FeeRecipient.Bytes()
|
||||
return finalResp, nil
|
||||
}
|
||||
}
|
||||
if s.validatorService.ProposerSettings.DefaultConfig != nil {
|
||||
finalResp.Data.Ethaddress = s.validatorService.ProposerSettings.DefaultConfig.FeeRecipient.Bytes()
|
||||
if s.validatorService.ProposerSettings().DefaultConfig != nil {
|
||||
finalResp.Data.Ethaddress = s.validatorService.ProposerSettings().DefaultConfig.FeeRecipient.Bytes()
|
||||
}
|
||||
return finalResp, nil
|
||||
}
|
||||
@@ -584,8 +586,9 @@ func (s *Server) SetFeeRecipientByPubkey(ctx context.Context, req *ethpbservice.
|
||||
}
|
||||
pOption := validatorServiceConfig.DefaultProposerOption()
|
||||
pOption.FeeRecipient = common.BytesToAddress(req.Ethaddress)
|
||||
|
||||
switch {
|
||||
case s.validatorService.ProposerSettings == nil:
|
||||
case s.validatorService.ProposerSettings() == nil:
|
||||
// get the default fee recipient defined with an invalid public key from beacon node
|
||||
resp, err := s.beaconNodeValidatorClient.GetFeeRecipientByPubKey(ctx, ð.FeeRecipientByPubKeyRequest{
|
||||
PublicKey: []byte(nonExistantPublicKey),
|
||||
@@ -602,19 +605,23 @@ func (s *Server) SetFeeRecipientByPubkey(ctx context.Context, req *ethpbservice.
|
||||
FeeRecipient: common.BytesToAddress(resp.FeeRecipient),
|
||||
}
|
||||
}
|
||||
s.validatorService.ProposerSettings = settings
|
||||
case s.validatorService.ProposerSettings.ProposeConfig == nil:
|
||||
pOption.BuilderConfig = s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig
|
||||
s.validatorService.ProposerSettings.ProposeConfig = map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption{
|
||||
s.validatorService.SetProposerSettings(settings)
|
||||
case s.validatorService.ProposerSettings().ProposeConfig == nil:
|
||||
settings := s.validatorService.ProposerSettings()
|
||||
pOption.BuilderConfig = settings.DefaultConfig.BuilderConfig
|
||||
settings.ProposeConfig = map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption{
|
||||
bytesutil.ToBytes48(validatorKey): &pOption,
|
||||
}
|
||||
s.validatorService.SetProposerSettings(settings)
|
||||
default:
|
||||
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
proposerOption, found := s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found {
|
||||
proposerOption.FeeRecipient = common.BytesToAddress(req.Ethaddress)
|
||||
} else {
|
||||
pOption.BuilderConfig = s.validatorService.ProposerSettings.DefaultConfig.BuilderConfig
|
||||
s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
settings := s.validatorService.ProposerSettings()
|
||||
pOption.BuilderConfig = settings.DefaultConfig.BuilderConfig
|
||||
settings.ProposeConfig[bytesutil.ToBytes48(validatorKey)] = &pOption
|
||||
s.validatorService.SetProposerSettings(settings)
|
||||
}
|
||||
}
|
||||
// override the 200 success with 202 according to the specs
|
||||
@@ -634,11 +641,11 @@ func (s *Server) DeleteFeeRecipientByPubkey(ctx context.Context, req *ethpbservi
|
||||
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
||||
}
|
||||
defaultFeeRecipient := params.BeaconConfig().DefaultFeeRecipient
|
||||
if s.validatorService.ProposerSettings != nil && s.validatorService.ProposerSettings.DefaultConfig != nil {
|
||||
defaultFeeRecipient = s.validatorService.ProposerSettings.DefaultConfig.FeeRecipient
|
||||
if s.validatorService.ProposerSettings() != nil && s.validatorService.ProposerSettings().DefaultConfig != nil {
|
||||
defaultFeeRecipient = s.validatorService.ProposerSettings().DefaultConfig.FeeRecipient
|
||||
}
|
||||
if s.validatorService.ProposerSettings != nil && s.validatorService.ProposerSettings.ProposeConfig != nil {
|
||||
proposerOption, found := s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if s.validatorService.ProposerSettings() != nil && s.validatorService.ProposerSettings().ProposeConfig != nil {
|
||||
proposerOption, found := s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(validatorKey)]
|
||||
if found {
|
||||
proposerOption.FeeRecipient = defaultFeeRecipient
|
||||
}
|
||||
|
||||
@@ -771,9 +771,10 @@ func TestServer_ListFeeRecipientByPubkey(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl)
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.args)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.args,
|
||||
Validator: m,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
if tt.args == nil || tt.args.ProposeConfig == nil {
|
||||
@@ -878,9 +879,10 @@ func TestServer_SetFeeRecipientByPubkey(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.proposerSettings)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.proposerSettings,
|
||||
Validator: m,
|
||||
})
|
||||
if tt.beaconReturn != nil {
|
||||
beaconClient.EXPECT().GetFeeRecipientByPubKey(
|
||||
@@ -895,8 +897,8 @@ func TestServer_SetFeeRecipientByPubkey(t *testing.T) {
|
||||
}
|
||||
_, err = s.SetFeeRecipientByPubkey(ctx, ðpbservice.SetFeeRecipientByPubkeyRequest{Pubkey: byteval, Ethaddress: common.HexToAddress(tt.args).Bytes()})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want.valEthAddress, s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(byteval)].FeeRecipient.Hex())
|
||||
assert.Equal(t, tt.want.defaultEthaddress, s.validatorService.ProposerSettings.DefaultConfig.FeeRecipient.Hex())
|
||||
assert.Equal(t, tt.want.valEthAddress, s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(byteval)].FeeRecipient.Hex())
|
||||
assert.Equal(t, tt.want.defaultEthaddress, s.validatorService.ProposerSettings().DefaultConfig.FeeRecipient.Hex())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -934,9 +936,10 @@ func TestServer_DeleteFeeRecipientByPubkey(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.proposerSettings)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.proposerSettings,
|
||||
Validator: m,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
s := &Server{
|
||||
@@ -944,7 +947,7 @@ func TestServer_DeleteFeeRecipientByPubkey(t *testing.T) {
|
||||
}
|
||||
_, err = s.DeleteFeeRecipientByPubkey(ctx, ðpbservice.PubkeyRequest{Pubkey: byteval})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want.EthAddress, s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(byteval)].FeeRecipient.Hex())
|
||||
assert.Equal(t, tt.want.EthAddress, s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(byteval)].FeeRecipient.Hex())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1002,9 +1005,10 @@ func TestServer_GetGasLimit(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.args)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.args,
|
||||
Validator: m,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
s := &Server{
|
||||
@@ -1143,9 +1147,10 @@ func TestServer_SetGasLimit(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
feeRecipient := params.BeaconConfig().DefaultFeeRecipient.Hex()
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.proposerSettings)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.proposerSettings,
|
||||
Validator: m,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
s := &Server{
|
||||
@@ -1164,9 +1169,9 @@ func TestServer_SetGasLimit(t *testing.T) {
|
||||
_, err = s.SetGasLimit(ctx, ðpbservice.SetGasLimitRequest{Pubkey: tt.pubkey, GasLimit: tt.newGasLimit})
|
||||
require.NoError(t, err)
|
||||
for _, w := range tt.w {
|
||||
assert.Equal(t, w.gaslimit, uint64(s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit))
|
||||
assert.Equal(t, w.gaslimit, uint64(s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit))
|
||||
}
|
||||
assert.Equal(t, s.validatorService.ProposerSettings.DefaultConfig.FeeRecipient.Hex(), feeRecipient)
|
||||
assert.Equal(t, s.validatorService.ProposerSettings().DefaultConfig.FeeRecipient.Hex(), feeRecipient)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1282,9 +1287,10 @@ func TestServer_DeleteGasLimit(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := &mock.MockValidator{}
|
||||
m.SetProposerSettings(tt.proposerSettings)
|
||||
vs, err := client.NewValidatorService(ctx, &client.Config{
|
||||
Validator: &mock.MockValidator{},
|
||||
ProposerSettings: tt.proposerSettings,
|
||||
Validator: m,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
s := &Server{
|
||||
@@ -1299,7 +1305,7 @@ func TestServer_DeleteGasLimit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
for _, w := range tt.w {
|
||||
assert.Equal(t, w.gaslimit, s.validatorService.ProposerSettings.ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit)
|
||||
assert.Equal(t, w.gaslimit, s.validatorService.ProposerSettings().ProposeConfig[bytesutil.ToBytes48(w.pubkey)].BuilderConfig.GasLimit)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user