From 7058fd7dfc08d562324228ad75594b6a76dd1c0f Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Wed, 30 Sep 2020 12:30:20 +0000 Subject: [PATCH] test: Optimize feature_block_reward_reallocation.py (#3743) * test: Optimize feature_block_reward_reallocation.py Signed-off-by: pasta * use submitblock instead of p2p.send_blocks_and_test in one more place * drop empty line * make sure all nodes are synced after reallocation is done Co-authored-by: UdjinM6 --- .../feature_block_reward_reallocation.py | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/test/functional/feature_block_reward_reallocation.py b/test/functional/feature_block_reward_reallocation.py index 5c3ad6c8cb..f6f9364128 100755 --- a/test/functional/feature_block_reward_reallocation.py +++ b/test/functional/feature_block_reward_reallocation.py @@ -3,7 +3,8 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. from test_framework.blocktools import create_block, create_coinbase, get_masternode_payment -from test_framework.mininode import * +from test_framework.mininode import P2PDataStore, network_thread_start +from test_framework.messages import CTxOut, FromHex, CCbTx, CTransaction, ToHex from test_framework.script import CScript from test_framework.test_framework import DashTestFramework from test_framework.util import assert_equal, get_bip9_status, hex_str_to_bytes @@ -15,9 +16,10 @@ Checks block reward reallocation correctness ''' + class BlockRewardReallocationTest(DashTestFramework): def set_test_params(self): - self.set_dash_test_params(4, 3, fast_dip3_enforcement=True) + self.set_dash_test_params(2, 1, fast_dip3_enforcement=True) self.set_dash_dip8_activation(450) # 536870912 == 0x20000000, i.e. not signalling for anything @@ -56,18 +58,15 @@ class BlockRewardReallocationTest(DashTestFramework): # create and send non-signalling blocks for i in range(500 - num_blocks): test_block = self.create_test_block() - self.nodes[0].p2p.send_blocks_and_test([test_block], self.nodes[0], timeout=5) + self.nodes[0].submitblock(ToHex(test_block)) # generate at most 10 signaling blocks at a time if num_blocks > 0: for i in range((num_blocks - 1) // 10): self.bump_mocktime(10) self.nodes[0].generate(10) - self.sync_blocks() self.nodes[0].generate((num_blocks - 1) % 10) - self.sync_blocks() assert_equal(get_bip9_status(self.nodes[0], 'realloc')['status'], 'started') self.nodes[0].generate(1) - self.sync_blocks() if expected_lockin: assert_equal(get_bip9_status(self.nodes[0], 'realloc')['status'], 'locked_in') else: @@ -84,7 +83,6 @@ class BlockRewardReallocationTest(DashTestFramework): while get_bip9_status(self.nodes[0], 'dip0003')['status'] != 'active': self.bump_mocktime(10) self.nodes[0].generate(10) - self.sync_blocks() self.nodes[0].add_p2p_connection(P2PDataStore()) network_thread_start() @@ -95,7 +93,6 @@ class BlockRewardReallocationTest(DashTestFramework): for i in range(498 - bi['blocks']): self.bump_mocktime(1) self.nodes[0].generate(1) - self.sync_blocks() self.log.info("Initial state is DEFINED") bi = self.nodes[0].getblockchaininfo() @@ -109,14 +106,14 @@ class BlockRewardReallocationTest(DashTestFramework): assert_equal(bi['bip9_softforks']['realloc']['status'], 'started') assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(0)) - self.signal(399, False) # 1 block short + 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'], self.threshold(1)) - self.signal(398, False) # 1 block short again + 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() @@ -124,15 +121,13 @@ class BlockRewardReallocationTest(DashTestFramework): assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(2)) pre_locked_in_blockhash = bi['bestblockhash'] - self.signal(396, True) # just enough to lock in + self.signal(396, True) # just enough to lock in self.log.info("Advanced to LOCKED_IN at height = 1999") for i in range(49): self.bump_mocktime(10) self.nodes[0].generate(10) - self.sync_blocks() self.nodes[0].generate(9) - self.sync_blocks() self.log.info("Still LOCKED_IN at height = 2498") bi = self.nodes[0].getblockchaininfo() @@ -140,7 +135,7 @@ class BlockRewardReallocationTest(DashTestFramework): assert_equal(bi['bip9_softforks']['realloc']['status'], 'locked_in') self.log.info("Advance from LOCKED_IN to ACTIVE at height = 2499") - self.nodes[0].generate(1) # activation + self.nodes[0].generate(1) # activation bi = self.nodes[0].getblockchaininfo() assert_equal(bi['blocks'], 2499) assert_equal(bi['bip9_softforks']['realloc']['status'], 'active') @@ -152,18 +147,16 @@ class BlockRewardReallocationTest(DashTestFramework): assert_equal(bt['height'], 2500) assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500)) self.nodes[0].generate(9) - self.sync_blocks() bt = self.nodes[0].getblocktemplate() assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500)) assert_equal(bt['coinbasevalue'], 13748571607) assert_equal(bt['masternode'][0]['amount'], 6874285801) # 0.4999999998 self.log.info("Reallocation should kick-in with the superblock mined at height = 2010") - for period in range(19): # there will be 19 adjustments, 3 superblocks long each + for period in range(19): # there will be 19 adjustments, 3 superblocks long each for i in range(3): self.bump_mocktime(10) self.nodes[0].generate(10) - self.sync_blocks() bt = self.nodes[0].getblocktemplate() assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500)) @@ -172,36 +165,38 @@ class BlockRewardReallocationTest(DashTestFramework): assert_equal(bt['masternode'][0]['amount'], 6132959502) # 0.6 self.log.info("Reward split should stay ~60/40 after reallocation is done") - for period in range(10): # check 10 next superblocks + for period in range(10): # check 10 next superblocks self.bump_mocktime(10) self.nodes[0].generate(10) - self.sync_blocks() bt = self.nodes[0].getblocktemplate() assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500)) assert_equal(bt['coinbasevalue'], 9491484944) assert_equal(bt['masternode'][0]['amount'], 5694890966) # 0.6 + # make sure all nodes are still synced + self.sync_all() + self.log.info("Rollback the chain back to the STARTED state") self.mocktime = self.nodes[0].getblock(pre_locked_in_blockhash, 1)['time'] for node in self.nodes: node.invalidateblock(pre_locked_in_blockhash) - self.sync_all() # create and send non-signalling block test_block = self.create_test_block() - self.nodes[0].p2p.send_blocks_and_test([test_block], self.nodes[0], timeout=5) + self.nodes[0].submitblock(ToHex(test_block)) bi = self.nodes[0].getblockchaininfo() assert_equal(bi['blocks'], 1499) assert_equal(bi['bip9_softforks']['realloc']['status'], 'started') assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(2)) self.log.info("Check thresholds reach min level and stay there") - for i in range(8): # 7 to reach min level and 1 more to check it doesn't go lower than that - self.signal(0, False) # no need to signal + for i in range(8): # 7 to reach min level and 1 more to check it doesn't go lower than that + self.signal(0, False) # no need to signal bi = self.nodes[0].getblockchaininfo() assert_equal(bi['blocks'], 1999 + i * 500) assert_equal(bi['bip9_softforks']['realloc']['status'], 'started') assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(i + 3)) assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], 300) + if __name__ == '__main__': BlockRewardReallocationTest().main()