From c389c6beacf66b6b455b28a5e5f8e703a13363c5 Mon Sep 17 00:00:00 2001 From: Max Revitt Date: Thu, 16 May 2024 08:43:07 +0100 Subject: [PATCH] tweak(plainstate): add close func to close cursors (#10368) If repeatedly using the plainstate in an iteration you can end up with so many cursors that tx.Rollback/Commit takes a very long time. The fix is to clean up the cursors as you go with Close() on the plainstate. --- core/state/plain_readonly.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/state/plain_readonly.go b/core/state/plain_readonly.go index b002ae61197..3b74ef47c11 100644 --- a/core/state/plain_readonly.go +++ b/core/state/plain_readonly.go @@ -76,6 +76,13 @@ func NewPlainState(tx kv.Tx, blockNr uint64, systemContractLookup map[libcommon. return ps } +func (s *PlainState) Close() { + s.accHistoryC.Close() + s.storageHistoryC.Close() + s.accChangesC.Close() + s.accHistoryC.Close() +} + func (s *PlainState) SetTrace(trace bool) { s.trace = trace }