diff --git a/test/functional/abc-parkedchain.py b/test/functional/abc-parkedchain.py --- a/test/functional/abc-parkedchain.py +++ b/test/functional/abc-parkedchain.py @@ -24,7 +24,13 @@ assert_equal(tip["status"], other_tip_status) def run_test(self): + def wait_for_tip(node, tip): + def check_tip(): + return node.getbestblockhash() == tip + wait_until(check_tip) + node = self.nodes[0] + parking_node = self.nodes[1] self.log.info("Test chain parking...") node.generate(10) @@ -34,6 +40,11 @@ node.generate(10) parked_tip = node.getbestblockhash() + # get parking_node caught up. + # (probably not needed, but just in case parking can have race + # condition like invalidateblock below) + wait_for_tip(parking_node, parked_tip) + # Let's park the chain. assert(parked_tip != tip) assert(block_to_park != tip) @@ -58,6 +69,9 @@ node.generate(1) good_tip = node.getbestblockhash() + # avoid race condition from parking_node requesting block when invalid + wait_for_tip(parking_node, good_tip) + node.invalidateblock(bad_tip) self.only_valid_tip(tip, other_tip_status="invalid") node.parkblock(bad_tip) @@ -75,6 +89,9 @@ node.generate(1) good_tip = node.getbestblockhash() + # avoid race condition from parking_node requesting block when invalid + wait_for_tip(parking_node, good_tip) + node.parkblock(bad_tip) self.only_valid_tip(tip, other_tip_status="parked") node.invalidateblock(bad_tip) @@ -95,6 +112,9 @@ node.generate(1) good_tip = node.getbestblockhash() + # avoid race condition from parking_node requesting block when invalid + wait_for_tip(parking_node, good_tip) + node.invalidateblock(bad_tip) self.only_valid_tip(tip, other_tip_status="invalid") node.parkblock(bad_tip) @@ -112,6 +132,9 @@ node.generate(1) good_tip = node.getbestblockhash() + # avoid race condition from parking_node requesting block when invalid + wait_for_tip(parking_node, good_tip) + node.parkblock(bad_tip) self.only_valid_tip(tip, other_tip_status="parked") node.invalidateblock(bad_tip) @@ -124,13 +147,7 @@ node.reconsiderblock(bad_tip) self.only_valid_tip(good_tip) - # First, make sure both nodes are in sync. - def wait_for_tip(node, tip): - def check_tip(): - return node.getbestblockhash() == tip - wait_until(check_tip) - - parking_node = self.nodes[1] + # To get ready for next testset, make sure both nodes are in sync. wait_for_tip(parking_node, good_tip) assert_equal(node.getbestblockhash(), parking_node.getbestblockhash())