Changes to core/blockchain_hook_test, core/state/plugin_hooks, and eth/plugin_hooks to reslove issues discovered in pull review 9-17-21
This commit is contained in:
parent
88f38674d1
commit
3af3c8c951
@ -2,21 +2,28 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/ethereum/go-ethereum/plugins"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/plugins"
|
||||||
|
"github.com/openrelayxyz/plugeth-utils/core"
|
||||||
|
)
|
||||||
|
|
||||||
func TestReorgLongHeadersHook(t *testing.T) {
|
func TestReorgLongHeadersHook(t *testing.T) {
|
||||||
invoked := false
|
invoked := false
|
||||||
done := plugins.HookTester("NewHead", func(b *types.Block, h common.Hash, logs []*types.Log) {
|
done := plugins.HookTester("NewHead", func(b []byte, h core.Hash, logs [][]byte) {
|
||||||
// invoked = true
|
invoked = true
|
||||||
if b == nil { t.Errorf("Expected block to be non-nil") }
|
if b == nil {
|
||||||
if h == (common.Hash{}) { t.Errorf("Expected hash to be non-empty") }
|
t.Errorf("Expected block to be non-nil")
|
||||||
if len(logs) > 0 { t.Errorf("Expected some logs") }
|
}
|
||||||
|
if h == (core.Hash{}) {
|
||||||
|
t.Errorf("Expected hash to be non-empty")
|
||||||
|
}
|
||||||
|
if len(logs) > 0 {
|
||||||
|
t.Errorf("Expected some logs")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
defer done()
|
defer done()
|
||||||
testReorgLong(t, true)
|
testReorgLong(t, true)
|
||||||
if !invoked { t.Errorf("Expected plugin invocation")}
|
if !invoked {
|
||||||
|
t.Errorf("Expected plugin invocation")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"github.com/openrelayxyz/plugeth-utils/core"
|
"github.com/openrelayxyz/plugeth-utils/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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) {
|
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 {
|
fnList := pl.Lookup("StateUpdate", func(item interface{}) bool {
|
||||||
_, ok := item.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte))
|
_, ok := item.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte))
|
||||||
|
@ -13,28 +13,6 @@ import (
|
|||||||
"github.com/openrelayxyz/plugeth-utils/core"
|
"github.com/openrelayxyz/plugeth-utils/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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.TracerResult instead of vm.Tracer, with appropriate type adjustments (let me know if this one is too hard)
|
|
||||||
type metaTracer struct {
|
type metaTracer struct {
|
||||||
tracers []core.TracerResult
|
tracers []core.TracerResult
|
||||||
}
|
}
|
||||||
@ -77,21 +55,11 @@ func PluginUpdateBlockchainVMConfig(pl *plugins.PluginLoader, cfg *vm.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.Debug = true
|
cfg.Debug = true
|
||||||
cfg.Tracer = mt //I think this means we will need a vm.config wrapper although confugure doesnt sound very passive
|
cfg.Tracer = mt
|
||||||
} else {
|
} else {
|
||||||
log.Warn("Module is not tracer")
|
log.Warn("Module is not tracer")
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
||||||
|
Loading…
Reference in New Issue
Block a user