From 40bf10e04d4113db54fa40606cc80c668f88cf19 Mon Sep 17 00:00:00 2001 From: web3-developer <51288821+web3-developer@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:10:14 +0800 Subject: [PATCH] Revert previous fix and force clear cache after processing each block. --- nimbus/core/executor/process_block.nim | 2 +- nimbus/db/ledger/accounts_cache.nim | 5 ++++- nimbus/db/ledger/accounts_ledger.nim | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nimbus/core/executor/process_block.nim b/nimbus/core/executor/process_block.nim index d175f6534f..3433cffaad 100644 --- a/nimbus/core/executor/process_block.nim +++ b/nimbus/core/executor/process_block.nim @@ -117,7 +117,7 @@ proc procBlkEpilogue(vmState: BaseVMState; if vmState.generateWitness: db.collectWitnessData() let clearEmptyAccount = vmState.determineFork >= FkSpurious - db.persist(clearEmptyAccount, ClearCache in vmState.flags) + db.persist(clearEmptyAccount, clearCache = true) let stateDb = vmState.stateDB if header.stateRoot != stateDb.rootHash: diff --git a/nimbus/db/ledger/accounts_cache.nim b/nimbus/db/ledger/accounts_cache.nim index 02e0f2c9bd..baeca19daa 100644 --- a/nimbus/db/ledger/accounts_cache.nim +++ b/nimbus/db/ledger/accounts_cache.nim @@ -596,7 +596,6 @@ proc persist*(ac: AccountsCache, if clearCache: ac.savePoint.cache.clear() - ac.witnessCache.clear() else: for x in cleanAccounts: ac.savePoint.cache.del x @@ -695,6 +694,10 @@ proc makeMultiKeys*(ac: AccountsCache): MultiKeysRef = result.add(k, v.codeTouched, multiKeys(v.storageKeys)) result.sort() + # reset the witness cache after collecting the witness data + # so it is clean before executing the next block + ac.witnessCache.clear() + proc accessList*(ac: AccountsCache, address: EthAddress) {.inline.} = ac.savePoint.accessList.add(address) diff --git a/nimbus/db/ledger/accounts_ledger.nim b/nimbus/db/ledger/accounts_ledger.nim index a469327f1c..25cabdacb5 100644 --- a/nimbus/db/ledger/accounts_ledger.nim +++ b/nimbus/db/ledger/accounts_ledger.nim @@ -627,7 +627,6 @@ proc persist*(ac: AccountsLedgerRef, if clearCache: ac.savePoint.cache.clear() - ac.witnessCache.clear() else: for x in cleanAccounts: ac.savePoint.cache.del x