From 0186a124128c8baab862c757ab9718bbb11d6c04 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Sun, 19 Feb 2023 19:00:40 -0800 Subject: [PATCH] functional and tested setTrieFlushIntervalClone plugin --- core/blockchain.go | 5 +++++ core/plugin_hooks.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index bb41601f7..39ff09b3e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1366,6 +1366,11 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. chosen := current - TriesInMemory flushInterval := time.Duration(atomic.LoadInt64(&bc.flushInterval)) // If we exceeded time allowance, flush an entire trie to disk + + // begin PluGeth code injection + flushInterval = pluginSetTrieFlushIntervalClone(flushInterval) + // end PluGeth code injection + if bc.gcproc > flushInterval { // If the header is missing (canonical chain behind), we're reorging a low // diff sidechain. Suspend committing until this operation is completed. diff --git a/core/plugin_hooks.go b/core/plugin_hooks.go index 14120903f..0786761cf 100644 --- a/core/plugin_hooks.go +++ b/core/plugin_hooks.go @@ -4,6 +4,7 @@ import ( "encoding/json" "math/big" "reflect" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -296,3 +297,24 @@ func pluginGetBlockTracer(hash common.Hash, statedb *state.StateDB) (*metaTracer } return PluginGetBlockTracer(plugins.DefaultPluginLoader, hash, statedb) } + +func PluginSetTrieFlushIntervalClone(pl *plugins.PluginLoader, flushInterval time.Duration) time.Duration { + fnList := pl.Lookup("SetTrieFlushIntervalClone", func(item interface{}) bool{ + _, ok := item.(func(time.Duration) time.Duration) + return ok + }) + for _, fni := range fnList { + log.Error("len fn list", "len", len(fnList)) + if fn, ok := fni.(func(time.Duration) time.Duration); ok { + return fn(flushInterval) + } + } + return flushInterval +} + +func pluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting setTreiFlushIntervalClone, but default PluginLoader has not been initialized") + } + return PluginSetTrieFlushIntervalClone(plugins.DefaultPluginLoader, flushInterval) +} \ No newline at end of file