Skip to content

Commit

Permalink
scripted-diff: Fix coinstats data member names
Browse files Browse the repository at this point in the history
Initially these values were 'per block' in an earlier version but were then changed to total values. The names were not updated to reflect that.

-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'm_block_unspendable_amount'              'm_unspendable_amount'
s 'm_block_prevout_spent_amount'            'm_prevout_spent_amount'
s 'm_block_new_outputs_ex_coinbase_amount'  'm_new_outputs_ex_coinbase_amount'
s 'm_block_coinbase_amount'                 'm_coinbase_amount'
s 'block_unspendable_amount'                'unspendable_amount'
s 'block_prevout_spent_amount'              'prevout_spent_amount'
s 'block_new_outputs_ex_coinbase_amount'    'new_outputs_ex_coinbase_amount'
s 'block_coinbase_amount'                   'coinbase_amount'
s 'm_total_subsidy'                         'm_subsidy'
s 'total_subsidy'                           'subsidy'
-END VERIFY SCRIPT-
  • Loading branch information
fjahr committed May 25, 2021
1 parent 8ea8c92 commit b778ac8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
92 changes: 46 additions & 46 deletions src/index/coinstatsindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ struct DBVal {
uint64_t transaction_output_count;
uint64_t bogo_size;
CAmount total_amount;
CAmount total_subsidy;
CAmount block_unspendable_amount;
CAmount block_prevout_spent_amount;
CAmount block_new_outputs_ex_coinbase_amount;
CAmount block_coinbase_amount;
CAmount subsidy;
CAmount unspendable_amount;
CAmount prevout_spent_amount;
CAmount new_outputs_ex_coinbase_amount;
CAmount coinbase_amount;
CAmount unspendables_genesis_block;
CAmount unspendables_bip30;
CAmount unspendables_scripts;
Expand All @@ -39,11 +39,11 @@ struct DBVal {
READWRITE(obj.transaction_output_count);
READWRITE(obj.bogo_size);
READWRITE(obj.total_amount);
READWRITE(obj.total_subsidy);
READWRITE(obj.block_unspendable_amount);
READWRITE(obj.block_prevout_spent_amount);
READWRITE(obj.block_new_outputs_ex_coinbase_amount);
READWRITE(obj.block_coinbase_amount);
READWRITE(obj.subsidy);
READWRITE(obj.unspendable_amount);
READWRITE(obj.prevout_spent_amount);
READWRITE(obj.new_outputs_ex_coinbase_amount);
READWRITE(obj.coinbase_amount);
READWRITE(obj.unspendables_genesis_block);
READWRITE(obj.unspendables_bip30);
READWRITE(obj.unspendables_scripts);
Expand Down Expand Up @@ -107,7 +107,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
{
CBlockUndo block_undo;
const CAmount block_subsidy{GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())};
m_total_subsidy += block_subsidy;
m_subsidy += block_subsidy;

// Ignore genesis block
if (pindex->nHeight > 0) {
Expand Down Expand Up @@ -138,7 +138,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)

// Skip duplicate txid coinbase transactions (BIP30).
if (is_bip30_block && tx->IsCoinBase()) {
m_block_unspendable_amount += block_subsidy;
m_unspendable_amount += block_subsidy;
m_unspendables_bip30 += block_subsidy;
continue;
}
Expand All @@ -150,17 +150,17 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)

// Skip unspendable coins
if (coin.out.scriptPubKey.IsUnspendable()) {
m_block_unspendable_amount += coin.out.nValue;
m_unspendable_amount += coin.out.nValue;
m_unspendables_scripts += coin.out.nValue;
continue;
}

m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));

if (tx->IsCoinBase()) {
m_block_coinbase_amount += coin.out.nValue;
m_coinbase_amount += coin.out.nValue;
} else {
m_block_new_outputs_ex_coinbase_amount += coin.out.nValue;
m_new_outputs_ex_coinbase_amount += coin.out.nValue;
}

++m_transaction_output_count;
Expand All @@ -178,7 +178,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)

m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));

m_block_prevout_spent_amount += coin.out.nValue;
m_prevout_spent_amount += coin.out.nValue;

--m_transaction_output_count;
m_total_amount -= coin.out.nValue;
Expand All @@ -188,28 +188,28 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
}
} else {
// genesis block
m_block_unspendable_amount += block_subsidy;
m_unspendable_amount += block_subsidy;
m_unspendables_genesis_block += block_subsidy;
}

// If spent prevouts + block subsidy are still a higher amount than
// new outputs + coinbase + current unspendable amount this means
// the miner did not claim the full block reward. Unclaimed block
// rewards are also unspendable.
const CAmount unclaimed_rewards{(m_block_prevout_spent_amount + m_total_subsidy) - (m_block_new_outputs_ex_coinbase_amount + m_block_coinbase_amount + m_block_unspendable_amount)};
m_block_unspendable_amount += unclaimed_rewards;
const CAmount unclaimed_rewards{(m_prevout_spent_amount + m_subsidy) - (m_new_outputs_ex_coinbase_amount + m_coinbase_amount + m_unspendable_amount)};
m_unspendable_amount += unclaimed_rewards;
m_unspendables_unclaimed_rewards += unclaimed_rewards;

std::pair<uint256, DBVal> value;
value.first = pindex->GetBlockHash();
value.second.transaction_output_count = m_transaction_output_count;
value.second.bogo_size = m_bogo_size;
value.second.total_amount = m_total_amount;
value.second.total_subsidy = m_total_subsidy;
value.second.block_unspendable_amount = m_block_unspendable_amount;
value.second.block_prevout_spent_amount = m_block_prevout_spent_amount;
value.second.block_new_outputs_ex_coinbase_amount = m_block_new_outputs_ex_coinbase_amount;
value.second.block_coinbase_amount = m_block_coinbase_amount;
value.second.subsidy = m_subsidy;
value.second.unspendable_amount = m_unspendable_amount;
value.second.prevout_spent_amount = m_prevout_spent_amount;
value.second.new_outputs_ex_coinbase_amount = m_new_outputs_ex_coinbase_amount;
value.second.coinbase_amount = m_coinbase_amount;
value.second.unspendables_genesis_block = m_unspendables_genesis_block;
value.second.unspendables_bip30 = m_unspendables_bip30;
value.second.unspendables_scripts = m_unspendables_scripts;
Expand Down Expand Up @@ -316,11 +316,11 @@ bool CoinStatsIndex::LookUpStats(const CBlockIndex* block_index, CCoinsStats& co
coins_stats.nTransactionOutputs = entry.transaction_output_count;
coins_stats.nBogoSize = entry.bogo_size;
coins_stats.nTotalAmount = entry.total_amount;
coins_stats.total_subsidy = entry.total_subsidy;
coins_stats.block_unspendable_amount = entry.block_unspendable_amount;
coins_stats.block_prevout_spent_amount = entry.block_prevout_spent_amount;
coins_stats.block_new_outputs_ex_coinbase_amount = entry.block_new_outputs_ex_coinbase_amount;
coins_stats.block_coinbase_amount = entry.block_coinbase_amount;
coins_stats.subsidy = entry.subsidy;
coins_stats.unspendable_amount = entry.unspendable_amount;
coins_stats.prevout_spent_amount = entry.prevout_spent_amount;
coins_stats.new_outputs_ex_coinbase_amount = entry.new_outputs_ex_coinbase_amount;
coins_stats.coinbase_amount = entry.coinbase_amount;
coins_stats.unspendables_genesis_block = entry.unspendables_genesis_block;
coins_stats.unspendables_bip30 = entry.unspendables_bip30;
coins_stats.unspendables_scripts = entry.unspendables_scripts;
Expand Down Expand Up @@ -353,11 +353,11 @@ bool CoinStatsIndex::Init()
m_transaction_output_count = entry.transaction_output_count;
m_bogo_size = entry.bogo_size;
m_total_amount = entry.total_amount;
m_total_subsidy = entry.total_subsidy;
m_block_unspendable_amount = entry.block_unspendable_amount;
m_block_prevout_spent_amount = entry.block_prevout_spent_amount;
m_block_new_outputs_ex_coinbase_amount = entry.block_new_outputs_ex_coinbase_amount;
m_block_coinbase_amount = entry.block_coinbase_amount;
m_subsidy = entry.subsidy;
m_unspendable_amount = entry.unspendable_amount;
m_prevout_spent_amount = entry.prevout_spent_amount;
m_new_outputs_ex_coinbase_amount = entry.new_outputs_ex_coinbase_amount;
m_coinbase_amount = entry.coinbase_amount;
m_unspendables_genesis_block = entry.unspendables_genesis_block;
m_unspendables_bip30 = entry.unspendables_bip30;
m_unspendables_scripts = entry.unspendables_scripts;
Expand All @@ -377,7 +377,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
std::pair<uint256, DBVal> read_out;

const CAmount block_subsidy{GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())};
m_total_subsidy -= block_subsidy;
m_subsidy -= block_subsidy;

// Ignore genesis block
if (pindex->nHeight > 0) {
Expand Down Expand Up @@ -409,17 +409,17 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex

// Skip unspendable coins
if (coin.out.scriptPubKey.IsUnspendable()) {
m_block_unspendable_amount -= coin.out.nValue;
m_unspendable_amount -= coin.out.nValue;
m_unspendables_scripts -= coin.out.nValue;
continue;
}

m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));

if (tx->IsCoinBase()) {
m_block_coinbase_amount -= coin.out.nValue;
m_coinbase_amount -= coin.out.nValue;
} else {
m_block_new_outputs_ex_coinbase_amount -= coin.out.nValue;
m_new_outputs_ex_coinbase_amount -= coin.out.nValue;
}

--m_transaction_output_count;
Expand All @@ -437,7 +437,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex

m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));

m_block_prevout_spent_amount -= coin.out.nValue;
m_prevout_spent_amount -= coin.out.nValue;

m_transaction_output_count++;
m_total_amount += coin.out.nValue;
Expand All @@ -446,8 +446,8 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
}
}

const CAmount unclaimed_rewards{(m_block_new_outputs_ex_coinbase_amount + m_block_coinbase_amount + m_block_unspendable_amount) - (m_block_prevout_spent_amount + m_total_subsidy)};
m_block_unspendable_amount -= unclaimed_rewards;
const CAmount unclaimed_rewards{(m_new_outputs_ex_coinbase_amount + m_coinbase_amount + m_unspendable_amount) - (m_prevout_spent_amount + m_subsidy)};
m_unspendable_amount -= unclaimed_rewards;
m_unspendables_unclaimed_rewards -= unclaimed_rewards;

// Check that the rolled back internal values are consistent with the DB read out
Expand All @@ -458,11 +458,11 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
Assert(m_transaction_output_count == read_out.second.transaction_output_count);
Assert(m_total_amount == read_out.second.total_amount);
Assert(m_bogo_size == read_out.second.bogo_size);
Assert(m_total_subsidy == read_out.second.total_subsidy);
Assert(m_block_unspendable_amount == read_out.second.block_unspendable_amount);
Assert(m_block_prevout_spent_amount == read_out.second.block_prevout_spent_amount);
Assert(m_block_new_outputs_ex_coinbase_amount == read_out.second.block_new_outputs_ex_coinbase_amount);
Assert(m_block_coinbase_amount == read_out.second.block_coinbase_amount);
Assert(m_subsidy == read_out.second.subsidy);
Assert(m_unspendable_amount == read_out.second.unspendable_amount);
Assert(m_prevout_spent_amount == read_out.second.prevout_spent_amount);
Assert(m_new_outputs_ex_coinbase_amount == read_out.second.new_outputs_ex_coinbase_amount);
Assert(m_coinbase_amount == read_out.second.coinbase_amount);
Assert(m_unspendables_genesis_block == read_out.second.unspendables_genesis_block);
Assert(m_unspendables_bip30 == read_out.second.unspendables_bip30);
Assert(m_unspendables_scripts == read_out.second.unspendables_scripts);
Expand Down
10 changes: 5 additions & 5 deletions src/index/coinstatsindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class CoinStatsIndex final : public BaseIndex
uint64_t m_transaction_output_count{0};
uint64_t m_bogo_size{0};
CAmount m_total_amount{0};
CAmount m_total_subsidy{0};
CAmount m_block_unspendable_amount{0};
CAmount m_block_prevout_spent_amount{0};
CAmount m_block_new_outputs_ex_coinbase_amount{0};
CAmount m_block_coinbase_amount{0};
CAmount m_subsidy{0};
CAmount m_unspendable_amount{0};
CAmount m_prevout_spent_amount{0};
CAmount m_new_outputs_ex_coinbase_amount{0};
CAmount m_coinbase_amount{0};
CAmount m_unspendables_genesis_block{0};
CAmount m_unspendables_bip30{0};
CAmount m_unspendables_scripts{0};
Expand Down
10 changes: 5 additions & 5 deletions src/node/coinstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ struct CCoinsStats
bool index_used{false};

// Following values are only available from coinstats index
CAmount total_subsidy{0};
CAmount block_unspendable_amount{0};
CAmount block_prevout_spent_amount{0};
CAmount block_new_outputs_ex_coinbase_amount{0};
CAmount block_coinbase_amount{0};
CAmount subsidy{0};
CAmount unspendable_amount{0};
CAmount prevout_spent_amount{0};
CAmount new_outputs_ex_coinbase_amount{0};
CAmount coinbase_amount{0};
CAmount unspendables_genesis_block{0};
CAmount unspendables_bip30{0};
CAmount unspendables_scripts{0};
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ static RPCHelpMan gettxoutsetinfo()
ret.pushKV("transactions", static_cast<int64_t>(stats.nTransactions));
ret.pushKV("disk_size", stats.nDiskSize);
} else {
ret.pushKV("total_unspendable_amount", ValueFromAmount(stats.block_unspendable_amount));
ret.pushKV("total_unspendable_amount", ValueFromAmount(stats.unspendable_amount));

CCoinsStats prev_stats{hash_type};

Expand All @@ -1200,10 +1200,10 @@ static RPCHelpMan gettxoutsetinfo()
}

UniValue block_info(UniValue::VOBJ);
block_info.pushKV("prevout_spent", ValueFromAmount(stats.block_prevout_spent_amount - prev_stats.block_prevout_spent_amount));
block_info.pushKV("coinbase", ValueFromAmount(stats.block_coinbase_amount - prev_stats.block_coinbase_amount));
block_info.pushKV("new_outputs_ex_coinbase", ValueFromAmount(stats.block_new_outputs_ex_coinbase_amount - prev_stats.block_new_outputs_ex_coinbase_amount));
block_info.pushKV("unspendable", ValueFromAmount(stats.block_unspendable_amount - prev_stats.block_unspendable_amount));
block_info.pushKV("prevout_spent", ValueFromAmount(stats.prevout_spent_amount - prev_stats.prevout_spent_amount));
block_info.pushKV("coinbase", ValueFromAmount(stats.coinbase_amount - prev_stats.coinbase_amount));
block_info.pushKV("new_outputs_ex_coinbase", ValueFromAmount(stats.new_outputs_ex_coinbase_amount - prev_stats.new_outputs_ex_coinbase_amount));
block_info.pushKV("unspendable", ValueFromAmount(stats.unspendable_amount - prev_stats.unspendable_amount));

UniValue unspendables(UniValue::VOBJ);
unspendables.pushKV("genesis_block", ValueFromAmount(stats.unspendables_genesis_block - prev_stats.unspendables_genesis_block));
Expand Down

0 comments on commit b778ac8

Please sign in to comment.