From dc56f2a361083f768cf548c3593c730da069fb96 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Tue, 11 Jul 2023 17:01:10 -0700 Subject: [PATCH] incremental commit, manual changes to support merge --- core/state_processor.go | 1 - eth/ethconfig/config.go | 17 +++++++++ plugins/wrappers/engine/enginewrapper.go | 10 +++-- rpc/plugin_subscriptions.go | 7 ++++ trie/plugin_hooks.go | 48 ------------------------ 5 files changed, 30 insertions(+), 53 deletions(-) delete mode 100644 trie/plugin_hooks.go diff --git a/core/state_processor.go b/core/state_processor.go index 321bc9016..b499f194e 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -82,7 +82,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // cfg.Debug = true } // end pluGeth code injection - vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg) // begin PluGeth code injection pluginPreProcessBlock(block) blockTracer.PreProcessBlock(block) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 5b5a30134..eaf2cd033 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -186,3 +186,20 @@ func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (conse } return beacon.New(ethash.NewFaker()), nil } + +// CreateConsensusEngine creates a consensus engine for the given chain config. +// Clique is allowed for now to live standalone, but ethash is forbidden and can +// only exist on already merged networks. +func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) { + // If proof-of-authority is requested, set it up + if config.Clique != nil { + return beacon.New(clique.New(config.Clique, db)), nil + } + // If defaulting to proof-of-work, enforce an already merged network since + // we cannot run PoW algorithms and more, so we cannot even follow a chain + // not coordinated by a beacon node. + if !config.TerminalTotalDifficultyPassed { + return nil, errors.New("ethash is only supported as a historical component of already merged networks") + } + return beacon.New(ethash.NewFaker()), nil +} diff --git a/plugins/wrappers/engine/enginewrapper.go b/plugins/wrappers/engine/enginewrapper.go index 2b95d2da5..7d004dda9 100644 --- a/plugins/wrappers/engine/enginewrapper.go +++ b/plugins/wrappers/engine/enginewrapper.go @@ -373,15 +373,17 @@ func (ew *engineWrapper) Author(header *types.Header) (common.Address, error) { addr, err := ew.engine.Author(gethToUtilsHeader(header)) return common.Address(addr), err } -func (ew *engineWrapper) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error { - return ew.engine.VerifyHeader(&WrappedHeaderReader{chain, nil}, gethToUtilsHeader(header), seal) +func (ew *engineWrapper) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error { + var dummySeal bool + return ew.engine.VerifyHeader(&WrappedHeaderReader{chain, nil}, gethToUtilsHeader(header), dummySeal) } -func (ew *engineWrapper) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { +func (ew *engineWrapper) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) { pheaders := make([]*ptypes.Header, len(headers)) for i, header := range headers { pheaders[i] = gethToUtilsHeader(header) } - return ew.engine.VerifyHeaders(&WrappedHeaderReader{chain, nil}, pheaders, seals) + dummySeals := []bool{false, false} + return ew.engine.VerifyHeaders(&WrappedHeaderReader{chain, nil}, pheaders, dummySeals) } func (ew *engineWrapper) VerifyUncles(chain consensus.ChainReader, block *types.Block) error { return ew.engine.VerifyUncles(&WrappedChainReader{chain, nil}, gethToUtilsBlock(block)) diff --git a/rpc/plugin_subscriptions.go b/rpc/plugin_subscriptions.go index ac8282925..66f2f5027 100644 --- a/rpc/plugin_subscriptions.go +++ b/rpc/plugin_subscriptions.go @@ -6,6 +6,13 @@ import ( "github.com/ethereum/go-ethereum/log" ) +// Is t context.Context or *context.Context? +func isContextType(t reflect.Type) bool { + for t.Kind() == reflect.Ptr { + t = t.Elem() + } + return t == contextType +} func isChanType(t reflect.Type) bool { // Pointers to channels are weird, but whatever diff --git a/trie/plugin_hooks.go b/trie/plugin_hooks.go deleted file mode 100644 index 1ef11c60c..000000000 --- a/trie/plugin_hooks.go +++ /dev/null @@ -1,48 +0,0 @@ -package trie - -import ( - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/plugins" - "github.com/ethereum/go-ethereum/common" - "github.com/openrelayxyz/plugeth-utils/core" -) - -func PluginPreTrieCommit(pl *plugins.PluginLoader, node common.Hash) { - fnList := pl.Lookup("PreTrieCommit", func(item interface{}) bool { - _, ok := item.(func(core.Hash)) - return ok - }) - for _, fni := range fnList { - if fn, ok := fni.(func(core.Hash)); ok { - fn(core.Hash(node)) - } - } -} - -func pluginPreTrieCommit(node common.Hash) { - if plugins.DefaultPluginLoader == nil { - log.Warn("Attempting PreTrieCommit, but default PluginLoader has not been initialized") - return - } - PluginPreTrieCommit(plugins.DefaultPluginLoader, node) -} - -func PluginPostTrieCommit(pl *plugins.PluginLoader, node common.Hash) { - fnList := pl.Lookup("PostTrieCommit", func(item interface{}) bool { - _, ok := item.(func(core.Hash)) - return ok - }) - for _, fni := range fnList { - if fn, ok := fni.(func(core.Hash)); ok { - fn(core.Hash(node)) - } - } -} - -func pluginPostTrieCommit(node common.Hash) { - if plugins.DefaultPluginLoader == nil { - log.Warn("Attempting PostTrieCommit, but default PluginLoader has not been initialized") - return - } - PluginPostTrieCommit(plugins.DefaultPluginLoader, node) -}