diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 7b2b45064..c140ec561 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -674,6 +674,12 @@ func (bc *Blockchain) storeBlock(block *block.Block) error { } bc.contracts.Policy.OnPersistEnd(bc.dao) bc.dao.MPT.Flush() + // Every persist cycle we also compact our in-memory MPT. + persistedHeight := atomic.LoadUint32(&bc.persistedHeight) + if persistedHeight == block.Index-1 { + // 10 is good and roughly estimated to fit remaining trie into 1M of memory. + bc.dao.MPT.Collapse(10) + } bc.topBlock.Store(block) atomic.StoreUint32(&bc.blockHeight, block.Index) bc.memPool.RemoveStale(bc.isTxStillRelevant, bc)