From 0783cb7d91ad7b3cdf72ac6c6edaec8318673eb6 Mon Sep 17 00:00:00 2001 From: Delweng Date: Tue, 6 Jun 2023 20:41:44 +0800 Subject: [PATCH] eth,core: add api debug_getTrieFlushInterval (#27303) * core,eth: add api debug_getTrieFlushInterval Signed-off-by: jsvisa * eth/api_debug: comment of SetTrieFlushInterval Signed-off-by: jsvisa * Apply suggestions from code review --------- Signed-off-by: jsvisa Co-authored-by: Martin Holst Swende --- core/blockchain.go | 5 +++++ eth/api_debug.go | 7 +++++++ internal/web3ext/web3ext.go | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index c1d15350fd..c9b80bc2ff 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2492,3 +2492,8 @@ func (bc *BlockChain) SetBlockValidatorAndProcessorForTesting(v Validator, p Pro func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) { bc.flushInterval.Store(int64(interval)) } + +// GetTrieFlushInterval gets the in-memroy tries flush interval +func (bc *BlockChain) GetTrieFlushInterval() time.Duration { + return time.Duration(bc.flushInterval.Load()) +} diff --git a/eth/api_debug.go b/eth/api_debug.go index 7cf0239174..4dd48508f6 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -406,6 +406,8 @@ func (api *DebugAPI) GetAccessibleState(from, to rpc.BlockNumber) (uint64, error // SetTrieFlushInterval configures how often in-memory tries are persisted // to disk. The value is in terms of block processing time, not wall clock. +// If the value is shorter than the block generation time, or even 0 or negative, +// the node will flush trie after processing each block (effectively archive mode). func (api *DebugAPI) SetTrieFlushInterval(interval string) error { t, err := time.ParseDuration(interval) if err != nil { @@ -414,3 +416,8 @@ func (api *DebugAPI) SetTrieFlushInterval(interval string) error { api.eth.blockchain.SetTrieFlushInterval(t) return nil } + +// GetTrieFlushInterval gets the current value of in-memory trie flush interval +func (api *DebugAPI) GetTrieFlushInterval() string { + return api.eth.blockchain.GetTrieFlushInterval().String() +} diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index ea4abef1f6..c171709586 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -495,6 +495,11 @@ web3._extend({ call: 'debug_setTrieFlushInterval', params: 1 }), + new web3._extend.Method({ + name: 'getTrieFlushInterval', + call: 'debug_getTrieFlushInterval', + params: 0 + }), ], properties: [] });