diff --git a/core/plugin_hooks.go b/core/plugin_hooks.go index 0189d1388..c5636d9c7 100644 --- a/core/plugin_hooks.go +++ b/core/plugin_hooks.go @@ -5,16 +5,18 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/plugins" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rlp" ) func PluginPreProcessBlock(pl *plugins.PluginLoader, block *types.Block) { fnList := pl.Lookup("PreProcessBlock", func(item interface{}) bool { - _, ok := item.(func(*types.Block)) + _, ok := item.(func([]byte)) return ok }) + encoded, _ = rlp.EncodeToBytes(block) for _, fni := range fnList { - if fn, ok := fni.(func(*types.Block)); ok { - fn(block) + if fn, ok := fni.(func([]byte)); ok { + fn(encoded) } } } @@ -27,12 +29,14 @@ func pluginPreProcessBlock(block *types.Block) { } func PluginPreProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int) { fnList := pl.Lookup("PreProcessTransaction", func(item interface{}) bool { - _, ok := item.(func(*types.Transaction, *types.Block, int)) + _, ok := item.(func([]byte, []byte, int)) return ok }) + txBytes, _ := tx.MarshalBinary() + blockBytes, _ := rlp.EncodeToBytes(block) for _, fni := range fnList { - if fn, ok := fni.(func(*types.Transaction, *types.Block, int)); ok { - fn(tx, block, i) + if fn, ok := fni.(func([]byte, []byte, int)); ok { + fn(txBytes, blockBytes, i) } } } diff --git a/core/state/plugin_hooks.go b/core/state/plugin_hooks.go index 5d11c4602..e55615dfb 100644 --- a/core/state/plugin_hooks.go +++ b/core/state/plugin_hooks.go @@ -6,6 +6,8 @@ import ( "github.com/ethereum/go-ethereum/log" ) +// TODO (philip): change common.Hash to core.Hash, + func PluginStateUpdate(pl *plugins.PluginLoader, blockRoot, parentRoot common.Hash, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte) { fnList := pl.Lookup("StateUpdate", func(item interface{}) bool { _, ok := item.(func(common.Hash, common.Hash, map[common.Hash]struct{}, map[common.Hash][]byte, map[common.Hash]map[common.Hash][]byte)) diff --git a/eth/plugin_hooks.go b/eth/plugin_hooks.go index 6ce5a6015..394b30a90 100644 --- a/eth/plugin_hooks.go +++ b/eth/plugin_hooks.go @@ -16,27 +16,28 @@ import ( "time" ) -func PluginCreateConsensusEngine(pl *plugins.PluginLoader, stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { - fnList := pl.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 pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { - if plugins.DefaultPluginLoader == nil { - log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized") - return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db) - } - return PluginCreateConsensusEngine(plugins.DefaultPluginLoader, stack, chainConfig, config, notify, noverify, db) -} +// func PluginCreateConsensusEngine(pl *plugins.PluginLoader, stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { +// fnList := pl.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 pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { +// if plugins.DefaultPluginLoader == nil { +// log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized") +// return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db) +// } +// return PluginCreateConsensusEngine(plugins.DefaultPluginLoader, stack, chainConfig, config, notify, noverify, db) +// } +// TODO (philip): Translate to core.Tracer instead of vm.Tracer, with appropriate type adjustments (let me know if this one is too hard) type metaTracer struct{ tracers []vm.Tracer } diff --git a/eth/tracers/plugin_hooks.go b/eth/tracers/plugin_hooks.go index be6ab2d0d..cbb6ceb5e 100644 --- a/eth/tracers/plugin_hooks.go +++ b/eth/tracers/plugin_hooks.go @@ -8,6 +8,7 @@ import ( "reflect" ) +// TODO (philip): Translate to use core.Tracer instead of vm.Tracer. This will require a wrapper func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB)interfaces.TracerResult, bool) { tracers := pl.Lookup("Tracers", func(item interface{}) bool { _, ok := item.(*map[string]func(*state.StateDB)interfaces.TracerResult)