From 9e40481a517e14ae8a6c225f2b476badb4273415 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Sat, 20 May 2023 21:50:50 +0800 Subject: [PATCH 1/3] core,eth: add api debug_getTrieFlushInterval Signed-off-by: jsvisa --- core/blockchain.go | 5 +++++ eth/api_debug.go | 6 ++++++ internal/web3ext/web3ext.go | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index c1d15350fd2f..c9b80bc2fffb 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 fbc48e349651..8e5a96e47a2b 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -403,3 +403,9 @@ func (api *DebugAPI) SetTrieFlushInterval(interval string) error { api.eth.blockchain.SetTrieFlushInterval(t) return nil } + +// GetTrieFlushInterval gets the current value of in-memroy tries flush interval +func (api *DebugAPI) GetTrieFlushInterval() string { + interval := api.eth.blockchain.GetTrieFlushInterval() + return interval.String() +} diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index a2fc3b5a9040..27159cb0d3ff 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: [] }); From 2709a71efb32a838bdc15a3541a153ceda9a818f Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 30 May 2023 10:34:39 +0800 Subject: [PATCH 2/3] eth/api_debug: comment of SetTrieFlushInterval Signed-off-by: jsvisa --- eth/api_debug.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eth/api_debug.go b/eth/api_debug.go index 8e5a96e47a2b..82a2abd3e52f 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -395,6 +395,9 @@ 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. +// Its behavior is the same as that of an archive node, so please use it with caution. func (api *DebugAPI) SetTrieFlushInterval(interval string) error { t, err := time.ParseDuration(interval) if err != nil { @@ -406,6 +409,5 @@ func (api *DebugAPI) SetTrieFlushInterval(interval string) error { // GetTrieFlushInterval gets the current value of in-memroy tries flush interval func (api *DebugAPI) GetTrieFlushInterval() string { - interval := api.eth.blockchain.GetTrieFlushInterval() - return interval.String() + return api.eth.blockchain.GetTrieFlushInterval().String() } From 162b0dd55a4b9c910b6a85087854fb11e57f616e Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 30 May 2023 04:42:59 -0400 Subject: [PATCH 3/3] Apply suggestions from code review --- eth/api_debug.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eth/api_debug.go b/eth/api_debug.go index 82a2abd3e52f..e5ad24ae1c63 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -396,8 +396,7 @@ 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. -// Its behavior is the same as that of an archive node, so please use it with caution. +// 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 { @@ -407,7 +406,7 @@ func (api *DebugAPI) SetTrieFlushInterval(interval string) error { return nil } -// GetTrieFlushInterval gets the current value of in-memroy tries flush interval +// GetTrieFlushInterval gets the current value of in-memory trie flush interval func (api *DebugAPI) GetTrieFlushInterval() string { return api.eth.blockchain.GetTrieFlushInterval().String() }