diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 98711be464..38f7909259 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -981,7 +981,12 @@ func ExExPluginFlags() []cli.Flag { for _, name := range exex.Plugins() { flagset = append(flagset, &cli.BoolFlag{ Name: fmt.Sprintf("exex.%s", name), - Usage: fmt.Sprintf("Enables the %s execution extension plugin", name), + Usage: fmt.Sprintf("Enables the '%s' execution extension plugin", name), + Category: flags.ExExCategory, + }) + flagset = append(flagset, &cli.StringFlag{ + Name: fmt.Sprintf("exex.%s.config", name), + Usage: fmt.Sprintf("Opaque config to pass to the '%s' execution extension plugin", name), Category: flags.ExExCategory, }) } @@ -1925,12 +1930,16 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } // Execution extension plugins for _, flag := range ExExPluginFlags() { - if ctx.IsSet(flag.(*cli.BoolFlag).Name) { - plugin := strings.TrimLeft(flag.(*cli.BoolFlag).Name, "exex.") // TODO(karalabe): Custom flag - if err := exex.Instantiate(plugin); err != nil { - Fatalf("Failed to instantiate ExEx plugin %s: %v", plugin, err) + if flag, ok := flag.(*cli.BoolFlag); ok { + if ctx.IsSet(flag.Name) { + plugin := strings.TrimLeft(flag.Name, "exex.") // TODO(karalabe): Custom flag + config := ctx.String(flag.Name + ".config") // TODO(karalabe): Custom flag + + if err := exex.Instantiate(plugin, config); err != nil { + Fatalf("Failed to instantiate ExEx plugin %s: %v", plugin, err) + } + log.Info("Instantiated ExEx plugin", "name", plugin) } - log.Info("Instantiated ExEx plugin", "name", plugin) } } } @@ -2223,12 +2232,16 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh } } for _, flag := range ExExPluginFlags() { - if ctx.IsSet(flag.(*cli.BoolFlag).Name) { - plugin := strings.TrimLeft(flag.(*cli.BoolFlag).Name, "exex.") // TODO(karalabe): Custom flag - if err := exex.Instantiate(plugin); err != nil { - Fatalf("Failed to instantiate ExEx plugin %s: %v", plugin, err) + if flag, ok := flag.(*cli.BoolFlag); ok { + if ctx.IsSet(flag.Name) { + plugin := strings.TrimLeft(flag.Name, "exex.") // TODO(karalabe): Custom flag + config := ctx.String(flag.Name + ".config") // TODO(karalabe): Custom flag + + if err := exex.Instantiate(plugin, config); err != nil { + Fatalf("Failed to instantiate ExEx plugin %s: %v", plugin, err) + } + log.Info("Instantiated ExEx plugin", "name", plugin) } - log.Info("Instantiated ExEx plugin", "name", plugin) } } // Disable transaction indexing/unindexing by default. diff --git a/core/exex/exex.go b/core/exex/exex.go index 60ae62949f..87b5c9ec3f 100644 --- a/core/exex/exex.go +++ b/core/exex/exex.go @@ -27,7 +27,15 @@ func RegisterV1(name string, constructor NewPluginV1) { } // NewPluginV1 is the constructor signature for making a new plugin. -type NewPluginV1 func(logger log.Logger) (*PluginV1, error) +type NewPluginV1 func(config *ConfigV1) (*PluginV1, error) + +// ConfigV1 contains some configurations for initializing exex plugins. Some of +// the fields originate from Geth, other fields from user configs. +type ConfigV1 struct { + Logger log.Logger // Geth's logger with the plugin name injected + + User string // Opaque flag provided by the user on the CLI +} // PluginV1 is an Execution Extension module that can be injected into Geth's // processing pipeline to subscribe to different node, chain and EVM lifecycle diff --git a/core/exex/exex/registry.go b/core/exex/exex/registry.go index 93552d2108..32f003a25e 100644 --- a/core/exex/exex/registry.go +++ b/core/exex/exex/registry.go @@ -33,7 +33,7 @@ func init() { // triggers to be invoked. type registry interface { Plugins() []string - Instantiate(name string) error + Instantiate(name string, userconf string) error TriggerInitHook(chain exex.Chain) TriggerCloseHook() @@ -46,8 +46,8 @@ func Plugins() []string { } // Instantiate constructs an execution extension plugin from a unique name. -func Instantiate(name string) error { - return globalRegistry.Instantiate(name) +func Instantiate(name string, userconf string) error { + return globalRegistry.Instantiate(name, userconf) } // TriggerInitHook triggers the OnInit hook in exex plugins. diff --git a/core/exex/registry_internal.go b/core/exex/registry_internal.go index b65482d110..e21ad1021b 100644 --- a/core/exex/registry_internal.go +++ b/core/exex/registry_internal.go @@ -35,10 +35,13 @@ func (reg *registry) Plugins() []string { } // Instantiate constructs an execution extension plugin from a unique name. -func (reg *registry) Instantiate(name string) error { +func (reg *registry) Instantiate(name string, userconf string) error { // Try instantiating a V1 plugin if constructor, ok := globalRegistry.pluginsMakersV1[name]; ok { - plugin, err := constructor(log.New("exex", name)) + plugin, err := constructor(&ConfigV1{ + Logger: log.New("exex", name), + User: userconf, + }) if err != nil { return err } diff --git a/plugins/minimal.go b/plugins/minimal.go index 9698626333..add3497fcd 100644 --- a/plugins/minimal.go +++ b/plugins/minimal.go @@ -19,7 +19,6 @@ package plugins import ( "github.com/ethereum/go-ethereum/core/exex" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" ) // Register the minimal ExEx plugin into Geth. @@ -29,10 +28,10 @@ func init() { // newMinimalPlugin creates a minimal Execution Extension plugin to react to some // chain events. -func newMinimalPlugin(logger log.Logger) (*exex.PluginV1, error) { +func newMinimalPlugin(config *exex.ConfigV1) (*exex.PluginV1, error) { return &exex.PluginV1{ OnHead: func(head *types.Header) { - logger.Info("Chain head updated", "number", head.Number, "hash", head.Hash()) + config.Logger.Info("Chain head updated", "number", head.Number, "hash", head.Hash()) }, }, nil }