aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-10-28 21:19:40 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-10-31 08:38:00 +0000
commite6deb8abda0b6560c8691f376d8a86aab163dd77 (patch)
treef6e0167b114fbf3ee379f18c5d0a3c3d554a33f4 /src/cryptonote_core/blockchain.cpp
parentcore: dynamic fee algorithm from ArticMine (diff)
downloadmonero-e6deb8abda0b6560c8691f376d8a86aab163dd77.tar.xz
rpc: add a dynamic fee estimation RPC call
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index c92ee6c9b..ffebcd592 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2761,6 +2761,36 @@ bool Blockchain::check_fee(size_t blob_size, uint64_t fee) const
}
//------------------------------------------------------------------
+uint64_t Blockchain::get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks) const
+{
+ const uint8_t version = get_current_hard_fork_version();
+
+ if (version < HF_VERSION_DYNAMIC_FEE)
+ return FEE_PER_KB;
+
+ if (grace_blocks >= CRYPTONOTE_REWARD_BLOCKS_WINDOW)
+ grace_blocks = CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1;
+
+ std::vector<size_t> sz;
+ get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW - grace_blocks);
+ for (size_t i = 0; i < grace_blocks; ++i)
+ sz.push_back(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2);
+
+ uint64_t median = epee::misc_utils::median(sz);
+ if(median <= CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2)
+ median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2;
+
+ uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
+ uint64_t base_reward;
+ if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
+ return false;
+
+ uint64_t fee = get_dynamic_per_kb_fee(base_reward, median);
+ LOG_PRINT_L2("Estimating " << grace_blocks << "-block fee at " << print_money(fee) << "/kB");
+ return fee;
+}
+
+//------------------------------------------------------------------
// This function checks to see if a tx is unlocked. unlock_time is either
// a block index or a unix time.
bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) const