Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add chain supply, transparent and burned coins value pools #609

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 8)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 2)
define(_CLIENT_VERSION_BUILD, 4)
define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50)))
define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1)))
define(_CLIENT_VERSION_IS_RELEASE, true)
Expand Down
60 changes: 60 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern CCriticalSection cs_main;

static const int SPROUT_VALUE_VERSION = 80102;
static const int SAPLING_VALUE_VERSION = 80102;
static const int TRANSPARENT_VALUE_VERSION = 80103;
static const int BURNED_VALUE_VERSION = 80104;

// These 5 are declared here to avoid circular dependencies
// code used this moved into .cpp
Expand Down Expand Up @@ -193,6 +195,44 @@ class CBlockIndex
//! (memory only) The anchor for the tree state up to the end of this block
uint256 hashFinalSproutRoot;

//! The change to the chain supply caused by this block. This is defined as
//! the value of the coinbase outputs in this block, minus fees not claimed
//! by the miner.
//!
//! Will be boost::none under the following conditions:
//! - if the block has never been connected to a chain tip
//! - for older blocks until a reindex has taken place
boost::optional<CAmount> nChainSupplyDelta;

//! (memory only) Total chain supply up to and including this block.
//!
//! Will be boost::none until a reindex has taken place, if nChainTx is
//! zero, or if the block has never been connected to a chain tip.
boost::optional<CAmount> nChainTotalSupply;

//! Change in value in the transparent pool produced by the action of the
//! transparent inputs to and outputs from transactions in this block.
//!
//! Will be boost::none for older blocks until a reindex has taken place.
boost::optional<CAmount> nTransparentValue;

//! (memory only) Total value of the transparent value pool up to and
//! including this block.
//!
//! Will be boost::none until a reindex has taken place.
//! Will be boost::none if nChainTx is zero.
boost::optional<CAmount> nChainTransparentValue;

// This refers to the number of coins burned in this block,
// essentially making them unspendable (due to the OP_RETURN scripts value).
//!
//! For older blocks, this will be boost::none until a reindexing has occurred.
boost::optional<CAmount> nBurnedAmountDelta;

//! (memory only) Total value of the burned coins up to and
//! including this block.
boost::optional<CAmount> nChainTotalBurned;

//! Change in value held by the Sprout circuit over this block.
//! Will be boost::none for older blocks on old nodes until a reindex has taken place.
boost::optional<CAmount> nSproutValue;
Expand Down Expand Up @@ -249,6 +289,13 @@ class CBlockIndex
hashSproutAnchor = uint256();
hashFinalSproutRoot = uint256();
nSequenceId = 0;

nChainSupplyDelta = boost::none;
nChainTotalSupply = boost::none;
nTransparentValue = boost::none;
nChainTransparentValue = boost::none;
nBurnedAmountDelta = boost::none;
nChainTotalBurned = boost::none;
nSproutValue = boost::none;
nChainSproutValue = boost::none;
nSaplingValue = 0;
Expand Down Expand Up @@ -443,6 +490,19 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nNonce);
READWRITE(nSolution);

// Only read/write nTransparentValue if the client version used to create
// this index was storing them.
if ((s.GetType() & SER_DISK) && (nVersion >= TRANSPARENT_VALUE_VERSION)) {
READWRITE(nChainSupplyDelta);
READWRITE(nTransparentValue);
}

// Only read/write nBurnedAmountDelta if the client version used to create
// this index was storing them.
if ((s.GetType() & SER_DISK) && (nVersion >= BURNED_VALUE_VERSION)) {
READWRITE(nBurnedAmountDelta);
}

// Only read/write nSproutValue if the client version used to create
// this index was storing them.
if ((s.GetType() & SER_DISK) && (nVersion >= SPROUT_VALUE_VERSION)) {
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 8
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_BUILD 4

//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
7 changes: 6 additions & 1 deletion src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const
* @returns Sum of value of all inputs (scriptSigs), (positive valueBalance or zero) and JoinSplit vpub_new
*/
CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t &interestp,const CTransaction& tx) const
{
return GetTransparentValueIn(nHeight, interestp, tx) + tx.GetShieldedValueIn();
}

// TODO: remove this if it ends up unused
CAmount CCoinsViewCache::GetTransparentValueIn(int32_t nHeight,int64_t &interestp,const CTransaction& tx) const
{
CAmount value,nResult = 0;
interestp = 0;
Expand Down Expand Up @@ -617,7 +623,6 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t &interestp,const CTr
}
#endif
}
nResult += tx.GetShieldedValueIn();

return nResult;
}
Expand Down
15 changes: 13 additions & 2 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,22 @@ class CCoinsViewCache : public CCoinsViewBacked
* so may not be able to calculate this.
* @param[in] nHeight the chain height
* @param[out] interestp the interest found
* @param[in] tx transaction for which we are checking input total
* @returns Sum of value of all inputs (scriptSigs), (positive valueBalance or zero) and JoinSplit vpub_new
* @param[in] tx transaction for which we are checking input total
* @return Sum of value of all inputs (scriptSigs), JoinSplit vpub_new, and
* positive values of valueBalanceSapling, and valueBalanceOrchard.
*/
CAmount GetValueIn(int32_t nHeight,int64_t &interestp,const CTransaction& tx) const;

/**
* Amount of coins coming in to a transaction in the transparent inputs.
*
* @param[in] nHeight the chain height
* @param[out] interestp the interest found
* @param[in] tx transaction for which we are checking input total
* @return Sum of value of all inputs (scriptSigs)
*/
CAmount GetTransparentValueIn(int32_t nHeight,int64_t &interestp,const CTransaction& tx) const;

//! Check whether all prevouts of the transaction are present in the UTXO set represented by this view
bool HaveInputs(const CTransaction& tx) const;

Expand Down
Loading
Loading