You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge PIVX-Project#1878: [Core][RPC][BUG] Use sum of utxo values as money supply
dcc032c [Cleanup] Remove ZC_WrappedSerialsSupply no longer needed (random-zebra)
0e7921e [DB] Also prune invalid/fraudulent/frozen outputs from the coins view (random-zebra)
b8647bd [Tests] Fix expected PIV supply in mining_pos_reorg (random-zebra)
40b7ea3 [DB] Prune zerocoin mints from coins DB at startup (random-zebra)
b89bb91 [BUG] Don't try to spend zc mint coins from the cache in DisconnectBlock (random-zebra)
cfc06ed [Core] Don't add zerocoin mints to the coins cache (random-zebra)
e8a782c [Cleanup] Remove unused function GetInvalidUTXOValue (random-zebra)
db7d8fd [Core] Remove nMoneySupply global and RecalculatePIVSupply function (random-zebra)
b674fde [DB] Remove money supply databasing (random-zebra)
373ee90 [Cleanup] Remove --reindexmoneysupply startup flag (random-zebra)
02c9aaa [RPC] Return total available utxo value as moneysupply (random-zebra)
cdf9bc1 [Core] Implement CCoinsViewCache::GetTotalAmount (random-zebra)
Pull request description:
Instead of updating and databasing independently `nMoneySupply`, just use the sum of all unspent tx outputs, returned by the coins cache.
This has the following advantages:
- Cleaner code: we don't need to add special cases for exceptional one-time events, such as wrapped serials, accumulator recalculation, etc.
- More robust: with the old code, `nMoneySupply` is databased at every block and does not follow the chainstate flushing strategy, so it's very easy to get an inconsistent state (see PIVX-Project#1873).
Even more so, considering the absence of any consistency check between the actual chain height and the height at which the supply was updated.
- More accurate number: this returns only the __spendable__ supply, so it excludes all unspendable outputs (OP_RETURN), such as proposals / finalized budgets collaterals, that were originally counted in.
Those outputs, in fact, are effectively "burnt" coins and should not be part of the total supply calculation.
Disadvantage:
- Calculating the supply from the coins DB is a bit slow, but the only place where this is done is in the RPC `getinfo`.
This PR removes the global variable `nMoneySupply` and all related code (ClosesPIVX-Project#1873) and gets rid of the startup flag `--reindexmoneysupply` no longer needed (PIVX-Project#1864 introduces `reindex-chainstate`).
⚠️ This also fixes the following bug with zerocoin txes:
Currently, on master, `gettxoutsetinfo` reports a total amount of about **811 million PIV**!
This is due to improper handling of zerocoin-related "utxos".
Basically mints are added to the coins cache (`AddCoin` only skips OP_RETURN coins, not mints) and *never* pruned/spent (as they are skipped inside `UpdateCoins`), except in `DisconnectBlock`.
Here we completely remove zerocoin mint outputs from the coins DB.
This makes sense, as originally they were not meant to be linked when spending, so should have been considered unspendable outputs, and not included in the first place. With the introduction of Public Spends, mint outputs are now referenced when spending, but we don't need to keep them in the cache either, as double spending is checked only via the zerocoin serial (and, as said, the coins aren't even spent in `UpdateCoins`).
We also remove all those utxos flagged as invalid.
Removing zerocoin mints from the unspent coins DB also gives a nice reduction to the utxoset size on disk (about 37%, from 428 Mb to 270 Mb).
ACKs for top commit:
Fuzzbawls:
ACK dcc032c
Tree-SHA512: da50dd81b9e3a56291812cf35158e1858f5a0c6ebdf1e5018d1e1d20b834dbdccdaa4cb0d82830c6f0a405c71428355615fd57f582065b992d42fa9a7313235e
strUsage += HelpMessageOpt("-reindex", _("Rebuild block chain index from current blk000??.dat files") + "" + _("on startup"));
421
-
strUsage += HelpMessageOpt("-reindexmoneysupply", strprintf(_("Reindex the %s and z%s money supply statistics"), CURRENCY_UNIT, CURRENCY_UNIT) + "" + _("on startup"));
422
421
strUsage += HelpMessageOpt("-resync", _("Delete blockchain folders and resync from scratch") + "" + _("on startup"));
423
422
#if !defined(WIN32)
424
423
strUsage += HelpMessageOpt("-sysperms", _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)"));
0 commit comments