core: restore MPT collapsing logic

Fix #1867, revert part of bf20db09e0.
This commit is contained in:
Roman Khimov 2021-04-07 11:14:18 +03:00
parent 99ca0b2578
commit 9b15ab48ad

View file

@ -754,6 +754,13 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
writeBuf.Reset() writeBuf.Reset()
} }
} }
// Every persist cycle we also compact our in-memory MPT. It's flushed
// already in AddMPTBatch, so collapsing it is safe.
persistedHeight := atomic.LoadUint32(&bc.persistedHeight)
if persistedHeight == block.Index-1 {
// 10 is good and roughly estimated to fit remaining trie into 1M of memory.
mpt.Collapse(10)
}
bc.lock.Lock() bc.lock.Lock()
_, err = cache.Persist() _, err = cache.Persist()