From 661f1fb8b2427e6fef20b34a48aecb200aa44b1a Mon Sep 17 00:00:00 2001 From: stoffu Date: Tue, 9 Apr 2019 17:46:54 +0900 Subject: [PATCH 1/4] blockchain: remove unused calc of short_term_constraint --- src/cryptonote_core/blockchain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 73c60760b..dd3a5f0b9 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3916,7 +3916,6 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti new_weights[0] = long_term_block_weight; long_term_median = epee::misc_utils::median(new_weights); m_long_term_effective_median_block_weight = std::max(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median); - short_term_constraint = m_long_term_effective_median_block_weight + m_long_term_effective_median_block_weight * 2 / 5; weights.clear(); get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW); From 815d08dc5f18f49fe229dfddfefdc18cbe6a50a8 Mon Sep 17 00:00:00 2001 From: stoffu Date: Tue, 9 Apr 2019 18:54:00 +0900 Subject: [PATCH 2/4] tests/block_weight: remove unused MULTIPLIER_SMALL --- tests/block_weight/block_weight.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py index ba533c53c..ae75844e2 100755 --- a/tests/block_weight/block_weight.py +++ b/tests/block_weight/block_weight.py @@ -9,7 +9,6 @@ import math MEDIAN_WINDOW_SMALL = 100 # number of recent blocks for median computation MEDIAN_WINDOW_BIG = 5000 -MULTIPLIER_SMALL = 1.4 # multipliers for determining weights MULTIPLIER_BIG = 50.0 MEDIAN_THRESHOLD = 300*1000 # initial value for median (scaled kB -> B) lcg_seed = 0 From 467f4c7ed303ca56bb0545716791c84fe11e3ce6 Mon Sep 17 00:00:00 2001 From: stoffu Date: Tue, 9 Apr 2019 19:13:55 +0900 Subject: [PATCH 3/4] tests/block_weight: use integer division when computing median --- tests/block_weight/block_weight.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py index ae75844e2..b23da3d77 100755 --- a/tests/block_weight/block_weight.py +++ b/tests/block_weight/block_weight.py @@ -23,9 +23,9 @@ def get_median(vec): #temp = vec temp = sorted(vec) if len(temp) % 2 == 1: - return temp[len(temp)/2] + return temp[len(temp)//2] else: - return int((temp[len(temp)/2]+temp[len(temp)/2-1])/2) + return int((temp[len(temp)//2]+temp[len(temp)//2-1])//2) def LCG(): global lcg_seed From e9fac29a4b31c8d09f2c63051400f62bc8fa457e Mon Sep 17 00:00:00 2001 From: stoffu Date: Tue, 9 Apr 2019 19:38:11 +0900 Subject: [PATCH 4/4] unit_tests/long_term_block_weight: some tweaks that seem to make more sense --- tests/unit_tests/long_term_block_weight.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp index bf1368618..b7713c63a 100644 --- a/tests/unit_tests/long_term_block_weight.cpp +++ b/tests/unit_tests/long_term_block_weight.cpp @@ -198,9 +198,10 @@ TEST(long_term_block_weight, multi_pop) const uint64_t effective_median = bc->get_current_cumulative_block_weight_median(); const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit(); - for (uint64_t h = 0; h < 4; ++h) + const uint64_t num_pop = 4; + for (uint64_t h = 0; h < num_pop; ++h) { - size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit(); + size_t w = bc->get_current_cumulative_block_weight_limit(); uint64_t ltw = bc->get_next_long_term_block_weight(w); bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}); ASSERT_TRUE(bc->update_next_cumulative_weight_limit()); @@ -208,10 +209,8 @@ TEST(long_term_block_weight, multi_pop) cryptonote::block b; std::vector txs; - bc->get_db().pop_block(b, txs); - bc->get_db().pop_block(b, txs); - bc->get_db().pop_block(b, txs); - bc->get_db().pop_block(b, txs); + for (uint64_t h = 0; h < num_pop; ++h) + bc->get_db().pop_block(b, txs); ASSERT_TRUE(bc->update_next_cumulative_weight_limit()); ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median()); @@ -294,9 +293,11 @@ TEST(long_term_block_weight, pop_invariant_random) { PREFIX(10); - for (uint64_t h = 1; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW - 10; ++h) + for (uint64_t h = 1; h < 2 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW - 10; ++h) { - size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit(); + lcg_seed = bc->get_db().height(); + uint32_t r = lcg(); + size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : (r % bc->get_current_cumulative_block_weight_limit()); uint64_t ltw = bc->get_next_long_term_block_weight(w); bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {}); ASSERT_TRUE(bc->update_next_cumulative_weight_limit());