2023-06-12 16:52:46 +00:00
|
|
|
package ethconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
2023-07-31 19:43:06 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
2023-06-12 16:52:46 +00:00
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
|
|
|
2023-07-31 19:43:06 +00:00
|
|
|
"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"
|
2023-06-12 16:52:46 +00:00
|
|
|
pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-31 19:43:06 +00:00
|
|
|
func PluginGetEngine(pl *plugins.PluginLoader, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
|
2023-06-12 16:52:46 +00:00
|
|
|
fnList := pl.Lookup("CreateEngine", func(item interface{}) bool {
|
2023-07-31 19:43:06 +00:00
|
|
|
_, ok := item.(func(*pparams.ChainConfig, restricted.Database) pconsensus.Engine)
|
2023-06-12 16:52:46 +00:00
|
|
|
return ok
|
|
|
|
})
|
|
|
|
for _, fni := range fnList {
|
2023-07-31 19:43:06 +00:00
|
|
|
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 {
|
2023-06-12 16:52:46 +00:00
|
|
|
wrappedEngine := wengine.NewWrappedEngine(engine)
|
|
|
|
return wrappedEngine
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:43:06 +00:00
|
|
|
func pluginGetEngine(chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
|
2023-06-12 16:52:46 +00:00
|
|
|
if plugins.DefaultPluginLoader == nil {
|
|
|
|
log.Warn("Attempting GetEngine, but default PluginLoader has not been initialized")
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-31 19:43:06 +00:00
|
|
|
return PluginGetEngine(plugins.DefaultPluginLoader, chainConfig, db)
|
2023-06-12 16:52:46 +00:00
|
|
|
}
|