| 1404 | self.import_deterministic_coinbase_privkeys() |
| 1405 | |
| 1406 | def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_weight=0, witness=False, accept=False): |
| 1407 | |
| 1408 | # Deplete block of any non-tapscript sigops using a single additional 0-value coinbase output. |
| 1409 | # It is not impossible to fit enough tapscript sigops to hit the old 80k limit without |
| 1410 | # busting txin-level limits. We simply have to account for the p2pk outputs in all |
| 1411 | # transactions. |
| 1412 | extra_output_script = CScript([OP_CHECKSIG]*((MAX_BLOCK_SIGOPS_WEIGHT - sigops_weight) // WITNESS_SCALE_FACTOR)) |
| 1413 | if extra_output_script == CScript(): |
| 1414 | extra_output_script = None ## ELEMENTS: an explicitly empty coinbase scriptpubkey would be rejected with bad-cb-fee |
| 1415 | |
| 1416 | coinbase_tx = create_coinbase(self.lastblockheight + 1, pubkey=cb_pubkey, extra_output_script=extra_output_script, fees=fees) |
| 1417 | block = create_block(self.tip, coinbase_tx, self.lastblocktime + 1, txlist=txs) |
| 1418 | witness and add_witness_commitment(block) |
| 1419 | block.solve() |
| 1420 | block_response = node.submitblock(block.serialize().hex()) |
| 1421 | if err_msg is not None: |
| 1422 | assert block_response is not None |
| 1423 | assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg) |
| 1424 | if accept: |
| 1425 | assert node.getbestblockhash() == block.hash, "Failed to accept: %s (response: %s)" % (msg, block_response) |
| 1426 | self.tip = block.sha256 |
| 1427 | self.lastblockhash = block.hash |
| 1428 | self.lastblocktime += 1 |
| 1429 | self.lastblockheight += 1 |
| 1430 | else: |
| 1431 | assert node.getbestblockhash() == self.lastblockhash, "Failed to reject: " + msg |
| 1432 | |
| 1433 | def init_blockinfo(self, node): |
| 1434 | # Initialize variables used by block_submit(). |