Added hook into trie.Database.Commit() in the trie package.
The hook enables a pre and post commit plugin to report on the status of the commit and expose this information to plugins.
This commit is contained in:
parent
50a295b789
commit
27810f60ad
@ -637,6 +637,11 @@ func (db *Database) Commit(node common.Hash, report bool) error {
|
|||||||
// outside code doesn't see an inconsistent state (referenced data removed from
|
// outside code doesn't see an inconsistent state (referenced data removed from
|
||||||
// memory cache during commit but not yet in persistent storage). This is ensured
|
// memory cache during commit but not yet in persistent storage). This is ensured
|
||||||
// by only uncaching existing data when the database write finalizes.
|
// by only uncaching existing data when the database write finalizes.
|
||||||
|
|
||||||
|
// begin PluGeth injection
|
||||||
|
pluginPreTrieCommit(node)
|
||||||
|
// end PluGeth injection
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
batch := db.diskdb.NewBatch()
|
batch := db.diskdb.NewBatch()
|
||||||
|
|
||||||
@ -683,6 +688,10 @@ func (db *Database) Commit(node common.Hash, report bool) error {
|
|||||||
db.gcnodes, db.gcsize, db.gctime = 0, 0, 0
|
db.gcnodes, db.gcsize, db.gctime = 0, 0, 0
|
||||||
db.flushnodes, db.flushsize, db.flushtime = 0, 0, 0
|
db.flushnodes, db.flushsize, db.flushtime = 0, 0, 0
|
||||||
|
|
||||||
|
// begin PluGeth injection
|
||||||
|
pluginPostTrieCommit(node)
|
||||||
|
// end PluGeth injection
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
trie/plugin_hooks.go
Normal file
46
trie/plugin_hooks.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package trie
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PluginPreTrieCommit(pl *plugins.PluginLoader, node common.Hash) {
|
||||||
|
fnList := pl.Lookup("PreTrieCommit", func(item interface{}) bool {
|
||||||
|
_, ok := item.(func(common.Hash))
|
||||||
|
return ok
|
||||||
|
})
|
||||||
|
for _, fni := range fnList {
|
||||||
|
if fn, ok := fni.(func(common.Hash)); ok {
|
||||||
|
fn(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pluginPreTrieCommit(node common.Hash,) {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PreTrieCommit, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPreTrieCommit(plugins.DefaultPluginLoader, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PluginPostTrieCommit(pl *plugins.PluginLoader, node common.Hash) {
|
||||||
|
fnList := pl.Lookup("PostTrieCommit", func(item interface{}) bool {
|
||||||
|
_, ok := item.(func(common.Hash))
|
||||||
|
return ok
|
||||||
|
})
|
||||||
|
for _, fni := range fnList {
|
||||||
|
if fn, ok := fni.(func(common.Hash)); ok {
|
||||||
|
fn(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pluginPostTrieCommit(node common.Hash,) {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PostTrieCommit, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPostTrieCommit(plugins.DefaultPluginLoader, node)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user