aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-01-27 17:25:40 -0800
committerRiccardo Spagni <ric@spagni.net>2018-01-27 17:25:40 -0800
commitf7dcb730cb0bea5a3478b500845a6dcd3eccc559 (patch)
tree20054422d37316d6e402bd11a3c0ca676191a36d /src
parentMerge pull request #3143 (diff)
parentrpc: expose recent median block size in getinfo (diff)
downloadmonero-f7dcb730cb0bea5a3478b500845a6dcd3eccc559.tar.xz
Merge pull request #3144
42f86624 rpc: expose recent median block size in getinfo (moneromooo-monero)
Diffstat (limited to '')
-rw-r--r--src/cryptonote_core/blockchain.cpp9
-rw-r--r--src/cryptonote_core/blockchain.h8
-rw-r--r--src/rpc/core_rpc_server.cpp2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h4
4 files changed, 21 insertions, 2 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 5e80a8fde..178479f3c 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -133,7 +133,7 @@ static const uint64_t testnet_hard_fork_version_1_till = 624633;
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) :
- m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0),
+ m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_current_block_cumul_sz_median(0),
m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_cancel(false)
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -1101,6 +1101,12 @@ uint64_t Blockchain::get_current_cumulative_blocksize_limit() const
return m_current_block_cumul_sz_limit;
}
//------------------------------------------------------------------
+uint64_t Blockchain::get_current_cumulative_blocksize_median() const
+{
+ LOG_PRINT_L3("Blockchain::" << __func__);
+ return m_current_block_cumul_sz_median;
+}
+//------------------------------------------------------------------
//TODO: This function only needed minor modification to work with BlockchainDB,
// and *works*. As such, to reduce the number of things that might break
// in moving to BlockchainDB, this function will remain otherwise
@@ -3518,6 +3524,7 @@ bool Blockchain::update_next_cumulative_size_limit()
get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
uint64_t median = epee::misc_utils::median(sz);
+ m_current_block_cumul_sz_median = median;
if(median <= full_reward_zone)
median = full_reward_zone;
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 9c47ab425..b2bbff488 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -637,6 +637,13 @@ namespace cryptonote
uint64_t get_current_cumulative_blocksize_limit() const;
/**
+ * @brief gets the blocksize median based on recent blocks (same window as for the limit)
+ *
+ * @return the median
+ */
+ uint64_t get_current_cumulative_blocksize_median() const;
+
+ /**
* @brief gets the difficulty of the block with a given height
*
* @param i the height
@@ -962,6 +969,7 @@ namespace cryptonote
// main chain
transactions_container m_transactions;
size_t m_current_block_cumul_sz_limit;
+ size_t m_current_block_cumul_sz_median;
// metadata containers
std::unordered_map<crypto::hash, std::unordered_map<crypto::key_image, std::vector<output_data_t>>> m_scan_table;
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index a19ff15a0..140094faa 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -153,6 +153,7 @@ namespace cryptonote
res.testnet = m_testnet;
res.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1);
res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit();
+ res.block_size_median = m_core.get_blockchain_storage().get_current_cumulative_blocksize_median();
res.status = CORE_RPC_STATUS_OK;
res.start_time = (uint64_t)m_core.get_start_time();
res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
@@ -1339,6 +1340,7 @@ namespace cryptonote
res.testnet = m_testnet;
res.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1);
res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit();
+ res.block_size_median = m_core.get_blockchain_storage().get_current_cumulative_blocksize_median();
res.status = CORE_RPC_STATUS_OK;
res.start_time = (uint64_t)m_core.get_start_time();
res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index ae8bc446f..9b9a8f949 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,7 +49,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 17
+#define CORE_RPC_VERSION_MINOR 18
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -926,6 +926,7 @@ namespace cryptonote
std::string top_block_hash;
uint64_t cumulative_difficulty;
uint64_t block_size_limit;
+ uint64_t block_size_median;
uint64_t start_time;
uint64_t free_space;
bool offline;
@@ -948,6 +949,7 @@ namespace cryptonote
KV_SERIALIZE(top_block_hash)
KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE(block_size_limit)
+ KV_SERIALIZE(block_size_median)
KV_SERIALIZE(start_time)
KV_SERIALIZE(free_space)
KV_SERIALIZE(offline)