dtr-org / unit-e

A digital currency for a new era of decentralized trust
https://unit-e.io
MIT License
45 stars 15 forks source link

unit-e consumes too much memory on reindex #1096

Closed cmihai closed 5 years ago

cmihai commented 5 years ago

When starting the node with unit-e -reindex, the client eats up all the RAM and is killed by the OOM killer.

This happens because unit-e first reads the entire blockchain and constructs the FinalizationState objects for all of them, and only as a last step calls ActivateBestChain, which trims the FinalizationStates for the finalized blocks:

ThreadImport
+-> LoadExternalBlockFile
    +-> CChainState::AcceptBlock
        +-> CChainState::ReceivedBlockTransactions
            +-> CChainState::ProcessFinalizationState
                +-> ProcessorImpl::ProcessNewTipCandidate
                    +-> ProcessorImpl::ProcessNewTipWorker
                        +-> FindOrCreate
+-> ActivateBestChain

To mitigate the issue, we could call ActivateBestChain during the import process, every X blocks, where X is a multiple of the epoch length.

See also #1073.