(self, make_transactions)
| 96 | assert_equal(n.getblockcount(), expected_height) |
| 97 | |
| 98 | def mine_block(self, make_transactions): |
| 99 | # mine block in round robin sense: depending on the block number, a node |
| 100 | # is selected to create the block, others sign it and the selected node |
| 101 | # broadcasts it |
| 102 | mineridx = self.nodes[0].getblockcount() % self.num_nodes # assuming in sync |
| 103 | mineridx_next = (self.nodes[0].getblockcount() + 1) % self.num_nodes |
| 104 | miner = self.nodes[mineridx] |
| 105 | miner_next = self.nodes[mineridx_next] |
| 106 | blockcount = miner.getblockcount() |
| 107 | |
| 108 | # If dynafed is enabled, this means signblockscript has been WSH-wrapped |
| 109 | deployment_info = self.nodes[0].getdeploymentinfo() |
| 110 | is_dyna = deployment_info['deployments']['dynafed']['bip9']['status'] == "active" |
| 111 | if is_dyna: |
| 112 | wsh_wrap = self.nodes[0].decodescript(self.witnessScript)['segwit']['hex'] |
| 113 | assert_equal(wsh_wrap, self.nodes[0].getblockchaininfo()['current_signblock_hex']) |
| 114 | |
| 115 | # Make a few transactions to make non-empty blocks for compact transmission |
| 116 | if make_transactions: |
| 117 | for i in range(20): |
| 118 | miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()['bitcoin']/10), "", "", True) |
| 119 | # miner makes a block |
| 120 | block = miner.getnewblockhex() |
| 121 | block_struct = from_hex(CBlock(), block) |
| 122 | |
| 123 | # make another block with the commitment field filled out |
| 124 | dummy_block = miner.getnewblockhex(commit_data="deadbeef") |
| 125 | dummy_struct = from_hex(CBlock(), dummy_block) |
| 126 | assert_equal(len(dummy_struct.vtx[0].vout), len(block_struct.vtx[0].vout) + 1) |
| 127 | # OP_RETURN deadbeef |
| 128 | assert_equal(CScript(dummy_struct.vtx[0].vout[0].scriptPubKey).hex(), '6a04deadbeef') |
| 129 | |
| 130 | # All nodes get compact blocks, first node may get complete |
| 131 | # block in 0.5 RTT even with transactions thanks to p2p connection |
| 132 | # with non-signing node being miner |
| 133 | for i in range(self.num_keys): |
| 134 | if i == mineridx: |
| 135 | continue |
| 136 | sketch = miner.getcompactsketch(block) |
| 137 | compact_response = self.nodes[i].consumecompactsketch(sketch) |
| 138 | if "block_tx_req" in compact_response: |
| 139 | block_txn = self.nodes[i].consumegetblocktxn(block, compact_response["block_tx_req"]) |
| 140 | final_block = self.nodes[i].finalizecompactblock(sketch, block_txn, compact_response["found_transactions"]) |
| 141 | else: |
| 142 | assert (mineridx == 4 and i == 0) or not make_transactions |
| 143 | # If there's only coinbase, it should succeed immediately |
| 144 | final_block = compact_response["blockhex"] |
| 145 | # Block should be complete, sans signatures |
| 146 | self.nodes[i].testproposedblock(final_block) |
| 147 | |
| 148 | # non-signing node can not sign |
| 149 | assert_raises_rpc_error(-25, "Could not sign the block.", self.nodes[-1].signblock, block, self.witnessScript) |
| 150 | |
| 151 | # collect num_keys signatures from signers, reduce to required_signers sigs during combine |
| 152 | sigs = [] |
| 153 | for i in range(self.num_keys): |
| 154 | result = miner.combineblocksigs(block, sigs, self.witnessScript) |
| 155 | sigs = sigs + self.nodes[i].signblock(block, self.witnessScript) |
no test coverage detected