03808de29a
When the plugin loader itself had to know the types in the arguments and return values of the plugin functions, it was very difficult to avoid import loops, given that the types were often defined in the same package that needed to invoke the plugins. Under this model, the plugin loader has much less knowledge of the plugins themselves, and within each package we define functions to interact with the plugins.
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package eth
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/plugins"
|
|
"github.com/ethereum/go-ethereum/node"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
)
|
|
|
|
|
|
func pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
|
fnList := plugins.Lookup("CreateConsensusEngine", func(item interface{}) bool {
|
|
_, ok := item.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine)
|
|
return ok
|
|
})
|
|
for _, fni := range fnList {
|
|
if fn, ok := fni.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine); ok {
|
|
return fn(stack, chainConfig, config, notify, noverify, db)
|
|
}
|
|
}
|
|
return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
|
}
|
|
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
|
fnList := plugins.Lookup("UpdateBlockchainVMConfig", func(item interface{}) bool {
|
|
_, ok := item.(func(*vm.Config))
|
|
return ok
|
|
})
|
|
for _, fni := range fnList {
|
|
if fn, ok := fni.(func(*vm.Config)); ok {
|
|
fn(cfg)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// ce, err := plug.Lookup("CreateConsensusEngine")
|
|
// if err == nil {
|
|
// cce, ok := ce.(func (stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine)
|
|
// if !ok {
|
|
// log.Warn("Could not cast plugin.CreateConsensusEngine to appropriate function", "file", fpath)
|
|
// } else {
|
|
// if setConsensus {
|
|
// log.Warn("CreateConsensusEngine redeclared", "file", fpath)
|
|
// }
|
|
// pl.CreateConsensusEngine = cce
|
|
// setConsensus = true
|
|
// }
|
|
// }
|