aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-06-01 19:32:37 +0200
committerRiccardo Spagni <ric@spagni.net>2017-06-01 19:32:37 +0200
commitfbfad8ee1bf12c1629e4d32c93e43d69e97442bd (patch)
treee102846c2c56b8833156fc92e920411bdb1fbcf1 /src/cryptonote_core
parentMerge pull request #2053 (diff)
parentSpeedup print_pool_stats (diff)
downloadmonero-fbfad8ee1bf12c1629e4d32c93e43d69e97442bd.tar.xz
Merge pull request #2061
5414970d Speedup print_pool_stats (Howard Chu)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp6
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
-rw-r--r--src/cryptonote_core/tx_pool.cpp25
-rw-r--r--src/cryptonote_core/tx_pool.h7
4 files changed, 45 insertions, 0 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 21b0b4ceb..2b3d09c45 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1046,6 +1046,12 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
+ bool core::get_pool_transaction_stats(struct txpool_stats& stats) const
+ {
+ m_mempool.get_transaction_stats(stats);
+ return true;
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::get_pool_transaction(const crypto::hash &id, cryptonote::blobdata& tx) const
{
return m_mempool.get_transaction(id, tx);
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 5e66af545..e5fbf7f91 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -411,6 +411,13 @@ namespace cryptonote
bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const;
/**
+ * @copydoc tx_memory_pool::get_transactions
+ *
+ * @note see tx_memory_pool::get_transactions
+ */
+ bool get_pool_transaction_stats(struct txpool_stats& stats) const;
+
+ /**
* @copydoc tx_memory_pool::get_transaction
*
* @note see tx_memory_pool::get_transaction
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 30aed50f9..ebf170c8c 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -546,6 +546,31 @@ namespace cryptonote
});
}
//------------------------------------------------------------------
+ void tx_memory_pool::get_transaction_stats(struct txpool_stats& stats) const
+ {
+ CRITICAL_REGION_LOCAL(m_transactions_lock);
+ CRITICAL_REGION_LOCAL1(m_blockchain);
+ const uint64_t now = time(NULL);
+ stats.txs_total = m_blockchain.get_txpool_tx_count();
+ m_blockchain.for_all_txpool_txes([&stats, now](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){
+ stats.bytes_total += meta.blob_size;
+ if (!stats.bytes_min || meta.blob_size < stats.bytes_min)
+ stats.bytes_min = meta.blob_size;
+ if (meta.blob_size > stats.bytes_max)
+ stats.bytes_max = meta.blob_size;
+ if (!meta.relayed)
+ stats.num_not_relayed++;
+ stats.fee_total += meta.fee;
+ if (!stats.oldest || meta.receive_time < stats.oldest)
+ stats.oldest = meta.receive_time;
+ if (meta.receive_time < now - 600)
+ stats.num_10m++;
+ if (meta.last_failed_height)
+ stats.num_failing++;
+ return true;
+ });
+ }
+ //------------------------------------------------------------------
//TODO: investigate whether boolean return is appropriate
bool tx_memory_pool::get_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const
{
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index a2ab76959..1858ccdd8 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -243,6 +243,13 @@ namespace cryptonote
void get_transaction_hashes(std::vector<crypto::hash>& txs) const;
/**
+ * @brief get a summary statistics of all transaction hashes in the pool
+ *
+ * @param stats return-by-reference the pool statistics
+ */
+ void get_transaction_stats(struct txpool_stats& stats) const;
+
+ /**
* @brief get information about all transactions and key images in the pool
*
* see documentation on tx_info and spent_key_image_info for more details