From 68e586e70022f2cfff7aff6ec1a5b37066d55d24 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 20 Apr 2021 03:01:29 +0300 Subject: [PATCH] daemon: print_tx_prun_info cmd added --- src/daemon/daemon_commands_handler.h | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index b6ede7e7..dee2a49d 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -42,6 +42,7 @@ public: m_cmd_binder.set_handler("print_bc_outs_stats", boost::bind(&daemon_commands_handler::print_bc_outs_stats, this, _1)); m_cmd_binder.set_handler("print_block", boost::bind(&daemon_commands_handler::print_block, this, _1), "Print block, print_block | "); m_cmd_binder.set_handler("print_block_info", boost::bind(&daemon_commands_handler::print_block_info, this, _1), "Print block info, print_block | "); + m_cmd_binder.set_handler("print_tx_prun_info", boost::bind(&daemon_commands_handler::print_tx_prun_info, this, _1), "Print tx prunning info"); m_cmd_binder.set_handler("print_tx", boost::bind(&daemon_commands_handler::print_tx, this, _1), "Print transaction, print_tx "); m_cmd_binder.set_handler("start_mining", boost::bind(&daemon_commands_handler::start_mining, this, _1), "Start mining for specified address, start_mining [threads=1]"); m_cmd_binder.set_handler("stop_mining", boost::bind(&daemon_commands_handler::stop_mining, this, _1), "Stop mining"); @@ -630,6 +631,56 @@ private: return true; } //-------------------------------------------------------------------------------- + bool print_tx_prun_info(const std::vector& arg) + { + currency::blockchain_storage& bcs = m_srv.get_payload_object().get_core().get_blockchain_storage(); + + size_t txs = 0; + size_t pruned_txs = 0; + size_t signatures = 0; + size_t attachments = 0; + size_t blocks = 0; + + uint64_t last_block_height = bcs.get_top_block_height(); + + LOG_PRINT_MAGENTA("start getting stats from 0 to " << last_block_height << " block, please wait ...", LOG_LEVEL_0); + + for (uint64_t height = 0; height <= last_block_height; height++, blocks++) + { + currency::block_extended_info bei = AUTO_VAL_INIT(bei); + bool r = bcs.get_block_extended_info_by_height(height, bei); + if (!r) + { + LOG_PRINT_RED("Failed to get block #" << height, LOG_LEVEL_0); + break; + } + + for (const auto& h : bei.bl.tx_hashes) + { + auto ptx = bcs.get_tx(h); + CHECK_AND_ASSERT_MES(ptx != nullptr, false, "failed to find transaction " << h << " in blockchain index, in block on height = " << height); + + if (ptx->signatures.size() == 0) + pruned_txs += 1; + + txs += 1; + signatures += ptx->signatures.size(); + attachments += ptx->attachment.size(); + } + } + + LOG_PRINT_MAGENTA(ENDL << "blockchain pruning stats:" << ENDL << + " last block height: " << last_block_height << ENDL << + " blocks processed: " << blocks << ENDL << + " total txs: " << txs << ENDL << + " pruned txs: " << pruned_txs << ENDL << + " total signatures: " << signatures << ENDL << + " total attachments: " << attachments << ENDL << + (pruned_txs == 0 ? "*** The database seems to be unpruned!" : "The database contains pruned transactions."), LOG_LEVEL_0); + + return true; + } + //-------------------------------------------------------------------------------- bool print_tx(const std::vector& args) { if (args.empty())