Skip to content

Commit 95c4740

Browse files
committed
getblockstats: Consider ct_fee as tx fee if available
Otherwise fall back to subtraction (mainly basecoin-to-basecoin) or skipping.
1 parent 17980aa commit 95c4740

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/rpc/blockchain.cpp

+36-28
Original file line numberDiff line numberDiff line change
@@ -2076,10 +2076,6 @@ static UniValue getblockstats(const JSONRPCRequest& request)
20762076
if (tx->IsCoinStake()) {
20772077
continue;
20782078
}
2079-
if (tx->vin[0].IsAnonInput()) {
2080-
// Can't really do much with a ringCT transaction
2081-
continue;
2082-
}
20832079

20842080
inputs += tx->vin.size(); // Don't count coinbase's fake input
20852081
total_out += tx_total_out; // Don't count coinbase reward
@@ -2110,34 +2106,46 @@ static UniValue getblockstats(const JSONRPCRequest& request)
21102106

21112107
if (loop_inputs) {
21122108

2113-
if (!g_txindex) {
2114-
throw JSONRPCError(RPC_INVALID_PARAMETER, "One or more of the selected stats requires -txindex enabled");
2115-
}
2116-
CAmount tx_total_in = 0;
2117-
for (const CTxIn& in : tx->vin) {
2118-
if (!in.IsZerocoinSpend()) {
2119-
CTransactionRef tx_in;
2120-
uint256 hashBlock;
2121-
if (!GetTransaction(in.prevout.hash, tx_in, Params().GetConsensus(), hashBlock, false)) {
2122-
throw JSONRPCError(RPC_INTERNAL_ERROR, std::string("Unexpected internal error (tx index seems corrupt)"));
2109+
CAmount txfee;
2110+
if (tx->vin[0].IsAnonInput()) {
2111+
if (!tx->GetCTFee(txfee)) {
2112+
// Can't really do much with a ringCT transaction with no fee
2113+
continue;
2114+
}
2115+
} else {
2116+
if (!g_txindex) {
2117+
throw JSONRPCError(RPC_INVALID_PARAMETER, "One or more of the selected stats requires -txindex enabled");
2118+
}
2119+
// Total up the utxo_size_inc even if we have a ct_fee
2120+
CAmount tx_total_in = 0;
2121+
for (const CTxIn& in : tx->vin) {
2122+
if (!in.IsZerocoinSpend()) {
2123+
CTransactionRef tx_in;
2124+
uint256 hashBlock;
2125+
if (!GetTransaction(in.prevout.hash, tx_in, Params().GetConsensus(), hashBlock, false)) {
2126+
throw JSONRPCError(RPC_INTERNAL_ERROR, std::string("Unexpected internal error (tx index seems corrupt)"));
2127+
}
2128+
2129+
auto prevoutput = tx_in->vpout[in.prevout.n];
2130+
2131+
tx_total_in += prevoutput->GetValue();
2132+
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
2133+
ss << *prevoutput.get();
2134+
utxo_size_inc -= ss.size() + PER_UTXO_OVERHEAD;
2135+
} else {
2136+
tx_total_in += in.GetZerocoinSpent();
2137+
}
2138+
}
2139+
// Prefer the ct_fee over the difference
2140+
if (!tx->GetCTFee(txfee)) {
2141+
txfee = tx_total_in - tx_total_out;
2142+
if (tx_total_in < tx_total_out) {
2143+
// RingCT with hidden inputs, can't count it
2144+
continue;
21232145
}
2124-
2125-
auto prevoutput = tx_in->vpout[in.prevout.n];
2126-
2127-
tx_total_in += prevoutput->GetValue();
2128-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
2129-
ss << *prevoutput.get();
2130-
utxo_size_inc -= ss.size() + PER_UTXO_OVERHEAD;
2131-
} else {
2132-
tx_total_in += in.GetZerocoinSpent();
21332146
}
21342147
}
21352148

2136-
CAmount txfee = tx_total_in - tx_total_out;
2137-
if (tx_total_in < tx_total_out) {
2138-
// RingCT with hidden inputs, can't count it
2139-
continue;
2140-
}
21412149
assert(MoneyRange(txfee));
21422150
if (do_medianfee) {
21432151
fee_array.push_back(txfee);

0 commit comments

Comments
 (0)