From b3e7b8b1c7988a85c61c3c13d7c198cac004c6c7 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 20 May 2025 11:04:17 -0300 Subject: [PATCH 1/3] Adds function that returns time before trie is flushed to disk --- core/blockchain.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 361b1c2cd4..cbdda4262c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1555,6 +1555,11 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { return nil } +func (bc *BlockChain) TimeBeforeFlush() time.Duration { + flushInterval := time.Duration(bc.flushInterval.Load()) + return flushInterval - (bc.gcproc + bc.gcprocRandOffset) +} + // writeBlockWithState writes block, metadata and corresponding state data to the // database. func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, statedb *state.StateDB) error { From 7b15b183dac512d3875f4a29aeb9c5eaa9051867 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Tue, 20 May 2025 19:42:45 -0300 Subject: [PATCH 2/3] Locks chaimu in TimeBeforeFlush --- core/blockchain.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index cbdda4262c..4d902dacbf 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1555,9 +1555,14 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { return nil } -func (bc *BlockChain) TimeBeforeFlush() time.Duration { +func (bc *BlockChain) TimeBeforeFlush() (time.Duration, error) { + if !bc.chainmu.TryLock() { + return 0, errChainStopped + } + defer bc.chainmu.Unlock() + flushInterval := time.Duration(bc.flushInterval.Load()) - return flushInterval - (bc.gcproc + bc.gcprocRandOffset) + return flushInterval - (bc.gcproc + bc.gcprocRandOffset), nil } // writeBlockWithState writes block, metadata and corresponding state data to the From e52a0fbedb67b2504204bdd09a80f9da6eda80f7 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Thu, 22 May 2025 10:08:06 -0300 Subject: [PATCH 3/3] Renames TimeBeforeFlush to ProcTimeBeforeFlush --- core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index 4d902dacbf..d06d70909e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1555,7 +1555,7 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { return nil } -func (bc *BlockChain) TimeBeforeFlush() (time.Duration, error) { +func (bc *BlockChain) ProcTimeBeforeFlush() (time.Duration, error) { if !bc.chainmu.TryLock() { return 0, errChainStopped }