Skip to content

Commit

Permalink
Add builder config toml support (ethereum#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored and avalonche committed Feb 6, 2023
1 parent 27ea449 commit c0e0053
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
36 changes: 36 additions & 0 deletions builder/config.go
@@ -0,0 +1,36 @@
package builder

type Config struct {
Enabled bool `toml:",omitempty"`
EnableValidatorChecks bool `toml:",omitempty"`
EnableLocalRelay bool `toml:",omitempty"`
DisableBundleFetcher bool `toml:",omitempty"`
DryRun bool `toml:",omitempty"`
BuilderSecretKey string `toml:",omitempty"`
RelaySecretKey string `toml:",omitempty"`
ListenAddr string `toml:",omitempty"`
GenesisForkVersion string `toml:",omitempty"`
BellatrixForkVersion string `toml:",omitempty"`
GenesisValidatorsRoot string `toml:",omitempty"`
BeaconEndpoint string `toml:",omitempty"`
RemoteRelayEndpoint string `toml:",omitempty"`
ValidationBlocklist string `toml:",omitempty"`
}

// DefaultConfig is the default config for the builder.
var DefaultConfig = Config{
Enabled: false,
EnableValidatorChecks: false,
EnableLocalRelay: false,
DisableBundleFetcher: false,
DryRun: false,
BuilderSecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
RelaySecretKey: "0x2fc12ae741f29701f8e30f5de6350766c020cb80768a0ff01e6838ffd2431e11",
ListenAddr: ":28545",
GenesisForkVersion: "0x00000000",
BellatrixForkVersion: "0x02000000",
GenesisValidatorsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
BeaconEndpoint: "http://127.0.0.1:5052",
RemoteRelayEndpoint: "",
ValidationBlocklist: "",
}
19 changes: 1 addition & 18 deletions builder/service.go
Expand Up @@ -104,24 +104,7 @@ func NewService(listenAddr string, localRelay *LocalRelay, builder *Builder) *Se
}
}

type BuilderConfig struct {
Enabled bool
EnableValidatorChecks bool
EnableLocalRelay bool
DisableBundleFetcher bool
DryRun bool
BuilderSecretKey string
RelaySecretKey string
ListenAddr string
GenesisForkVersion string
BellatrixForkVersion string
GenesisValidatorsRoot string
BeaconEndpoint string
RemoteRelayEndpoint string
ValidationBlocklist string
}

func Register(stack *node.Node, backend *eth.Ethereum, cfg *BuilderConfig) error {
func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error {
envRelaySkBytes, err := hexutil.Decode(cfg.RelaySecretKey)
if err != nil {
return errors.New("incorrect builder API secret key provided")
Expand Down
5 changes: 5 additions & 0 deletions cmd/geth/config.go
Expand Up @@ -92,6 +92,7 @@ type gethConfig struct {
Node node.Config
Ethstats ethstatsConfig
Metrics metrics.Config
Builder builder.Config
}

func loadConfig(file string, cfg *gethConfig) error {
Expand Down Expand Up @@ -127,6 +128,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig,
Builder: builder.DefaultConfig,
}

// Load config file.
Expand All @@ -153,6 +155,9 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
}
applyMetricConfig(ctx, &cfg)

// Apply builder flags
utils.SetBuilderConfig(ctx, &cfg.Builder)

return stack, cfg
}

Expand Down
20 changes: 19 additions & 1 deletion cmd/utils/flags.go
Expand Up @@ -1551,6 +1551,24 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
}
}

// SetBuilderConfig applies node-related command line flags to the config.
func SetBuilderConfig(ctx *cli.Context, cfg *builder.Config) {
cfg.Enabled = ctx.IsSet(BuilderEnabled.Name)
cfg.EnableValidatorChecks = ctx.IsSet(BuilderEnableValidatorChecks.Name)
cfg.EnableLocalRelay = ctx.IsSet(BuilderEnableLocalRelay.Name)
cfg.DisableBundleFetcher = ctx.IsSet(BuilderDisableBundleFetcher.Name)
cfg.DryRun = ctx.IsSet(BuilderDryRun.Name)
cfg.BuilderSecretKey = ctx.String(BuilderSecretKey.Name)
cfg.RelaySecretKey = ctx.String(BuilderRelaySecretKey.Name)
cfg.ListenAddr = ctx.String(BuilderListenAddr.Name)
cfg.GenesisForkVersion = ctx.String(BuilderGenesisForkVersion.Name)
cfg.BellatrixForkVersion = ctx.String(BuilderBellatrixForkVersion.Name)
cfg.GenesisValidatorsRoot = ctx.String(BuilderGenesisValidatorsRoot.Name)
cfg.BeaconEndpoint = ctx.String(BuilderBeaconEndpoint.Name)
cfg.RemoteRelayEndpoint = ctx.String(BuilderRemoteRelayEndpoint.Name)
cfg.ValidationBlocklist = ctx.String(BuilderBlockValidationBlacklistSourceFilePath.Name)
}

// SetNodeConfig applies node-related command line flags to the config.
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
SetP2PConfig(ctx, &cfg.P2P)
Expand Down Expand Up @@ -2117,7 +2135,7 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
// RegisterEthService adds an Ethereum client to the stack.
// The second return value is the full node instance, which may be nil if the
// node is running as a light client.
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config, bpCfg *builder.BuilderConfig) (ethapi.Backend, *eth.Ethereum) {
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config, bpCfg *builder.Config) (ethapi.Backend, *eth.Ethereum) {
if cfg.SyncMode == downloader.LightSync {
backend, err := les.New(stack, cfg)
if err != nil {
Expand Down

0 comments on commit c0e0053

Please sign in to comment.