From 39b5250f63aa017323d1fc1a271f3171d987067f Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Mon, 23 Oct 2023 17:25:52 -0700 Subject: [PATCH] ForkIDs() added to test plugin --- cmd/utils/flags.go | 2 -- core/forkid/forkid.go | 10 +++++----- core/forkid/plugin_hooks.go | 38 ++++++++++++++++++------------------ plugins/test-plugin/hooks.go | 23 +++++++++++++++++++--- plugins/test-plugin/main.go | 2 ++ 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2b0542084..083039c2e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1447,7 +1447,6 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { setGraphQL(ctx, cfg) setWS(ctx, cfg) setNodeUserIdent(ctx, cfg) - log.Error("calling set data dir", "cfg.datadir", cfg.DataDir) SetDataDir(ctx, cfg) setSmartCard(ctx, cfg) @@ -1512,7 +1511,6 @@ func setSmartCard(ctx *cli.Context, cfg *node.Config) { } func SetDataDir(ctx *cli.Context, cfg *node.Config) { - log.Error("Inside of setDataDir", "default", node.DefaultDataDir()) // begin PluGeth injection pluginPath := pluginDefaultDataDir(node.DefaultDataDir()) switch { diff --git a/core/forkid/forkid.go b/core/forkid/forkid.go index c43c74473..1bf81f8dd 100644 --- a/core/forkid/forkid.go +++ b/core/forkid/forkid.go @@ -240,11 +240,6 @@ 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{}) @@ -299,5 +294,10 @@ func gatherForks(config *params.ChainConfig, genesis uint64) ([]uint64, []uint64 for len(forksByTime) > 0 && forksByTime[0] <= genesis { forksByTime = forksByTime[1:] } + // begin PluGeth injection + if byBlock, byTime, ok := pluginForkIDs(forksByBlock, forksByTime); ok { + return byBlock, byTime + } + // end PluGeth injection return forksByBlock, forksByTime } diff --git a/core/forkid/plugin_hooks.go b/core/forkid/plugin_hooks.go index 222ef7b2a..b9102c9b8 100644 --- a/core/forkid/plugin_hooks.go +++ b/core/forkid/plugin_hooks.go @@ -1,37 +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") +func PluginForkIDs(pl *plugins.PluginLoader, byBlock, byTime []uint64) ([]uint64, []uint64, bool) { + f, ok := plugins.LookupOne[func([]uint64, []uint64) ([]uint64, []uint64)](pl, "ForkIDs") if !ok { return nil, nil, false } - byBlock, byTime := f() + pluginByBlock, pluginByTime := f(byBlock, byTime) - return byBlock, byTime, ok + return pluginByBlock, pluginByTime, ok + + // fnList := pl.Lookup("ForkIDs", func(item interface{}) bool { + // _, ok := item.(func([]uint64, []uint64) ([]uint64, []uint64)) + // return ok + // }) + // for _, fni := range fnList { + // if fn, ok := fni.(func([]uint64, []uint64) ([]uint64, []uint64)); ok { + // pluginByBlock, pluginByTime := fn(byBlock, byTime) + // return pluginByBlock, pluginByTime, true + // } + // } + + // return nil, nil, false } -func pluginForkIDs() ([]uint64, []uint64, bool) { +func pluginForkIDs(byBlock, byTime []uint64) ([]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) + return PluginForkIDs(plugins.DefaultPluginLoader, byBlock, byTime) } diff --git a/plugins/test-plugin/hooks.go b/plugins/test-plugin/hooks.go index 72a1c76ae..1a60266a1 100644 --- a/plugins/test-plugin/hooks.go +++ b/plugins/test-plugin/hooks.go @@ -141,6 +141,23 @@ func SetTrieFlushIntervalClone(duration time.Duration) time.Duration { return duration } +// core/forkid/ + +var onceZero sync.Once + +func ForkIDs(byBlock, byTime []uint64) ([]uint64, []uint64) { + go func() { + onceZero.Do(func() { + m := map[string]struct{}{ + "ForkIDs":struct{}{}, + } + hookChan <- m + }) + }() + + return byBlock, byTime +} + // core/rawdb/ func ModifyAncients(index uint64, freezerUpdate map[string]struct{}) { @@ -154,7 +171,6 @@ func AppendAncient(number uint64, hash, header, body, receipts, td []byte) { // core/state/ func StateUpdate(blockRoot core.Hash, parentRoot core.Hash, coreDestructs map[core.Hash]struct{}, coreAccounts map[core.Hash][]byte, coreStorage map[core.Hash]map[core.Hash][]byte, coreCode map[core.Hash][]byte) { - // log.Warn("StatueUpdate", "blockRoot", blockRoot, "parentRoot", parentRoot, "coreDestructs", coreDestructs, "coreAccounts", coreAccounts, "coreStorage", coreStorage, "coreCode", coreCode) m := map[string]struct{}{ "StateUpdate":struct{}{}, } @@ -171,11 +187,11 @@ func GetRPCCalls(method string, id string, params string) { hookChan <- m } -var once sync.Once +var onceOne sync.Once func RPCSubscriptionTest() { go func() { - once.Do(func() { + onceOne.Do(func() { m := map[string]struct{}{ "RPCSubscriptionTest":struct{}{}, } @@ -230,5 +246,6 @@ var plugins map[string]struct{} = map[string]struct{}{ "SetNetworkId":struct{}{}, "SetETHDiscoveryURLs": struct{}{}, "SetSnapDiscoveryURLs": struct{}{}, + "ForkIDs": struct{}{}, } diff --git a/plugins/test-plugin/main.go b/plugins/test-plugin/main.go index 9acd1b908..313e87572 100644 --- a/plugins/test-plugin/main.go +++ b/plugins/test-plugin/main.go @@ -126,6 +126,8 @@ func BlockChain() { delete(plugins, "SetETHDiscoveryURLs") case f("SetSnapDiscoveryURLs"): delete(plugins, "SetSnapDiscoveryURLs") + case f("ForkIDs"): + delete(plugins, "ForkIDs") } } }