aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com>2023-10-01 13:40:06 +0100
committerBoog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com>2023-10-02 15:27:31 +0100
commit810f6a6cd2431988b6d349444aa3359ae90b2778 (patch)
tree7c8717f987fb495d93b3dbaf9502eb9c2135f729 /src
parentMerge pull request #9001 (diff)
downloadmonero-810f6a6cd2431988b6d349444aa3359ae90b2778.tar.xz
Fix: long term block weight cache
The long term block weight cache was doing a wrong calculation when adding a new block to the cache.
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain.cpp35
1 files changed, 2 insertions, 33 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 54ee3b088..1af5fb975 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -4616,40 +4616,9 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
}
else
{
- const uint64_t block_weight = m_db->get_block_weight(db_height - 1);
+ const uint64_t nblocks = std::min<uint64_t>(m_long_term_block_weights_window, db_height);
+ const uint64_t long_term_median = get_long_term_block_weight_median(db_height - nblocks, nblocks);
- uint64_t long_term_median;
- if (db_height == 1)
- {
- long_term_median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5;
- }
- else
- {
- uint64_t nblocks = std::min<uint64_t>(m_long_term_block_weights_window, db_height);
- if (nblocks == db_height)
- --nblocks;
- long_term_median = get_long_term_block_weight_median(db_height - nblocks - 1, nblocks);
- }
-
- m_long_term_effective_median_block_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median);
-
- uint64_t short_term_constraint = m_long_term_effective_median_block_weight;
- if (hf_version >= HF_VERSION_2021_SCALING)
- short_term_constraint += m_long_term_effective_median_block_weight * 7 / 10;
- else
- short_term_constraint += m_long_term_effective_median_block_weight * 2 / 5;
- uint64_t long_term_block_weight = std::min<uint64_t>(block_weight, short_term_constraint);
-
- if (db_height == 1)
- {
- long_term_median = long_term_block_weight;
- }
- else
- {
- m_long_term_block_weights_cache_tip_hash = m_db->get_block_hash_from_height(db_height - 1);
- m_long_term_block_weights_cache_rolling_median.insert(long_term_block_weight);
- long_term_median = m_long_term_block_weights_cache_rolling_median.median();
- }
m_long_term_effective_median_block_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median);
std::vector<uint64_t> weights;