Merge pull request #1885 from nspcc-dev/restore-mpt-collapsing

core: restore MPT collapsing logic
This commit is contained in:
Roman Khimov 2021-04-07 14:29:51 +03:00 committed by GitHub
commit 7360ed4245
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -754,6 +754,13 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
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()
_, err = cache.Persist()