A couple of translation examples plus todos for Philip

This commit is contained in:
Austin Roberts 2021-08-31 15:51:41 -05:00
parent 820a0af71c
commit 8291edc416
4 changed files with 34 additions and 26 deletions

View File

@ -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)
}
}
}

View File

@ -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))

View File

@ -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
}

View File

@ -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)