Plugin Interface Refactor

This makes two main changes to the plugin system:

* Instead of assuming that each plugin will have exactly one type,
  inspect each plugin to see which interfaces it provides, and
  register it as a provider of each provided interface. This can
  allow a single .so file to provide multiple interfaces, which
  will likely be necessary for aggregating certain types of info.
* Rather than using dependency injection and having to propagate
  the plugin system all throughout Geth, have a default plugin
  loader so we need only import the module and make calls to it.
  If the plan were to integrate this into mainline Geth, I would
  say we use dependency injection and take the time to pass the
  plugin loader throughout the codebase, but as I expect this to
  be a fork that has to pull upstream changes, this approach
  should make merge conflicts much less common.
This commit is contained in:
Austin Roberts
2021-06-25 10:57:56 -05:00
parent ff46e3c7f8
commit 5c55657c54
4 changed files with 58 additions and 53 deletions
+9 -2
View File
@@ -20,6 +20,7 @@ package main
import (
"fmt"
"os"
"path"
"sort"
"strconv"
"strings"
@@ -39,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/plugins"
"gopkg.in/urfave/cli.v1"
)
@@ -311,13 +313,18 @@ func prepare(ctx *cli.Context) {
// It creates a default node based on the command line arguments and runs it in
// blocking mode, waiting for it to be shut down.
func geth(ctx *cli.Context) error {
if args := ctx.Args(); len(args) > 0 {
return fmt.Errorf("invalid command: %q", args[0])
if err := plugins.Initialize(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "plugins")); err != nil { return err }
if ok, err := plugins.RunSubcommand(ctx); ok { return err }
if !plugins.ParseFlags(ctx.Args()) {
if args := ctx.Args(); len(args) > 0 {
return fmt.Errorf("invalid command: %q", args[0])
}
}
prepare(ctx)
stack, backend := makeFullNode(ctx)
defer stack.Close()
stack.RegisterAPIs(plugins.GetAPIs(stack, backend))
startNode(ctx, stack, backend)
stack.Wait()