From 839280d5fc245cae101b07f3106c4b0031dd5941 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 23 Oct 2016 12:11:07 +0100 Subject: [PATCH] daemon: add a print_pool_stats daemon command Helps see what's going on now that Monero is getting used --- contrib/rlwrap/monerocommands_bitmonerod.txt | 1 + src/daemon/command_parser_executor.cpp | 7 +++ src/daemon/command_parser_executor.h | 2 + src/daemon/command_server.cpp | 5 ++ src/daemon/rpc_command_executor.cpp | 56 ++++++++++++++++++++ src/daemon/rpc_command_executor.h | 2 + 6 files changed, 73 insertions(+) diff --git a/contrib/rlwrap/monerocommands_bitmonerod.txt b/contrib/rlwrap/monerocommands_bitmonerod.txt index 1c97cfed..9572e40f 100644 --- a/contrib/rlwrap/monerocommands_bitmonerod.txt +++ b/contrib/rlwrap/monerocommands_bitmonerod.txt @@ -19,6 +19,7 @@ print_height print_pl print_pool print_pool_sh +print_pool_stats print_status print_tx q diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 5d7ed6cc..88b77f76 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -222,6 +222,13 @@ bool t_command_parser_executor::print_transaction_pool_short(const std::vector& args) +{ + if (!args.empty()) return false; + + return m_executor.print_transaction_pool_stats(); +} + bool t_command_parser_executor::start_mining(const std::vector& args) { if(!args.size()) diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index 6a984aa7..93b1fab5 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -84,6 +84,8 @@ public: bool print_transaction_pool_short(const std::vector& args); + bool print_transaction_pool_stats(const std::vector& args); + bool start_mining(const std::vector& args); bool stop_mining(const std::vector& args); diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 1418b920..729b19cb 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -110,6 +110,11 @@ t_command_server::t_command_server( , std::bind(&t_command_parser_executor::print_transaction_pool_short, &m_parser, p::_1) , "Print transaction pool (short format)" ); + m_command_lookup.set_handler( + "print_pool_stats" + , std::bind(&t_command_parser_executor::print_transaction_pool_stats, &m_parser, p::_1) + , "Print transaction pool statistics" + ); m_command_lookup.set_handler( "show_hr" , std::bind(&t_command_parser_executor::show_hash_rate, &m_parser, p::_1) diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index bed10715..525e87e7 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -824,6 +824,62 @@ bool t_rpc_command_executor::print_transaction_pool_short() { return true; } +bool t_rpc_command_executor::print_transaction_pool_stats() { + cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req; + cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res; + + std::string fail_message = "Problem fetching transaction pool"; + + if (m_is_rpc) + { + if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str())) + { + return true; + } + } + else + { + if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK) + { + tools::fail_msg_writer() << fail_message.c_str(); + return true; + } + } + + size_t n_transactions = res.transactions.size(); + size_t bytes = 0, min_bytes = 0, max_bytes = 0; + size_t n_not_relayed = 0; + uint64_t fee = 0; + uint64_t oldest = 0; + size_t n_10m = 0; + size_t n_failing = 0; + const uint64_t now = time(NULL); + for (const auto &tx_info: res.transactions) + { + bytes += tx_info.blob_size; + if (min_bytes == 0 || bytes < min_bytes) + min_bytes = bytes; + if (bytes > max_bytes) + max_bytes = bytes; + if (!tx_info.relayed) + n_not_relayed++; + fee += tx_info.fee; + if (oldest == 0 || tx_info.receive_time < oldest) + oldest = tx_info.receive_time; + if (tx_info.receive_time < now - 600) + n_10m++; + if (tx_info.last_failed_height) + ++n_failing; + } + size_t avg_bytes = bytes / n_transactions; + + tools::msg_writer() << n_transactions << " tx(es), " << bytes << " bytes total (min " << min_bytes << ", max " << max_bytes << ", avg " << avg_bytes << ")" << std::endl + << "fees " << cryptonote::print_money(fee) << " (avg " << cryptonote::print_money(fee / n_transactions) << " per tx)" << std::endl + << n_not_relayed << " not relayed, " << n_failing << " failing, " << n_10m << " older than 10 minutes (oldest " << (oldest == 0 ? "-" : get_human_time_ago(oldest, now)) << ")" << std::endl; + + return true; +} + bool t_rpc_command_executor::start_mining(cryptonote::account_public_address address, uint64_t num_threads, bool testnet) { cryptonote::COMMAND_RPC_START_MINING::request req; cryptonote::COMMAND_RPC_START_MINING::response res; diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index c097453e..c1c99155 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -96,6 +96,8 @@ public: bool print_transaction_pool_short(); + bool print_transaction_pool_stats(); + bool start_mining(cryptonote::account_public_address address, uint64_t num_threads, bool testnet); bool stop_mining();