From 4dbf29bd329c8891f9b6a8eaab71ee985518800b Mon Sep 17 00:00:00 2001 From: moneromooo Date: Wed, 23 Aug 2017 18:20:51 +0100 Subject: [PATCH 1/2] txpool: add tx size median to the pool stats --- src/cryptonote_core/tx_pool.cpp | 6 +++++- src/daemon/rpc_command_executor.cpp | 2 +- src/rpc/core_rpc_server_commands_defs.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 73f519079..e7fc14a44 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -560,7 +560,10 @@ namespace cryptonote const uint64_t now = time(NULL); std::map agebytes; stats.txs_total = m_blockchain.get_txpool_tx_count(); - m_blockchain.for_all_txpool_txes([&stats, now, &agebytes](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){ + std::vector sizes; + sizes.reserve(stats.txs_total); + m_blockchain.for_all_txpool_txes([&stats, &sizes, now, &agebytes](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){ + sizes.push_back(meta.blob_size); stats.bytes_total += meta.blob_size; if (!stats.bytes_min || meta.blob_size < stats.bytes_min) stats.bytes_min = meta.blob_size; @@ -580,6 +583,7 @@ namespace cryptonote agebytes[age].bytes += meta.blob_size; return true; }); + stats.bytes_med = epee::misc_utils::median(sizes); if (stats.txs_total > 1) { /* looking for 98th percentile */ diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index fde1749d2..f0ae59882 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -973,7 +973,7 @@ bool t_rpc_command_executor::print_transaction_pool_stats() { backlog_message = (boost::format("estimated %u block (%u minutes) backlog") % backlog % (backlog * DIFFICULTY_TARGET_V2 / 60)).str(); } - tools::msg_writer() << n_transactions << " tx(es), " << res.pool_stats.bytes_total << " bytes total (min " << res.pool_stats.bytes_min << ", max " << res.pool_stats.bytes_max << ", avg " << avg_bytes << ")" << std::endl + tools::msg_writer() << n_transactions << " tx(es), " << res.pool_stats.bytes_total << " bytes total (min " << res.pool_stats.bytes_min << ", max " << res.pool_stats.bytes_max << ", avg " << avg_bytes << ", median " << res.pool_stats.bytes_med << ")" << std::endl << "fees " << cryptonote::print_money(res.pool_stats.fee_total) << " (avg " << cryptonote::print_money(n_transactions ? res.pool_stats.fee_total / n_transactions : 0) << " per tx" << ", " << cryptonote::print_money(res.pool_stats.bytes_total ? res.pool_stats.fee_total / res.pool_stats.bytes_total : 0) << " per byte)" << std::endl << res.pool_stats.num_not_relayed << " not relayed, " << res.pool_stats.num_failing << " failing, " << res.pool_stats.num_10m << " older than 10 minutes (oldest " << (res.pool_stats.oldest == 0 ? "-" : get_human_time_ago(res.pool_stats.oldest, now)) << "), " << backlog_message; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index c413f9af8..2ada091f8 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1087,6 +1087,7 @@ namespace cryptonote uint64_t bytes_total; uint32_t bytes_min; uint32_t bytes_max; + uint32_t bytes_med; uint64_t fee_total; uint64_t oldest; uint32_t txs_total; @@ -1100,6 +1101,7 @@ namespace cryptonote KV_SERIALIZE(bytes_total) KV_SERIALIZE(bytes_min) KV_SERIALIZE(bytes_max) + KV_SERIALIZE(bytes_med) KV_SERIALIZE(fee_total) KV_SERIALIZE(oldest) KV_SERIALIZE(txs_total) From 1914c999c7382a3407aa7c440cb0d6a0e5428df2 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Wed, 23 Aug 2017 18:21:14 +0100 Subject: [PATCH 2/2] txpool: update db tx metadata when it changes --- src/cryptonote_core/tx_pool.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index e7fc14a44..893066580 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -909,7 +909,21 @@ namespace cryptonote // Skip transactions that are not ready to be // included into the blockchain or that are // missing key images - if (!is_transaction_ready_to_go(meta, tx)) + const cryptonote::txpool_tx_meta_t original_meta = meta; + bool ready = is_transaction_ready_to_go(meta, tx); + if (memcmp(&original_meta, &meta, sizeof(meta))) + { + try + { + m_blockchain.update_txpool_tx(sorted_it->second, meta); + } + catch (const std::exception &e) + { + MERROR("Failed to update tx meta: " << e.what()); + // continue, not fatal + } + } + if (!ready) { LOG_PRINT_L2(" not ready to go"); sorted_it++;