From cb62de132cdef66d1a2f4aadc131a9ba9d96ca46 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Tue, 10 Oct 2023 15:26:47 -0700 Subject: [PATCH] Added forkIDs plugin hook --- cmd/utils/plugin_hooks.go | 1 + core/forkid/forkid.go | 6 ++++++ core/forkid/plugin_hooks.go | 37 +++++++++++++++++++++++++++++++++++++ go.mod | 4 +++- go.sum | 6 ++---- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 core/forkid/plugin_hooks.go diff --git a/cmd/utils/plugin_hooks.go b/cmd/utils/plugin_hooks.go index df28ad8f1..12b85b581 100644 --- a/cmd/utils/plugin_hooks.go +++ b/cmd/utils/plugin_hooks.go @@ -22,6 +22,7 @@ func DefaultDataDir(pl *plugins.PluginLoader, path string) string { } func pluginDefaultDataDir(path string) string { + log.Error("public default data dir") if plugins.DefaultPluginLoader == nil { log.Warn("Attempting DefaultDataDir, but default PluginLoader has not been initialized") return "" diff --git a/core/forkid/forkid.go b/core/forkid/forkid.go index 76825d3be..c43c74473 100644 --- a/core/forkid/forkid.go +++ b/core/forkid/forkid.go @@ -240,6 +240,12 @@ func checksumToBytes(hash uint32) [4]byte { // gatherForks gathers all the known forks and creates two sorted lists out of // them, one for the block number based forks and the second for the timestamps. func gatherForks(config *params.ChainConfig, genesis uint64) ([]uint64, []uint64) { + // begin PluGeth injection + if byBlock, byTime, ok := pluginForkIDs(); ok { + return byBlock, byTime + } + // end PluGeth injection + // Gather all the fork block numbers via reflection kind := reflect.TypeOf(params.ChainConfig{}) conf := reflect.ValueOf(config).Elem() diff --git a/core/forkid/plugin_hooks.go b/core/forkid/plugin_hooks.go new file mode 100644 index 000000000..222ef7b2a --- /dev/null +++ b/core/forkid/plugin_hooks.go @@ -0,0 +1,37 @@ +package forkid + +import ( + // "encoding/json" + // "math/big" + // "reflect" + // "time" + // "sync" + + // "github.com/ethereum/go-ethereum/common" + // "github.com/ethereum/go-ethereum/core/state" + // "github.com/ethereum/go-ethereum/core/types" + // "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" + // "github.com/ethereum/go-ethereum/plugins/wrappers" + // "github.com/ethereum/go-ethereum/rlp" + // "github.com/openrelayxyz/plugeth-utils/core" +) + +func PluginForkIDs(pl *plugins.PluginLoader) ([]uint64, []uint64, bool) { + f, ok := plugins.LookupOne[func() ([]uint64, []uint64)](pl, "ForkIDs") + if !ok { + return nil, nil, false + } + byBlock, byTime := f() + + return byBlock, byTime, ok +} + +func pluginForkIDs() ([]uint64, []uint64, bool) { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting PluginForkIDs, but default PluginLoader has not been initialized") + return nil, nil, false + } + return PluginForkIDs(plugins.DefaultPluginLoader) +} diff --git a/go.mod b/go.mod index 2490cd6e3..e2395b2a4 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/consensys/gnark-crypto v0.10.0 github.com/crate-crypto/go-kzg-4844 v0.3.0 github.com/davecgh/go-spew v1.1.1 - github.com/deckarep/golang-set/v2 v2.1.0 + github.com/deckarep/golang-set/v2 v2.3.1 github.com/docker/docker v24.0.5+incompatible github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 github.com/ethereum/c-kzg-4844 v0.3.1 @@ -134,3 +134,5 @@ require ( gotest.tools/v3 v3.5.0 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) + +replace github.com/openrelayxyz/plugeth-utils => /home/philip/src/rivet/plugeth_superspace/plugeth-utils diff --git a/go.sum b/go.sum index 57596642f..fa02d7d76 100644 --- a/go.sum +++ b/go.sum @@ -142,8 +142,8 @@ github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= -github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A= +github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= @@ -458,8 +458,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/openrelayxyz/plugeth-utils v1.3.0 h1:0goW7zzasytejXJJcWCJiIRXl3X8o/oFtK8zKF//rlE= -github.com/openrelayxyz/plugeth-utils v1.3.0/go.mod h1:p5Jc8deG2yxXI8DzmrH3kHNEwlQqcOQS0pmGulsqg+M= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=