aboutsummaryrefslogtreecommitdiff
path: root/tests/block_weight/block_weight.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/block_weight/block_weight.py')
-rwxr-xr-xtests/block_weight/block_weight.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py
index 5ec09896d..cfd0900fb 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]))