aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp30
-rw-r--r--src/cryptonote_core/blockchain.h14
2 files changed, 44 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
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 3311798f0..eb7a050b2 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -526,6 +526,20 @@ namespace cryptonote
static uint64_t get_dynamic_per_kb_fee(uint64_t block_reward, size_t median_block_size);
/**
+ * @brief get dynamic per kB fee estimate for the next few blocks
+ *
+ * The dynamic fee is based on the block size in a past window, and
+ * the current block reward. It is expressed by kB. This function
+ * calculates an estimate for a dynamic fee which will be valid for
+ * the next grace_blocks
+ *
+ * @param grace_blocks number of blocks we want the fee to be valid for
+ *
+ * @return the per kB fee estimate
+ */
+ uint64_t get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks) const;
+
+ /**
* @brief validate a transaction's fee
*
* This function validates the fee is enough for the transaction.