diff --git a/Dockerfile b/Dockerfile index 1951fed8e..db8be0dd9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG BUILDNUM="" # Build Geth in a stock Go builder container FROM golang:1.20-alpine as builder -RUN apk add --no-cache gcc musl-dev linux-headers git +RUN apk add --no-cache gcc musl-dev binutils-gold linux-headers git # Get dependencies - will also be cached if we won't change go.mod/go.sum COPY go.mod /go-ethereum/ diff --git a/README.md b/README.md index c52c76e11..3d5a51e8d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ rather than forking the Geth project. Out of the box, PluGeth behaves exactly like upstream Geth, but by installing plugins written in Golang, developers can extend its functionality in a wide variety of way. +### Submitting Pull Requests + +We are eager to include contributions from the community into the project. We ask that pull requests which include new features to be covered by our test plugin found in: `/plugins/test-plugin`. The test design and instructions for use are documented there. If further assistance is needed please get in touch with us. + ### Contact Us If you're trying to do something that isn't supported by the current plugin system, Reach out to us on [Discord](https://discord.gg/Epf7b7Gr) and we'll help you figure out how to make it work. diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 662056298..8ff471028 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -20,7 +20,7 @@ package main import ( "fmt" "os" - "path" + "path/filepath" "sort" "strconv" "strings" @@ -57,6 +57,9 @@ const ( var ( // flags that configure the node nodeFlags = flags.Merge([]cli.Flag{ + //begin PluGeth code injection + utils.PluginsDirFlag, + //end PluGeth code injection utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, @@ -322,7 +325,14 @@ func prepare(ctx *cli.Context) { // blocking mode, waiting for it to be shut down. func geth(ctx *cli.Context) error { //begin PluGeth code injection - if err := plugins.Initialize(path.Join(ctx.String(utils.DataDirFlag.Name), "plugins"), ctx); err != nil { + var pluginsDir string + if ctx.IsSet(utils.PluginsDirFlag.Name) { + pluginsDir = ctx.String(utils.PluginsDirFlag.Name) + } else { + pluginsDir = filepath.Join(ctx.String(utils.DataDirFlag.Name), "plugins") + } + + if err := plugins.Initialize(pluginsDir, ctx); err != nil { return err } prepare(ctx) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index b67671e03..8e1d637e8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -88,6 +88,14 @@ import ( var ( // General settings + //begin PluGeth code injection + PluginsDirFlag = &flags.DirectoryFlag{ + Name: "pluginsdir", + Usage: "Directory for plugins", + Value: flags.DirectoryString(filepath.Join("", "plugins")), + Category: flags.EthCategory, + } + //end PluGeth code injection DataDirFlag = &flags.DirectoryFlag{ Name: "datadir", Usage: "Data directory for the databases and keystore", diff --git a/plugins/plugin_loader.go b/plugins/plugin_loader.go index 652988d9c..dfb4af030 100644 --- a/plugins/plugin_loader.go +++ b/plugins/plugin_loader.go @@ -8,7 +8,7 @@ import ( "plugin" "reflect" "strings" - + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/openrelayxyz/plugeth-utils/core" @@ -58,6 +58,7 @@ func Lookup(name string, validate func(interface{}) bool) []interface{} { var DefaultPluginLoader *PluginLoader func NewPluginLoader(target string) (*PluginLoader, error) { + log.Info("Loading plugins from directory", "path", target) pl := &PluginLoader{ Plugins: []pluginDetails{}, Subcommands: make(map[string]Subcommand), diff --git a/plugins/test-plugin/main.go b/plugins/test-plugin/main.go index 2e76f84e1..bd6cd6a06 100644 --- a/plugins/test-plugin/main.go +++ b/plugins/test-plugin/main.go @@ -5,9 +5,11 @@ import ( "math/big" "time" "os" - + "bytes" + "github.com/openrelayxyz/plugeth-utils/core" "github.com/openrelayxyz/plugeth-utils/restricted/hexutil" + "github.com/openrelayxyz/plugeth-utils/restricted/crypto" ) var hookChan chan map[string]struct{} = make(chan map[string]struct{}, 10) @@ -223,6 +225,8 @@ func txTracer() { log.Error("debug_traceTransaction failed", "err", err) } + testGetContractCode(t3) + debugArg0 := map[string]interface{}{ "input": "0x60006000fd", "from": coinBase, @@ -242,7 +246,6 @@ func txTracer() { var trResult1 interface{} err = client.Call(&trResult1, "debug_traceCall", debugArg1, "latest", t) - final := map[string]interface{}{ "input": "0x61520873000000000000000000000000000000000000000060006000600060006000f1", "from": coinBase, @@ -258,3 +261,39 @@ func txTracer() { } +func testGetContractCode(hash core.Hash) { + + cl := apis[0].Service.(*engineService).stack + client, err := cl.Attach() + if err != nil { + log.Error("Error connecting with client testGetContractCode") + } + + receipt := map[string]interface{}{} + err = client.Call(&receipt, "eth_getTransactionReceipt", hash) + if err != nil { + log.Error("Error calling getTransactionReciepts, testGetContractCode", "err", err) + } + + var controlCode hexutil.Bytes + err = client.Call(&controlCode, "eth_getCode", receipt["contractAddress"], receipt["blockNumber"]) + if err != nil { + log.Error("Error calling getCode, testGetContractCode", "err", err) + } + + codeHash := crypto.Keccak256Hash(controlCode) + + testCode, err := apis[0].Service.(*engineService).backend.GetContractCode(codeHash) + if err != nil { + log.Error("Error calling GetContractCode", "err", err) + } + + if !bytes.Equal(testCode, controlCode) { + + log.Error("Exit with error, return value from GetContractCode is divergent from control value") + os.Exit(1) + } + + log.Info("made it through checkGetContractCode") +} + diff --git a/plugins/wrappers/backendwrapper/backendwrapper.go b/plugins/wrappers/backendwrapper/backendwrapper.go index 6716d4182..083e070c8 100644 --- a/plugins/wrappers/backendwrapper/backendwrapper.go +++ b/plugins/wrappers/backendwrapper/backendwrapper.go @@ -11,8 +11,9 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" gcore "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/event" gparams "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/internal/ethapi" @@ -510,7 +511,6 @@ func (b *Backend) GetAccountTrie(stateRoot core.Hash, account core.Address) (cor return NewWrappedTrie(acTr), nil } - - - - +func (b *Backend) GetContractCode(h core.Hash) ([]byte, error) { + return state.NewDatabase(b.b.ChainDb()).ContractCode(common.Hash{}, common.Hash(h)) +}