Initial commit of stand alone consensus engine work.

This commit is contained in:
philip-morlier
2023-06-12 09:52:46 -07:00
parent 9badeb2b93
commit 7434ccb8c8
7 changed files with 548 additions and 1 deletions
+6
View File
@@ -212,6 +212,12 @@ type Config struct {
// CreateConsensusEngine creates a consensus engine for the given chain configuration.
func CreateConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
//begin PluGeth code injection
if engine := pluginGetEngine(stack, notify, noverify, db); engine != nil {
log.Debug("returning plugin consensus engine")
return engine
}
//end PluGeth code injection
var engine consensus.Engine
if cliqueConfig != nil {
engine = clique.New(cliqueConfig, db)
+44
View File
@@ -0,0 +1,44 @@
package ethconfig
import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/plugins"
"github.com/ethereum/go-ethereum/plugins/wrappers"
wengine "github.com/ethereum/go-ethereum/plugins/wrappers/engine"
"github.com/ethereum/go-ethereum/plugins/wrappers/backendwrapper"
"github.com/openrelayxyz/plugeth-utils/core"
"github.com/openrelayxyz/plugeth-utils/restricted"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/node"
pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus"
)
func PluginGetEngine(pl *plugins.PluginLoader, stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
fnList := pl.Lookup("CreateEngine", func(item interface{}) bool {
_, ok := item.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine); ok {
if engine := fn(wrappers.NewNode(stack), notify, noverify, backendwrapper.NewDB(db)); engine != nil {
wrappedEngine := wengine.NewWrappedEngine(engine)
return wrappedEngine
}
}
}
return nil
}
func pluginGetEngine(stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting GetEngine, but default PluginLoader has not been initialized")
return nil
}
return PluginGetEngine(plugins.DefaultPluginLoader, stack, notify, noverify, db)
}