From e0b3507c8822bb9eebe38b39e4b785bf3f29c83c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 8 Aug 2022 06:03:10 +0000 Subject: [PATCH] tests: update block_weight for 2021 scaling the test was still performed with consensus rules from before that change --- tests/block_weight/block_weight.cpp | 6 +++--- tests/block_weight/block_weight.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp index b478a5633..948feca39 100644 --- a/tests/block_weight/block_weight.cpp +++ b/tests/block_weight/block_weight.cpp @@ -141,7 +141,7 @@ static uint32_t lcg() static void test(test_t t, uint64_t blocks) { - PREFIX(10); + PREFIX(HF_VERSION_2021_SCALING); for (uint64_t h = 0; h < LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h) { @@ -180,8 +180,8 @@ static void test(test_t t, uint64_t blocks) } uint64_t ltw = bc->get_next_long_term_block_weight(w); cryptonote::block b; - b.major_version = 10; - b.minor_version = 10; + b.major_version = HF_VERSION_2021_SCALING; + b.minor_version = HF_VERSION_2021_SCALING; bc->get_db().add_block(std::make_pair(std::move(b), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {}); if (!bc->update_next_cumulative_weight_limit()) diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py index 16154bab9..c9fa03b7b 100755 --- a/tests/block_weight/block_weight.py +++ b/tests/block_weight/block_weight.py @@ -18,14 +18,20 @@ ltembw = MEDIAN_THRESHOLD weights = [MEDIAN_THRESHOLD]*MEDIAN_WINDOW_SMALL # weights of recent blocks (B), with index -1 most recent lt_weights = [MEDIAN_THRESHOLD]*MEDIAN_WINDOW_BIG # long-term weights +# see contrib/epee/include/misc_language.h, get_mid +def get_mid(a, b): + return (a//2) + (b//2) + ((a - 2*(a//2)) + (b - 2*(b//2)))//2; + # Compute the median of a list def get_median(vec): - #temp = vec + if len(vec) == 1: + return vec[0] temp = sorted(vec) + n = len(temp) // 2 if len(temp) % 2 == 1: - return temp[len(temp)//2] + return temp[n] else: - return int((temp[len(temp)//2]+temp[len(temp)//2-1])//2) + return get_mid(temp[n-1], temp[n]) def LCG(): global lcg_seed @@ -46,7 +52,7 @@ def run(t, blocks): # determine the effective weight stmedian = get_median(weights[-MEDIAN_WINDOW_SMALL:]) - embw = min(max(MEDIAN_THRESHOLD,stmedian),int(MULTIPLIER_BIG*ltembw)) + embw = min(max(ltembw,stmedian),int(MULTIPLIER_BIG*ltembw)) # drop the lowest values weights = weights[1:] @@ -64,7 +70,7 @@ def run(t, blocks): else: sys.exit(1) weights.append(max_weight) - lt_weights.append(min(max_weight,int(ltembw + int(ltembw * 2 / 5)))) + lt_weights.append(min(max(max_weight, ltembw * 10 // 17),int(ltembw + int(ltembw * 7 / 10)))) #print "H %u, r %u, BW %u, EMBW %u, LTBW %u, LTEMBW %u, ltmedian %u" % (block, r, max_weight, embw, lt_weights[-1], ltembw, ltmedian) print("H %u, BW %u, EMBW %u, LTBW %u" % (block, max_weight, embw, lt_weights[-1]))