HomePhabricator

[backport#16443 2/3] refactor: have CCoins* data managed under CChainState

Description

[backport#16443 2/3] refactor: have CCoins* data managed under CChainState

Summary:
This change encapsulates UTXO set data within CChainState instances, removing
global data pcoinsTip and pcoinsviewdb. This is necessary if we want to
maintain multiple chainstates with their own rendering of the UTXO set.

We introduce a class CoinsViews which consolidates the construction of a
CCoins* hierarchy. Construction of its various pieces (db, coinscatcher,
in-memory cache) is split up so that we avoid flushing bad state to disk if
startup is interrupted.

We also introduce CChainState::CanFlushToDisk() which tells us when it is
safe to flush the chainstate based on this partial construction.

This commit could be broken into smaller pieces, but it would require more
ephemeral diffs to, e.g., temporarily change CCoinsViewDB's constructor
invocations.

Other changes:

  • A parameter has been added to the CCoinsViewDB constructor that allows the name of the corresponding leveldb directory to be specified.

Thanks to Russell Yanofsky and Marco Falke for helpful feedback.


https://github.com/bitcoin/bitcoin/pull/16443/commits/569353068568444a25b301bbd6513bb510157dc9

Partial backport of Core PR16443

Depends on D7580

Test Plan:

cmake .. -DENABLE_SANITIZERS=address
ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7581

Details

Provenance
James O'Beirne <james.obeirne@gmail.com>Authored on Jul 24 2019, 17:23
majcostaCommitted on Oct 15 2020, 23:57
majcostaPushed on Oct 15 2020, 23:57
Reviewer
Restricted Project
Differential Revision
D7581: [backport#16443 2/3] refactor: have CCoins* data managed under CChainState
Parents
rABC76953e642b2b: [backport#16443 1/3] refactor: pcoinsTip -> CChainState::CoinsTip()
Branches
Unknown
Tags
Unknown