Skip to content

Commit 9006119

Browse files
committed
Merge pull request #6734
3aae649 Tweak format, add option for difficulty (hyc) e416f56 Add options to print daily coin emission and fees (hyc) 2f481da Don't forget size of prunable txn part (hyc)
2 parents c9aad8a + 3aae649 commit 9006119

File tree

1 file changed

+70
-11
lines changed

1 file changed

+70
-11
lines changed

src/blockchain_utilities/blockchain_stats.cpp

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ int main(int argc, char* argv[])
6868
const command_line::arg_descriptor<bool> arg_outputs = {"with-outputs", "with output stats", false};
6969
const command_line::arg_descriptor<bool> arg_ringsize = {"with-ringsize", "with ringsize stats", false};
7070
const command_line::arg_descriptor<bool> arg_hours = {"with-hours", "with txns per hour", false};
71+
const command_line::arg_descriptor<bool> arg_emission = {"with-emission", "with coin emission", false};
72+
const command_line::arg_descriptor<bool> arg_fees = {"with-fees", "with txn fees", false};
73+
const command_line::arg_descriptor<bool> arg_diff = {"with-diff", "with difficulty", false};
7174

7275
command_line::add_arg(desc_cmd_sett, cryptonote::arg_data_dir);
7376
command_line::add_arg(desc_cmd_sett, cryptonote::arg_testnet_on);
@@ -79,6 +82,9 @@ int main(int argc, char* argv[])
7982
command_line::add_arg(desc_cmd_sett, arg_outputs);
8083
command_line::add_arg(desc_cmd_sett, arg_ringsize);
8184
command_line::add_arg(desc_cmd_sett, arg_hours);
85+
command_line::add_arg(desc_cmd_sett, arg_emission);
86+
command_line::add_arg(desc_cmd_sett, arg_fees);
87+
command_line::add_arg(desc_cmd_sett, arg_diff);
8288
command_line::add_arg(desc_cmd_only, command_line::arg_help);
8389

8490
po::options_description desc_options("Allowed options");
@@ -120,6 +126,9 @@ int main(int argc, char* argv[])
120126
bool do_outputs = command_line::get_arg(vm, arg_outputs);
121127
bool do_ringsize = command_line::get_arg(vm, arg_ringsize);
122128
bool do_hours = command_line::get_arg(vm, arg_hours);
129+
bool do_emission = command_line::get_arg(vm, arg_emission);
130+
bool do_fees = command_line::get_arg(vm, arg_fees);
131+
bool do_diff = command_line::get_arg(vm, arg_diff);
123132

124133
LOG_PRINT_L0("Initializing source blockchain (BlockchainDB)");
125134
std::unique_ptr<Blockchain> core_storage;
@@ -177,12 +186,20 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
177186
// spit out a comment that GnuPlot can use as an index
178187
std::cout << ENDL << "# DATA" << ENDL;
179188
std::cout << "Date\tBlocks/day\tBlocks\tTxs/Day\tTxs\tBytes/Day\tBytes";
189+
if (do_emission)
190+
std::cout << "\tEmission/day\tEmission";
191+
if (do_fees)
192+
std::cout << "\tFees/day\tFees";
193+
if (do_diff)
194+
std::cout << "\tDiffMin\tDiffMax\tDiffAvg";
180195
if (do_inputs)
181196
std::cout << "\tInMin\tInMax\tInAvg";
182197
if (do_outputs)
183198
std::cout << "\tOutMin\tOutMax\tOutAvg";
184199
if (do_ringsize)
185200
std::cout << "\tRingMin\tRingMax\tRingAvg";
201+
if (do_inputs || do_outputs || do_ringsize)
202+
std::cout << std::setprecision(2) << std::fixed;
186203
if (do_hours) {
187204
char buf[8];
188205
unsigned int i;
@@ -193,14 +210,20 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
193210
}
194211
std::cout << ENDL;
195212

213+
#define MAX_INOUT 0xffffffff
214+
#define MAX_RINGS 0xffffffff
215+
196216
struct tm prevtm = {0}, currtm;
197217
uint64_t prevsz = 0, currsz = 0;
198218
uint64_t prevtxs = 0, currtxs = 0;
199219
uint64_t currblks = 0;
200220
uint64_t totins = 0, totouts = 0, totrings = 0;
201-
uint32_t minins = 10, maxins = 0;
202-
uint32_t minouts = 10, maxouts = 0;
203-
uint32_t minrings = 50, maxrings = 0;
221+
boost::multiprecision::uint128_t prevemission = 0, prevfees = 0;
222+
boost::multiprecision::uint128_t emission = 0, fees = 0;
223+
boost::multiprecision::uint128_t totdiff = 0, mindiff = 0, maxdiff = 0;
224+
uint32_t minins = MAX_INOUT, maxins = 0;
225+
uint32_t minouts = MAX_INOUT, maxouts = 0;
226+
uint32_t minrings = MAX_RINGS, maxrings = 0;
204227
uint32_t io, tottxs = 0;
205228
uint32_t txhr[24] = {0};
206229
unsigned int i;
@@ -230,34 +253,50 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
230253
std::cout << timebuf << "\t" << currblks << "\t" << h << "\t" << currtxs << "\t" << prevtxs + currtxs << "\t" << currsz << "\t" << prevsz + currsz;
231254
prevsz += currsz;
232255
currsz = 0;
233-
currblks = 0;
234256
prevtxs += currtxs;
235257
currtxs = 0;
236258
if (!tottxs)
237259
tottxs = 1;
260+
if (do_emission) {
261+
std::cout << "\t" << print_money(emission) << "\t" << print_money(prevemission + emission);
262+
prevemission += emission;
263+
emission = 0;
264+
}
265+
if (do_fees) {
266+
std::cout << "\t" << print_money(fees) << "\t" << print_money(prevfees + fees);
267+
prevfees += fees;
268+
fees = 0;
269+
}
270+
if (do_diff) {
271+
std::cout << "\t" << (maxdiff ? mindiff : 0) << "\t" << maxdiff << "\t" << totdiff / currblks;
272+
mindiff = 0; maxdiff = 0; totdiff = 0;
273+
}
238274
if (do_inputs) {
239-
std::cout << "\t" << (maxins ? minins : 0) << "\t" << maxins << "\t" << totins / tottxs;
240-
minins = 10; maxins = 0; totins = 0;
275+
std::cout << "\t" << (maxins ? minins : 0) << "\t" << maxins << "\t" << totins * 1.0 / tottxs;
276+
minins = MAX_INOUT; maxins = 0; totins = 0;
241277
}
242278
if (do_outputs) {
243-
std::cout << "\t" << (maxouts ? minouts : 0) << "\t" << maxouts << "\t" << totouts / tottxs;
244-
minouts = 10; maxouts = 0; totouts = 0;
279+
std::cout << "\t" << (maxouts ? minouts : 0) << "\t" << maxouts << "\t" << totouts * 1.0 / tottxs;
280+
minouts = MAX_INOUT; maxouts = 0; totouts = 0;
245281
}
246282
if (do_ringsize) {
247-
std::cout << "\t" << (maxrings ? minrings : 0) << "\t" << maxrings << "\t" << totrings / tottxs;
248-
minrings = 50; maxrings = 0; totrings = 0;
283+
std::cout << "\t" << (maxrings ? minrings : 0) << "\t" << maxrings << "\t" << totrings * 1.0 / tottxs;
284+
minrings = MAX_RINGS; maxrings = 0; totrings = 0;
249285
}
250-
tottxs = 0;
251286
if (do_hours) {
252287
for (i=0; i<24; i++) {
253288
std::cout << "\t" << txhr[i];
254289
txhr[i] = 0;
255290
}
256291
}
292+
currblks = 0;
293+
tottxs = 0;
257294
std::cout << ENDL;
258295
}
259296
skip:
260297
currsz += bd.size();
298+
uint64_t coinbase_amount;
299+
uint64_t tx_fee_amount = 0;
261300
for (const auto& tx_id : blk.tx_hashes)
262301
{
263302
if (tx_id == crypto::null_hash)
@@ -275,7 +314,12 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
275314
return 1;
276315
}
277316
currsz += bd.size();
317+
if (db->get_prunable_tx_blob(tx_id, bd))
318+
currsz += bd.size();
278319
currtxs++;
320+
if (do_fees || do_emission) {
321+
tx_fee_amount += get_tx_fee(tx);
322+
}
279323
if (do_hours)
280324
txhr[currtm.tm_hour]++;
281325
if (do_inputs) {
@@ -306,6 +350,21 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
306350
}
307351
tottxs++;
308352
}
353+
if (do_diff) {
354+
difficulty_type diff = db->get_block_difficulty(h);
355+
if (!mindiff || diff < mindiff)
356+
mindiff = diff;
357+
if (diff > maxdiff)
358+
maxdiff = diff;
359+
totdiff += diff;
360+
}
361+
if (do_emission) {
362+
coinbase_amount = get_outs_money_amount(blk.miner_tx);
363+
emission += coinbase_amount - tx_fee_amount;
364+
}
365+
if (do_fees) {
366+
fees += tx_fee_amount;
367+
}
309368
currblks++;
310369

311370
if (stop_requested)

0 commit comments

Comments
 (0)