Skip to content

Commit

Permalink
Track many-to-one consolidations
Browse files Browse the repository at this point in the history
getblockstats now counts the number of transactions with at least 3
inputs and exactly one output as "many-to-one" (mto) consolidations.

It also counts the total number of outputs consolidated by mto
transactions per block.

Test changes contributed by Mike Schmidt <[email protected]>.
  • Loading branch information
Marcin Jachymiak authored and jnewbery committed Jul 16, 2019
1 parent 840f2b5 commit 3592649
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 106 deletions.
17 changes: 17 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,8 @@ static UniValue getblockstats(const JSONRPCRequest& request)
" \"txs_batching\": xxxxx, (numeric) The total number batching transactions (defined as at least 3 outputs)\n"
" \"outcount_bins\": xxxxx, (numeric_array) The numbers of transactions that have certain numbers of outputs\n"
" \"dust_bins\": xxxxx, (numeric_array) The total number of outputs that are dust at several fee-rates\n"
" \"mto_consolidations\": xxxxx, (numeric) The total number of transactions with at least 3 inputs and exactly 1 output\n"
" \"mto_output_count\": xxxxx, (numeric) The total number of outputs spent in all mto_consolidation transactions\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getblockstats", "1000 '[\"minfeerate\",\"avgfeerate\"]'")
Expand Down Expand Up @@ -1848,6 +1850,11 @@ static UniValue getblockstats(const JSONRPCRequest& request)
int64_t outputs_consolidated = 0;
int64_t txs_batching = 0;

std::vector<CTxDestination> high_consolidation_addrs;
std::vector<int64_t> cons_in_count;
int64_t many_to_one_consolidating_txs = 0;
int64_t many_to_one_consolidated_outputs = 0;

// Batch ranges = [(1), (2), (3-4), (5-9), (10-49), (50-99), (100+)]
constexpr int NUM_OUTCOUNT_BINS = 7;
int64_t output_count_bins[NUM_OUTCOUNT_BINS] = {0};
Expand Down Expand Up @@ -1927,6 +1934,12 @@ static UniValue getblockstats(const JSONRPCRequest& request)
outputs_consolidated += tx->vin.size();
}

// Look for transactions with high number of inputs and low outputs
if ((tx->vin.size() >= CONSOLIDATION_THRESHOLD) && tx->vout.size() == 1) {
++many_to_one_consolidating_txs;
many_to_one_consolidated_outputs += tx->vin.size();
}

int64_t tx_size = 0;
if (do_calculate_size) {

Expand Down Expand Up @@ -2109,6 +2122,9 @@ static UniValue getblockstats(const JSONRPCRequest& request)
}
ret_all.pushKV("dust_bins", dust_res);

ret_all.pushKV("mto_consolidations", many_to_one_consolidating_txs);
ret_all.pushKV("mto_output_count", many_to_one_consolidated_outputs);

if (do_all) {
return ret_all;
}
Expand All @@ -2121,6 +2137,7 @@ static UniValue getblockstats(const JSONRPCRequest& request)
}
ret.pushKV(stat, value);
}

return ret;
}

Expand Down
Loading

0 comments on commit 3592649

Please sign in to comment.