diff --git a/trie/database.go b/trie/database.go index 895ffdf89..5b55293b2 100644 --- a/trie/database.go +++ b/trie/database.go @@ -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 // memory cache during commit but not yet in persistent storage). This is ensured // by only uncaching existing data when the database write finalizes. + + // begin PluGeth injection + pluginPreTrieCommit(node) + // end PluGeth injection + start := time.Now() 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.flushnodes, db.flushsize, db.flushtime = 0, 0, 0 + // begin PluGeth injection + pluginPostTrieCommit(node) + // end PluGeth injection + return nil } diff --git a/trie/plugin_hooks.go b/trie/plugin_hooks.go new file mode 100644 index 000000000..478b7f126 --- /dev/null +++ b/trie/plugin_hooks.go @@ -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) +} \ No newline at end of file