diff --git a/core/plugeth_injection_test.go b/core/plugeth_injection_test.go index faa7c2399..3068cb68e 100644 --- a/core/plugeth_injection_test.go +++ b/core/plugeth_injection_test.go @@ -1,6 +1,7 @@ package core import ( + // "reflect" "fmt" "testing" "math/big" @@ -61,7 +62,7 @@ var ( ) -func TestBlockProcessingInjections(t *testing.T) { +func TestPlugethInjections(t *testing.T) { blockchain, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil) @@ -89,5 +90,23 @@ func TestBlockProcessingInjections(t *testing.T) { } }) - -} \ No newline at end of file + t.Run(fmt.Sprintf("test Reorg"), func(t *testing.T) { + called := false + injectionCalled = &called + + // the transaction has to be initialized with a different gas price than the previous tx in order to trigger a reorg + txns2 := []*types.Transaction{ + makeTx(key1, 0, common.Address{}, big.NewInt(1000), params.TxGas-1000, big.NewInt(875000001), nil), + } + block2 := GenerateBadBlock(gspec.ToBlock(), engine, txns2, gspec.Config) + + + _, _ = blockchain.writeBlockAndSetHead(block, []*types.Receipt{}, []*types.Log{}, statedb, false) + + _ = blockchain.reorg(block.Header(), block2) + + if *injectionCalled != true { + t.Fatalf("pluginReorg injection in blockChain.Reorg() not called") + } + }) +} \ No newline at end of file diff --git a/core/plugin_hooks.go b/core/plugin_hooks.go index 9abbfa723..06d2e89ee 100644 --- a/core/plugin_hooks.go +++ b/core/plugin_hooks.go @@ -169,6 +169,7 @@ func pluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) } func PluginReorg(pl *plugins.PluginLoader, commonBlock *types.Block, oldChain, newChain types.Blocks) { + fnList := pl.Lookup("Reorg", func(item interface{}) bool { _, ok := item.(func(core.Hash, []core.Hash, []core.Hash)) return ok @@ -188,6 +189,12 @@ func PluginReorg(pl *plugins.PluginLoader, commonBlock *types.Block, oldChain, n } } func pluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { + + if injectionCalled != nil { + called := true + injectionCalled = &called + } + if plugins.DefaultPluginLoader == nil { log.Warn("Attempting Reorg, but default PluginLoader has not been initialized") return