Add reorg hooks, fix hook name lookup
This commit is contained in:
parent
c45774b74b
commit
7a8bb87257
@ -2196,6 +2196,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
|
|||||||
msg = "Large chain reorg detected"
|
msg = "Large chain reorg detected"
|
||||||
logFn = log.Warn
|
logFn = log.Warn
|
||||||
}
|
}
|
||||||
|
pluginReorg(commonBlock, oldChain, newChain)
|
||||||
logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(),
|
logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(),
|
||||||
"drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash())
|
"drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash())
|
||||||
blockReorgAddMeter.Mark(int64(len(newChain)))
|
blockReorgAddMeter.Mark(int64(len(newChain)))
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func PluginPreProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
func PluginPreProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
||||||
fnList := pl.Lookup("ProcessBlock", func(item interface{}) bool {
|
fnList := pl.Lookup("PreProcessBlock", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Block))
|
_, ok := item.(func(*types.Block))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -26,7 +26,7 @@ func pluginPreProcessBlock(block *types.Block) {
|
|||||||
PluginPreProcessBlock(plugins.DefaultPluginLoader, block) // TODO
|
PluginPreProcessBlock(plugins.DefaultPluginLoader, block) // TODO
|
||||||
}
|
}
|
||||||
func PluginPreProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int) {
|
func PluginPreProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int) {
|
||||||
fnList := pl.Lookup("ProcessTransaction", func(item interface{}) bool {
|
fnList := pl.Lookup("PreProcessTransaction", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, int))
|
_, ok := item.(func(*types.Transaction, *types.Block, int))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -44,7 +44,7 @@ func pluginPreProcessTransaction(tx *types.Transaction, block *types.Block, i in
|
|||||||
PluginPreProcessTransaction(plugins.DefaultPluginLoader, tx, block, i)
|
PluginPreProcessTransaction(plugins.DefaultPluginLoader, tx, block, i)
|
||||||
}
|
}
|
||||||
func PluginBlockProcessingError(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, err error) {
|
func PluginBlockProcessingError(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, err error) {
|
||||||
fnList := pl.Lookup("ProcessingError", func(item interface{}) bool {
|
fnList := pl.Lookup("BlockProcessingError", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, error))
|
_, ok := item.(func(*types.Transaction, *types.Block, error))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -62,7 +62,7 @@ func pluginBlockProcessingError(tx *types.Transaction, block *types.Block, err e
|
|||||||
PluginBlockProcessingError(plugins.DefaultPluginLoader, tx, block, err)
|
PluginBlockProcessingError(plugins.DefaultPluginLoader, tx, block, err)
|
||||||
}
|
}
|
||||||
func PluginPostProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
|
func PluginPostProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
|
||||||
fnList := pl.Lookup("ProcessTransaction", func(item interface{}) bool {
|
fnList := pl.Lookup("PostProcessTransaction", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, int, *types.Receipt))
|
_, ok := item.(func(*types.Transaction, *types.Block, int, *types.Receipt))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -80,7 +80,7 @@ func pluginPostProcessTransaction(tx *types.Transaction, block *types.Block, i i
|
|||||||
PluginPostProcessTransaction(plugins.DefaultPluginLoader, tx, block, i, receipt)
|
PluginPostProcessTransaction(plugins.DefaultPluginLoader, tx, block, i, receipt)
|
||||||
}
|
}
|
||||||
func PluginPostProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
func PluginPostProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
||||||
fnList := pl.Lookup("ProcessBlock", func(item interface{}) bool {
|
fnList := pl.Lookup("PostProcessBlock", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Block))
|
_, ok := item.(func(*types.Block))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -136,3 +136,22 @@ func pluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log)
|
|||||||
}
|
}
|
||||||
PluginNewSideBlock(plugins.DefaultPluginLoader, block, hash, logs)
|
PluginNewSideBlock(plugins.DefaultPluginLoader, block, hash, logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PluginReorg(pl *plugins.PluginLoader, commonBlock *types.Block, oldChain, newChain types.Blocks) {
|
||||||
|
fnList := pl.Lookup("Reorg", func(item interface{}) bool {
|
||||||
|
_, ok := item.(func(common *types.Block, oldChain, newChain types.Blocks))
|
||||||
|
return ok
|
||||||
|
})
|
||||||
|
for _, fni := range fnList {
|
||||||
|
if fn, ok := fni.(func(common *types.Block, oldChain, newChain types.Blocks)); ok {
|
||||||
|
fn(commonBlock, oldChain, newChain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func pluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting Reorg, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginReorg(plugins.DefaultPluginLoader, commonBlock, oldChain, newChain)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user