Skip to content

Commit

Permalink
Add simplified threshold calculation and use it in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Sep 10, 2020
1 parent 6deb157 commit 5b44deb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/functional/feature_block_reward_reallocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def signal(self, num_blocks, expected_lockin):
else:
assert_equal(get_bip9_status(self.nodes[0], 'realloc')['status'], 'started')

def threshold(self, attempt):
threshold_calc = 400 - attempt * attempt;
if threshold_calc < 300:
return 300
return threshold_calc

def run_test(self):
self.log.info("Wait for DIP3 to activate")
while get_bip9_status(self.nodes[0], 'dip0003')['status'] != 'active':
Expand Down Expand Up @@ -101,21 +107,21 @@ def run_test(self):
bi = self.nodes[0].getblockchaininfo()
assert_equal(bi['blocks'], 499)
assert_equal(bi['bip9_softforks']['realloc']['status'], 'started')
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], 400)
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(0))

self.signal(399, False) # 1 block short

self.log.info("Still STARTED but new threshold should be lower at height = 999")
bi = self.nodes[0].getblockchaininfo()
assert_equal(bi['blocks'], 999)
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], 399)
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(1))

self.signal(398, False) # 1 block short again

self.log.info("Still STARTED but new threshold should be even lower at height = 1499")
bi = self.nodes[0].getblockchaininfo()
assert_equal(bi['blocks'], 1499)
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], 396)
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(2))

self.signal(396, True) # just enough to lock in
self.log.info("Advanced to LOCKED_IN at height = 1999")
Expand Down

0 comments on commit 5b44deb

Please sign in to comment.