Skip to content

Commit fb65dde

Browse files
committed
scripted-diff: Fix coinstats data member names
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_total_unspendable_amount' s 'm_block_prevout_spent_amount' 'm_total_prevout_spent_amount' s 'm_block_new_outputs_ex_coinbase_amount' 'm_total_new_outputs_ex_coinbase_amount' s 'm_block_coinbase_amount' 'm_total_coinbase_amount' s 'block_unspendable_amount' 'total_unspendable_amount' s 'block_prevout_spent_amount' 'total_prevout_spent_amount' s 'block_new_outputs_ex_coinbase_amount' 'total_new_outputs_ex_coinbase_amount' s 'block_coinbase_amount' 'total_coinbase_amount' s 'unspendables_genesis_block' 'total_unspendables_genesis_block' s 'unspendables_bip30' 'total_unspendables_bip30' s 'unspendables_scripts' 'total_unspendables_scripts' s 'unspendables_unclaimed_rewards' 'total_unspendables_unclaimed_rewards' s 'm_unspendables_genesis_block' 'm_total_unspendables_genesis_block' s 'm_unspendables_bip30' 'm_total_unspendables_bip30' s 'm_unspendables_scripts' 'm_total_unspendables_scripts' s 'm_unspendables_unclaimed_rewards' 'm_total_unspendables_unclaimed_rewards' -END VERIFY SCRIPT-
1 parent 8ea8c92 commit fb65dde

File tree

4 files changed

+93
-93
lines changed

4 files changed

+93
-93
lines changed

src/index/coinstatsindex.cpp

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ struct DBVal {
2424
uint64_t bogo_size;
2525
CAmount total_amount;
2626
CAmount total_subsidy;
27-
CAmount block_unspendable_amount;
28-
CAmount block_prevout_spent_amount;
29-
CAmount block_new_outputs_ex_coinbase_amount;
30-
CAmount block_coinbase_amount;
31-
CAmount unspendables_genesis_block;
32-
CAmount unspendables_bip30;
33-
CAmount unspendables_scripts;
34-
CAmount unspendables_unclaimed_rewards;
27+
CAmount total_unspendable_amount;
28+
CAmount total_prevout_spent_amount;
29+
CAmount total_new_outputs_ex_coinbase_amount;
30+
CAmount total_coinbase_amount;
31+
CAmount total_unspendables_genesis_block;
32+
CAmount total_unspendables_bip30;
33+
CAmount total_unspendables_scripts;
34+
CAmount total_unspendables_unclaimed_rewards;
3535

3636
SERIALIZE_METHODS(DBVal, obj)
3737
{
@@ -40,14 +40,14 @@ struct DBVal {
4040
READWRITE(obj.bogo_size);
4141
READWRITE(obj.total_amount);
4242
READWRITE(obj.total_subsidy);
43-
READWRITE(obj.block_unspendable_amount);
44-
READWRITE(obj.block_prevout_spent_amount);
45-
READWRITE(obj.block_new_outputs_ex_coinbase_amount);
46-
READWRITE(obj.block_coinbase_amount);
47-
READWRITE(obj.unspendables_genesis_block);
48-
READWRITE(obj.unspendables_bip30);
49-
READWRITE(obj.unspendables_scripts);
50-
READWRITE(obj.unspendables_unclaimed_rewards);
43+
READWRITE(obj.total_unspendable_amount);
44+
READWRITE(obj.total_prevout_spent_amount);
45+
READWRITE(obj.total_new_outputs_ex_coinbase_amount);
46+
READWRITE(obj.total_coinbase_amount);
47+
READWRITE(obj.total_unspendables_genesis_block);
48+
READWRITE(obj.total_unspendables_bip30);
49+
READWRITE(obj.total_unspendables_scripts);
50+
READWRITE(obj.total_unspendables_unclaimed_rewards);
5151
}
5252
};
5353

@@ -138,8 +138,8 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
138138

139139
// Skip duplicate txid coinbase transactions (BIP30).
140140
if (is_bip30_block && tx->IsCoinBase()) {
141-
m_block_unspendable_amount += block_subsidy;
142-
m_unspendables_bip30 += block_subsidy;
141+
m_total_unspendable_amount += block_subsidy;
142+
m_total_unspendables_bip30 += block_subsidy;
143143
continue;
144144
}
145145

@@ -150,17 +150,17 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
150150

151151
// Skip unspendable coins
152152
if (coin.out.scriptPubKey.IsUnspendable()) {
153-
m_block_unspendable_amount += coin.out.nValue;
154-
m_unspendables_scripts += coin.out.nValue;
153+
m_total_unspendable_amount += coin.out.nValue;
154+
m_total_unspendables_scripts += coin.out.nValue;
155155
continue;
156156
}
157157

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

160160
if (tx->IsCoinBase()) {
161-
m_block_coinbase_amount += coin.out.nValue;
161+
m_total_coinbase_amount += coin.out.nValue;
162162
} else {
163-
m_block_new_outputs_ex_coinbase_amount += coin.out.nValue;
163+
m_total_new_outputs_ex_coinbase_amount += coin.out.nValue;
164164
}
165165

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

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

181-
m_block_prevout_spent_amount += coin.out.nValue;
181+
m_total_prevout_spent_amount += coin.out.nValue;
182182

183183
--m_transaction_output_count;
184184
m_total_amount -= coin.out.nValue;
@@ -188,32 +188,32 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
188188
}
189189
} else {
190190
// genesis block
191-
m_block_unspendable_amount += block_subsidy;
192-
m_unspendables_genesis_block += block_subsidy;
191+
m_total_unspendable_amount += block_subsidy;
192+
m_total_unspendables_genesis_block += block_subsidy;
193193
}
194194

195195
// If spent prevouts + block subsidy are still a higher amount than
196196
// new outputs + coinbase + current unspendable amount this means
197197
// the miner did not claim the full block reward. Unclaimed block
198198
// rewards are also unspendable.
199-
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)};
200-
m_block_unspendable_amount += unclaimed_rewards;
201-
m_unspendables_unclaimed_rewards += unclaimed_rewards;
199+
const CAmount unclaimed_rewards{(m_total_prevout_spent_amount + m_total_subsidy) - (m_total_new_outputs_ex_coinbase_amount + m_total_coinbase_amount + m_total_unspendable_amount)};
200+
m_total_unspendable_amount += unclaimed_rewards;
201+
m_total_unspendables_unclaimed_rewards += unclaimed_rewards;
202202

203203
std::pair<uint256, DBVal> value;
204204
value.first = pindex->GetBlockHash();
205205
value.second.transaction_output_count = m_transaction_output_count;
206206
value.second.bogo_size = m_bogo_size;
207207
value.second.total_amount = m_total_amount;
208208
value.second.total_subsidy = m_total_subsidy;
209-
value.second.block_unspendable_amount = m_block_unspendable_amount;
210-
value.second.block_prevout_spent_amount = m_block_prevout_spent_amount;
211-
value.second.block_new_outputs_ex_coinbase_amount = m_block_new_outputs_ex_coinbase_amount;
212-
value.second.block_coinbase_amount = m_block_coinbase_amount;
213-
value.second.unspendables_genesis_block = m_unspendables_genesis_block;
214-
value.second.unspendables_bip30 = m_unspendables_bip30;
215-
value.second.unspendables_scripts = m_unspendables_scripts;
216-
value.second.unspendables_unclaimed_rewards = m_unspendables_unclaimed_rewards;
209+
value.second.total_unspendable_amount = m_total_unspendable_amount;
210+
value.second.total_prevout_spent_amount = m_total_prevout_spent_amount;
211+
value.second.total_new_outputs_ex_coinbase_amount = m_total_new_outputs_ex_coinbase_amount;
212+
value.second.total_coinbase_amount = m_total_coinbase_amount;
213+
value.second.total_unspendables_genesis_block = m_total_unspendables_genesis_block;
214+
value.second.total_unspendables_bip30 = m_total_unspendables_bip30;
215+
value.second.total_unspendables_scripts = m_total_unspendables_scripts;
216+
value.second.total_unspendables_unclaimed_rewards = m_total_unspendables_unclaimed_rewards;
217217

218218
uint256 out;
219219
m_muhash.Finalize(out);
@@ -317,14 +317,14 @@ bool CoinStatsIndex::LookUpStats(const CBlockIndex* block_index, CCoinsStats& co
317317
coins_stats.nBogoSize = entry.bogo_size;
318318
coins_stats.nTotalAmount = entry.total_amount;
319319
coins_stats.total_subsidy = entry.total_subsidy;
320-
coins_stats.block_unspendable_amount = entry.block_unspendable_amount;
321-
coins_stats.block_prevout_spent_amount = entry.block_prevout_spent_amount;
322-
coins_stats.block_new_outputs_ex_coinbase_amount = entry.block_new_outputs_ex_coinbase_amount;
323-
coins_stats.block_coinbase_amount = entry.block_coinbase_amount;
324-
coins_stats.unspendables_genesis_block = entry.unspendables_genesis_block;
325-
coins_stats.unspendables_bip30 = entry.unspendables_bip30;
326-
coins_stats.unspendables_scripts = entry.unspendables_scripts;
327-
coins_stats.unspendables_unclaimed_rewards = entry.unspendables_unclaimed_rewards;
320+
coins_stats.total_unspendable_amount = entry.total_unspendable_amount;
321+
coins_stats.total_prevout_spent_amount = entry.total_prevout_spent_amount;
322+
coins_stats.total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
323+
coins_stats.total_coinbase_amount = entry.total_coinbase_amount;
324+
coins_stats.total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
325+
coins_stats.total_unspendables_bip30 = entry.total_unspendables_bip30;
326+
coins_stats.total_unspendables_scripts = entry.total_unspendables_scripts;
327+
coins_stats.total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
328328

329329
return true;
330330
}
@@ -354,14 +354,14 @@ bool CoinStatsIndex::Init()
354354
m_bogo_size = entry.bogo_size;
355355
m_total_amount = entry.total_amount;
356356
m_total_subsidy = entry.total_subsidy;
357-
m_block_unspendable_amount = entry.block_unspendable_amount;
358-
m_block_prevout_spent_amount = entry.block_prevout_spent_amount;
359-
m_block_new_outputs_ex_coinbase_amount = entry.block_new_outputs_ex_coinbase_amount;
360-
m_block_coinbase_amount = entry.block_coinbase_amount;
361-
m_unspendables_genesis_block = entry.unspendables_genesis_block;
362-
m_unspendables_bip30 = entry.unspendables_bip30;
363-
m_unspendables_scripts = entry.unspendables_scripts;
364-
m_unspendables_unclaimed_rewards = entry.unspendables_unclaimed_rewards;
357+
m_total_unspendable_amount = entry.total_unspendable_amount;
358+
m_total_prevout_spent_amount = entry.total_prevout_spent_amount;
359+
m_total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
360+
m_total_coinbase_amount = entry.total_coinbase_amount;
361+
m_total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
362+
m_total_unspendables_bip30 = entry.total_unspendables_bip30;
363+
m_total_unspendables_scripts = entry.total_unspendables_scripts;
364+
m_total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
365365
}
366366

367367
return true;
@@ -409,17 +409,17 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
409409

410410
// Skip unspendable coins
411411
if (coin.out.scriptPubKey.IsUnspendable()) {
412-
m_block_unspendable_amount -= coin.out.nValue;
413-
m_unspendables_scripts -= coin.out.nValue;
412+
m_total_unspendable_amount -= coin.out.nValue;
413+
m_total_unspendables_scripts -= coin.out.nValue;
414414
continue;
415415
}
416416

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

419419
if (tx->IsCoinBase()) {
420-
m_block_coinbase_amount -= coin.out.nValue;
420+
m_total_coinbase_amount -= coin.out.nValue;
421421
} else {
422-
m_block_new_outputs_ex_coinbase_amount -= coin.out.nValue;
422+
m_total_new_outputs_ex_coinbase_amount -= coin.out.nValue;
423423
}
424424

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

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

440-
m_block_prevout_spent_amount -= coin.out.nValue;
440+
m_total_prevout_spent_amount -= coin.out.nValue;
441441

442442
m_transaction_output_count++;
443443
m_total_amount += coin.out.nValue;
@@ -446,9 +446,9 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
446446
}
447447
}
448448

449-
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)};
450-
m_block_unspendable_amount -= unclaimed_rewards;
451-
m_unspendables_unclaimed_rewards -= unclaimed_rewards;
449+
const CAmount unclaimed_rewards{(m_total_new_outputs_ex_coinbase_amount + m_total_coinbase_amount + m_total_unspendable_amount) - (m_total_prevout_spent_amount + m_total_subsidy)};
450+
m_total_unspendable_amount -= unclaimed_rewards;
451+
m_total_unspendables_unclaimed_rewards -= unclaimed_rewards;
452452

453453
// Check that the rolled back internal values are consistent with the DB read out
454454
uint256 out;
@@ -459,14 +459,14 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
459459
Assert(m_total_amount == read_out.second.total_amount);
460460
Assert(m_bogo_size == read_out.second.bogo_size);
461461
Assert(m_total_subsidy == read_out.second.total_subsidy);
462-
Assert(m_block_unspendable_amount == read_out.second.block_unspendable_amount);
463-
Assert(m_block_prevout_spent_amount == read_out.second.block_prevout_spent_amount);
464-
Assert(m_block_new_outputs_ex_coinbase_amount == read_out.second.block_new_outputs_ex_coinbase_amount);
465-
Assert(m_block_coinbase_amount == read_out.second.block_coinbase_amount);
466-
Assert(m_unspendables_genesis_block == read_out.second.unspendables_genesis_block);
467-
Assert(m_unspendables_bip30 == read_out.second.unspendables_bip30);
468-
Assert(m_unspendables_scripts == read_out.second.unspendables_scripts);
469-
Assert(m_unspendables_unclaimed_rewards == read_out.second.unspendables_unclaimed_rewards);
462+
Assert(m_total_unspendable_amount == read_out.second.total_unspendable_amount);
463+
Assert(m_total_prevout_spent_amount == read_out.second.total_prevout_spent_amount);
464+
Assert(m_total_new_outputs_ex_coinbase_amount == read_out.second.total_new_outputs_ex_coinbase_amount);
465+
Assert(m_total_coinbase_amount == read_out.second.total_coinbase_amount);
466+
Assert(m_total_unspendables_genesis_block == read_out.second.total_unspendables_genesis_block);
467+
Assert(m_total_unspendables_bip30 == read_out.second.total_unspendables_bip30);
468+
Assert(m_total_unspendables_scripts == read_out.second.total_unspendables_scripts);
469+
Assert(m_total_unspendables_unclaimed_rewards == read_out.second.total_unspendables_unclaimed_rewards);
470470

471471
return m_db->Write(DB_MUHASH, m_muhash);
472472
}

src/index/coinstatsindex.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class CoinStatsIndex final : public BaseIndex
2525
uint64_t m_bogo_size{0};
2626
CAmount m_total_amount{0};
2727
CAmount m_total_subsidy{0};
28-
CAmount m_block_unspendable_amount{0};
29-
CAmount m_block_prevout_spent_amount{0};
30-
CAmount m_block_new_outputs_ex_coinbase_amount{0};
31-
CAmount m_block_coinbase_amount{0};
32-
CAmount m_unspendables_genesis_block{0};
33-
CAmount m_unspendables_bip30{0};
34-
CAmount m_unspendables_scripts{0};
35-
CAmount m_unspendables_unclaimed_rewards{0};
28+
CAmount m_total_unspendable_amount{0};
29+
CAmount m_total_prevout_spent_amount{0};
30+
CAmount m_total_new_outputs_ex_coinbase_amount{0};
31+
CAmount m_total_coinbase_amount{0};
32+
CAmount m_total_unspendables_genesis_block{0};
33+
CAmount m_total_unspendables_bip30{0};
34+
CAmount m_total_unspendables_scripts{0};
35+
CAmount m_total_unspendables_unclaimed_rewards{0};
3636

3737
bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex);
3838

src/node/coinstats.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ struct CCoinsStats
4646

4747
// Following values are only available from coinstats index
4848
CAmount total_subsidy{0};
49-
CAmount block_unspendable_amount{0};
50-
CAmount block_prevout_spent_amount{0};
51-
CAmount block_new_outputs_ex_coinbase_amount{0};
52-
CAmount block_coinbase_amount{0};
53-
CAmount unspendables_genesis_block{0};
54-
CAmount unspendables_bip30{0};
55-
CAmount unspendables_scripts{0};
56-
CAmount unspendables_unclaimed_rewards{0};
49+
CAmount total_unspendable_amount{0};
50+
CAmount total_prevout_spent_amount{0};
51+
CAmount total_new_outputs_ex_coinbase_amount{0};
52+
CAmount total_coinbase_amount{0};
53+
CAmount total_unspendables_genesis_block{0};
54+
CAmount total_unspendables_bip30{0};
55+
CAmount total_unspendables_scripts{0};
56+
CAmount total_unspendables_unclaimed_rewards{0};
5757

5858
CCoinsStats(CoinStatsHashType hash_type) : m_hash_type(hash_type) {}
5959
};

src/rpc/blockchain.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ static RPCHelpMan gettxoutsetinfo()
11911191
ret.pushKV("transactions", static_cast<int64_t>(stats.nTransactions));
11921192
ret.pushKV("disk_size", stats.nDiskSize);
11931193
} else {
1194-
ret.pushKV("total_unspendable_amount", ValueFromAmount(stats.block_unspendable_amount));
1194+
ret.pushKV("total_unspendable_amount", ValueFromAmount(stats.total_unspendable_amount));
11951195

11961196
CCoinsStats prev_stats{hash_type};
11971197

@@ -1200,16 +1200,16 @@ static RPCHelpMan gettxoutsetinfo()
12001200
}
12011201

12021202
UniValue block_info(UniValue::VOBJ);
1203-
block_info.pushKV("prevout_spent", ValueFromAmount(stats.block_prevout_spent_amount - prev_stats.block_prevout_spent_amount));
1204-
block_info.pushKV("coinbase", ValueFromAmount(stats.block_coinbase_amount - prev_stats.block_coinbase_amount));
1205-
block_info.pushKV("new_outputs_ex_coinbase", ValueFromAmount(stats.block_new_outputs_ex_coinbase_amount - prev_stats.block_new_outputs_ex_coinbase_amount));
1206-
block_info.pushKV("unspendable", ValueFromAmount(stats.block_unspendable_amount - prev_stats.block_unspendable_amount));
1203+
block_info.pushKV("prevout_spent", ValueFromAmount(stats.total_prevout_spent_amount - prev_stats.total_prevout_spent_amount));
1204+
block_info.pushKV("coinbase", ValueFromAmount(stats.total_coinbase_amount - prev_stats.total_coinbase_amount));
1205+
block_info.pushKV("new_outputs_ex_coinbase", ValueFromAmount(stats.total_new_outputs_ex_coinbase_amount - prev_stats.total_new_outputs_ex_coinbase_amount));
1206+
block_info.pushKV("unspendable", ValueFromAmount(stats.total_unspendable_amount - prev_stats.total_unspendable_amount));
12071207

12081208
UniValue unspendables(UniValue::VOBJ);
1209-
unspendables.pushKV("genesis_block", ValueFromAmount(stats.unspendables_genesis_block - prev_stats.unspendables_genesis_block));
1210-
unspendables.pushKV("bip30", ValueFromAmount(stats.unspendables_bip30 - prev_stats.unspendables_bip30));
1211-
unspendables.pushKV("scripts", ValueFromAmount(stats.unspendables_scripts - prev_stats.unspendables_scripts));
1212-
unspendables.pushKV("unclaimed_rewards", ValueFromAmount(stats.unspendables_unclaimed_rewards - prev_stats.unspendables_unclaimed_rewards));
1209+
unspendables.pushKV("genesis_block", ValueFromAmount(stats.total_unspendables_genesis_block - prev_stats.total_unspendables_genesis_block));
1210+
unspendables.pushKV("bip30", ValueFromAmount(stats.total_unspendables_bip30 - prev_stats.total_unspendables_bip30));
1211+
unspendables.pushKV("scripts", ValueFromAmount(stats.total_unspendables_scripts - prev_stats.total_unspendables_scripts));
1212+
unspendables.pushKV("unclaimed_rewards", ValueFromAmount(stats.total_unspendables_unclaimed_rewards - prev_stats.total_unspendables_unclaimed_rewards));
12131213
block_info.pushKV("unspendables", unspendables);
12141214

12151215
ret.pushKV("block_info", block_info);

0 commit comments

Comments
 (0)