Changes made to support unity across all plugeth projects with resepct to consensus engine.

This commit is contained in:
philip-morlier
2023-07-31 12:43:06 -07:00
parent 477985fdcd
commit bb43b2cbc4
6 changed files with 41 additions and 88 deletions
+2 -2
View File
@@ -171,8 +171,8 @@ type Config struct {
func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
// If proof-of-authority is requested, set it up
//begin PluGeth code injection
if engine := pluginGetEngine(); engine != nil {
log.Error("returning plugin consensus engine")
if engine := pluginGetEngine(config, db); engine != nil {
log.Info("returning plugin consensus engine")
return engine, nil
}
//end PluGeth code injection
+15 -14
View File
@@ -3,29 +3,30 @@ 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/params"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/consensus"
// "github.com/ethereum/go-ethereum/ethdb"
// "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/plugins/wrappers/backendwrapper"
wengine "github.com/ethereum/go-ethereum/plugins/wrappers/engine"
"github.com/openrelayxyz/plugeth-utils/restricted"
pparams "github.com/openrelayxyz/plugeth-utils/restricted/params"
pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus"
)
func PluginGetEngine(pl *plugins.PluginLoader) consensus.Engine {
func PluginGetEngine(pl *plugins.PluginLoader, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
fnList := pl.Lookup("CreateEngine", func(item interface{}) bool {
_, ok := item.(func() pconsensus.Engine)
_, ok := item.(func(*pparams.ChainConfig, restricted.Database) pconsensus.Engine)
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func() pconsensus.Engine); ok {
if engine := fn(); engine != nil {
if fn, ok := fni.(func(*pparams.ChainConfig, restricted.Database) pconsensus.Engine); ok {
clonedConfig := backendwrapper.CloneChainConfig(chainConfig)
wrappedDb := backendwrapper.NewDb(db)
if engine := fn(clonedConfig, wrappedDb); engine != nil {
wrappedEngine := wengine.NewWrappedEngine(engine)
return wrappedEngine
}
@@ -35,10 +36,10 @@ func PluginGetEngine(pl *plugins.PluginLoader) consensus.Engine {
return nil
}
func pluginGetEngine() consensus.Engine {
func pluginGetEngine(chainConfig *params.ChainConfig, 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)
return PluginGetEngine(plugins.DefaultPluginLoader, chainConfig, db)
}