|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2015-2018 The Dash Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +from test_framework.mininode import * |
| 7 | +from test_framework.test_framework import DashTestFramework |
| 8 | +from test_framework.util import sync_blocks, set_node_times, \ |
| 9 | + isolate_node, reconnect_isolated_node |
| 10 | + |
| 11 | +''' |
| 12 | +llmq-is-retroactive.py |
| 13 | +
|
| 14 | +Tests retroactive signing |
| 15 | +
|
| 16 | +We have 6 nodes where node 0 is the control node, nodes 1-5 are masternodes. |
| 17 | +Mempool inconsistencies are simulated via disconnecting/reconnecting node 3 |
| 18 | +and by having a higher relay fee on nodes 4 and 5. |
| 19 | +''' |
| 20 | + |
| 21 | +class LLMQ_IS_RetroactiveSigning(DashTestFramework): |
| 22 | + def set_test_params(self): |
| 23 | + # -whitelist is needed to avoid the trickling logic on node0 |
| 24 | + self.set_dash_test_params(6, 5, [["-whitelist=127.0.0.1"], [], [], [], ["-minrelaytxfee=0.001"], ["-minrelaytxfee=0.001"]], fast_dip3_enforcement=True) |
| 25 | + |
| 26 | + def run_test(self): |
| 27 | + while self.nodes[0].getblockchaininfo()["bip9_softforks"]["dip0008"]["status"] != "active": |
| 28 | + self.nodes[0].generate(10) |
| 29 | + sync_blocks(self.nodes, timeout=60*5) |
| 30 | + |
| 31 | + self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0) |
| 32 | + self.nodes[0].spork("SPORK_19_CHAINLOCKS_ENABLED", 0) |
| 33 | + self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0) |
| 34 | + self.nodes[0].spork("SPORK_3_INSTANTSEND_BLOCK_FILTERING", 0) |
| 35 | + self.wait_for_sporks_same() |
| 36 | + |
| 37 | + self.mine_quorum() |
| 38 | + self.mine_quorum() |
| 39 | + |
| 40 | + # Make sure that all nodes are chainlocked at the same height before starting actual tests |
| 41 | + self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) |
| 42 | + |
| 43 | + self.log.info("trying normal IS lock") |
| 44 | + txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
| 45 | + # 3 nodes should be enough to create an IS lock even if nodes 4 and 5 (which have no tx itself) |
| 46 | + # are the only "neighbours" in intra-quorum connections for one of them. |
| 47 | + self.wait_for_instantlock(txid, self.nodes[0]) |
| 48 | + self.bump_mocktime(1) |
| 49 | + set_node_times(self.nodes, self.mocktime) |
| 50 | + block = self.nodes[0].generate(1)[0] |
| 51 | + self.wait_for_chainlocked_block_all_nodes(block) |
| 52 | + |
| 53 | + self.log.info("testing normal signing with partially known TX") |
| 54 | + isolate_node(self.nodes[3]) |
| 55 | + txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
| 56 | + # Make sure nodes 1 and 2 received the TX before we continue, |
| 57 | + # otherwise it might announce the TX to node 3 when reconnecting |
| 58 | + self.wait_for_tx(txid, self.nodes[1]) |
| 59 | + self.wait_for_tx(txid, self.nodes[2]) |
| 60 | + reconnect_isolated_node(self.nodes[3], 0) |
| 61 | + self.wait_for_mnauth(self.nodes[3], 2) |
| 62 | + # node 3 fully reconnected but the TX wasn't relayed to it, so there should be no IS lock |
| 63 | + self.wait_for_instantlock(txid, self.nodes[0], False, 5) |
| 64 | + # push the tx directly via rpc |
| 65 | + self.nodes[3].sendrawtransaction(self.nodes[0].getrawtransaction(txid)) |
| 66 | + # node 3 should vote on a tx now since it became aware of it via sendrawtransaction |
| 67 | + # and this should be enough to complete an IS lock |
| 68 | + self.wait_for_instantlock(txid, self.nodes[0]) |
| 69 | + |
| 70 | + self.log.info("testing retroactive signing with unknown TX") |
| 71 | + isolate_node(self.nodes[3]) |
| 72 | + rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1}) |
| 73 | + rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex'] |
| 74 | + rawtx = self.nodes[0].signrawtransaction(rawtx)['hex'] |
| 75 | + txid = self.nodes[3].sendrawtransaction(rawtx) |
| 76 | + # Make node 3 consider the TX as safe |
| 77 | + self.bump_mocktime(10 * 60 + 1) |
| 78 | + set_node_times(self.nodes, self.mocktime) |
| 79 | + block = self.nodes[3].generatetoaddress(1, self.nodes[0].getnewaddress())[0] |
| 80 | + reconnect_isolated_node(self.nodes[3], 0) |
| 81 | + self.wait_for_chainlocked_block_all_nodes(block) |
| 82 | + self.nodes[0].setmocktime(self.mocktime) |
| 83 | + |
| 84 | + self.log.info("testing retroactive signing with partially known TX") |
| 85 | + isolate_node(self.nodes[3]) |
| 86 | + txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
| 87 | + # Make sure nodes 1 and 2 received the TX before we continue, |
| 88 | + # otherwise it might announce the TX to node 3 when reconnecting |
| 89 | + self.wait_for_tx(txid, self.nodes[1]) |
| 90 | + self.wait_for_tx(txid, self.nodes[2]) |
| 91 | + reconnect_isolated_node(self.nodes[3], 0) |
| 92 | + self.wait_for_mnauth(self.nodes[3], 2) |
| 93 | + # node 3 fully reconnected but the TX wasn't relayed to it, so there should be no IS lock |
| 94 | + self.wait_for_instantlock(txid, self.nodes[0], False, 5) |
| 95 | + # Make node0 consider the TX as safe |
| 96 | + self.bump_mocktime(10 * 60 + 1) |
| 97 | + set_node_times(self.nodes, self.mocktime) |
| 98 | + block = self.nodes[0].generate(1)[0] |
| 99 | + self.wait_for_chainlocked_block_all_nodes(block) |
| 100 | + |
| 101 | + self.log.info("testing retroactive signing with partially known TX and all nodes session timeout") |
| 102 | + self.test_all_nodes_session_timeout(False) |
| 103 | + self.log.info("repeating test, but with cycled LLMQs") |
| 104 | + self.test_all_nodes_session_timeout(True) |
| 105 | + |
| 106 | + self.log.info("testing retroactive signing with partially known TX and single node session timeout") |
| 107 | + self.test_single_node_session_timeout(False) |
| 108 | + self.log.info("repeating test, but with cycled LLMQs") |
| 109 | + self.test_single_node_session_timeout(True) |
| 110 | + |
| 111 | + def cycle_llmqs(self): |
| 112 | + self.mine_quorum() |
| 113 | + self.mine_quorum() |
| 114 | + self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) |
| 115 | + |
| 116 | + def test_all_nodes_session_timeout(self, do_cycle_llmqs): |
| 117 | + set_node_times(self.nodes, self.mocktime) |
| 118 | + isolate_node(self.nodes[3]) |
| 119 | + rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1}) |
| 120 | + rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex'] |
| 121 | + rawtx = self.nodes[0].signrawtransaction(rawtx)['hex'] |
| 122 | + txid = self.nodes[0].sendrawtransaction(rawtx) |
| 123 | + txid = self.nodes[3].sendrawtransaction(rawtx) |
| 124 | + # Make sure nodes 1 and 2 received the TX before we continue |
| 125 | + self.wait_for_tx(txid, self.nodes[1]) |
| 126 | + self.wait_for_tx(txid, self.nodes[2]) |
| 127 | + # Make sure signing is done on nodes 1 and 2 (it's async) |
| 128 | + time.sleep(5) |
| 129 | + # Make the signing session for the IS lock timeout on nodes 1-3 |
| 130 | + self.bump_mocktime(61) |
| 131 | + set_node_times(self.nodes, self.mocktime) |
| 132 | + time.sleep(2) # make sure Cleanup() is called |
| 133 | + reconnect_isolated_node(self.nodes[3], 0) |
| 134 | + self.wait_for_mnauth(self.nodes[3], 2) |
| 135 | + # node 3 fully reconnected but the signing session is already timed out on all nodes, so no IS lock |
| 136 | + self.wait_for_instantlock(txid, self.nodes[0], False, 5) |
| 137 | + if do_cycle_llmqs: |
| 138 | + self.cycle_llmqs() |
| 139 | + self.wait_for_instantlock(txid, self.nodes[0], False, 5) |
| 140 | + # Make node 0 consider the TX as safe |
| 141 | + self.bump_mocktime(10 * 60 + 1) |
| 142 | + self.nodes[0].setmocktime(self.mocktime) |
| 143 | + block = self.nodes[0].generate(1)[0] |
| 144 | + self.wait_for_chainlocked_block_all_nodes(block) |
| 145 | + |
| 146 | + def test_single_node_session_timeout(self, do_cycle_llmqs): |
| 147 | + set_node_times(self.nodes, self.mocktime) |
| 148 | + isolate_node(self.nodes[3]) |
| 149 | + rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1}) |
| 150 | + rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex'] |
| 151 | + rawtx = self.nodes[0].signrawtransaction(rawtx)['hex'] |
| 152 | + txid = self.nodes[3].sendrawtransaction(rawtx) |
| 153 | + time.sleep(2) # make sure signing is done on node 2 (it's async) |
| 154 | + # Make the signing session for the IS lock timeout on node 3 |
| 155 | + self.bump_mocktime(61) |
| 156 | + set_node_times(self.nodes, self.mocktime) |
| 157 | + time.sleep(2) # make sure Cleanup() is called |
| 158 | + reconnect_isolated_node(self.nodes[3], 0) |
| 159 | + self.wait_for_mnauth(self.nodes[3], 2) |
| 160 | + self.nodes[0].sendrawtransaction(rawtx) |
| 161 | + # Make sure nodes 1 and 2 received the TX |
| 162 | + self.wait_for_tx(txid, self.nodes[1]) |
| 163 | + self.wait_for_tx(txid, self.nodes[2]) |
| 164 | + # Make sure signing is done on nodes 1 and 2 (it's async) |
| 165 | + time.sleep(5) |
| 166 | + # node 3 fully reconnected but the signing session is already timed out on it, so no IS lock |
| 167 | + self.wait_for_instantlock(txid, self.nodes[0], False, 1) |
| 168 | + if do_cycle_llmqs: |
| 169 | + self.cycle_llmqs() |
| 170 | + self.wait_for_instantlock(txid, self.nodes[0], False, 5) |
| 171 | + # Make node 0 consider the TX as safe |
| 172 | + self.bump_mocktime(10 * 60 + 1) |
| 173 | + self.nodes[0].setmocktime(self.mocktime) |
| 174 | + block = self.nodes[0].generate(1)[0] |
| 175 | + self.wait_for_chainlocked_block_all_nodes(block) |
| 176 | + |
| 177 | +if __name__ == '__main__': |
| 178 | + LLMQ_IS_RetroactiveSigning().main() |
0 commit comments