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

refactoring how proposer settings load into validator client #13645

Merged
merged 54 commits into from
Mar 4, 2024

Conversation

james-prysm
Copy link
Contributor

@james-prysm james-prysm commented Feb 21, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

the proposer settings is a configuration that is saved on the validator client both in memory and in the DB to provide configuration information such as fee recipients or configuring a validator to use a mev builder. The current implementation is littered with inconsistent checks and hopefully this will improve readability.

fixes #13797

@james-prysm james-prysm added the Cleanup Code health! label Feb 21, 2024
@james-prysm james-prysm marked this pull request as ready for review February 21, 2024 20:51
@james-prysm james-prysm requested a review from a team as a code owner February 21, 2024 20:51
@james-prysm james-prysm requested review from kasey, nalepae, terencechain, prestonvanloon, saolyn and rkapka and removed request for terencechain February 21, 2024 20:51
"github.com/urfave/cli/v2"
)

type SettingsType int
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to export

Comment on lines 31 to 33
type ProposerSettingsLoader interface {
Load(cliCtx *cli.Context) (*validatorService.ProposerSettings, error)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Interface that has only one implementation is kind of useless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can take it out for now, was going to make changes with it when #13541 is addressed

Comment on lines 36 to 38
LoadMethods []SettingsType
ExistsInDB bool
Db iface.ValidatorDB
Copy link
Contributor

Choose a reason for hiding this comment

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

These can be lowercase (functionally-wise it's probably irrelevant since the type is not exported anyway)

Load(cliCtx *cli.Context) (*validatorService.ProposerSettings, error)
}

type proposerSettingsLoader struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type proposerSettingsLoader struct {
type settingsLoader struct {

Type name should not start with package name

}

// ProposerSettingsLoaderOption sets additional flag checks that affect the proposer settings
type ProposerSettingsLoaderOption func(cliCtx *cli.Context, psl *proposerSettingsLoader) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type ProposerSettingsLoaderOption func(cliCtx *cli.Context, psl *proposerSettingsLoader) error
type SettingsLoaderOption func(cliCtx *cli.Context, psl *proposerSettingsLoader) error

Type name should not start with package name

config/validator/service/proposer_settings.go Outdated Show resolved Hide resolved
config/validator/service/proposer_settings.go Outdated Show resolved Hide resolved
config/validator/service/proposer_settings.go Outdated Show resolved Hide resolved
return p
}

func (po *ProposerOption) ToConsensus() *validatorpb.ProposerOptionPayload {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing doc

validator/client/validator.go Outdated Show resolved Hide resolved
@rkapka
Copy link
Contributor

rkapka commented Feb 22, 2024

proposer_settings.go can be a part of the proposer package and most things from this file can be unexported

func (psl *SettingsLoader) processProposerSettings(loadedSettings, dbSettings *validatorpb.ProposerSettingsPayload) *validatorpb.ProposerSettingsPayload {
dbOnly := false
if loadedSettings == nil && dbSettings == nil {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This case is not covered by any test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think this is possible since it'd probably only happen on db only but it should exist in the db... can take it out if we want but also think it's fine to keep it in

config/proposer/testdata/empty.json Outdated Show resolved Hide resolved
config/proposer/testdata/proposer-config-only.json Outdated Show resolved Hide resolved
config/util.go Outdated Show resolved Hide resolved
config/util.go Outdated Show resolved Hide resolved
config/util.go Outdated Show resolved Hide resolved
config/util.go Show resolved Hide resolved
config/proposer/loader.go Outdated Show resolved Hide resolved
config/proposer/loader.go Outdated Show resolved Hide resolved
@@ -136,6 +147,35 @@ type ProposerOption struct {
BuilderConfig *BuilderConfig
}

// Clone creates a deep copy of proposer option
func (po *ProposerOption) Clone() *ProposerOption {
if po == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it even possible to enter into this function if po == nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably not i think... don't remember by we added those checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nvm it's used on fee recipient APIs reverted this...

}

func (po *ProposerOption) ToConsensus() *validatorpb.ProposerOptionPayload {
if po == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it even possible to enter into this function if po == nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

happens on key manager APIs

Copy link
Contributor

Choose a reason for hiding this comment

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

You'r right, I just learned in go it was possible to do:

f.bar()

even i f is nil.

Like:

image

==> Should we add receiver nilness check in each method?

@james-prysm
Copy link
Contributor Author

proposer_settings.go can be a part of the proposer package and most things from this file can be unexported

thing still need to be exported here for db and api use as well as tests

@james-prysm james-prysm added this pull request to the merge queue Mar 4, 2024
@james-prysm james-prysm removed this pull request from the merge queue due to a manual request Mar 4, 2024
@james-prysm james-prysm added this pull request to the merge queue Mar 4, 2024
Merged via the queue into develop with commit d6fb8c2 Mar 4, 2024
17 checks passed
@james-prysm james-prysm deleted the improve-proposer-setting-process branch March 4, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code health!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default gas_limit is not followed in mev-builder configuration
3 participants