| 30 | TIMESTAMP_WINDOW = 2 * 60 * 60 |
| 31 | |
| 32 | def mine_large_blocks(node, n): |
| 33 | # Make a large scriptPubKey for the coinbase transaction. This is OP_RETURN |
| 34 | # followed by 950k of OP_NOP. This would be non-standard in a non-coinbase |
| 35 | # transaction but is consensus valid. |
| 36 | |
| 37 | # Set the nTime if this is the first time this function has been called. |
| 38 | # A static variable ensures that time is monotonicly increasing and is therefore |
| 39 | # different for each block created => blockhash is unique. |
| 40 | if "nTimes" not in mine_large_blocks.__dict__: |
| 41 | mine_large_blocks.nTime = 0 |
| 42 | |
| 43 | # Get the block parameters for the first block |
| 44 | big_script = CScript([OP_RETURN] + [OP_NOP] * 950000) |
| 45 | best_block = node.getblock(node.getbestblockhash()) |
| 46 | height = int(best_block["height"]) + 1 |
| 47 | mine_large_blocks.nTime = max(mine_large_blocks.nTime, int(best_block["time"])) + 1 |
| 48 | previousblockhash = int(best_block["hash"], 16) |
| 49 | |
| 50 | for _ in range(n): |
| 51 | # Build the coinbase transaction (with large scriptPubKey) |
| 52 | coinbase_tx = create_coinbase(height) |
| 53 | coinbase_tx.vin[0].nSequence = 2 ** 32 - 1 |
| 54 | coinbase_tx.vout[0].scriptPubKey = big_script |
| 55 | coinbase_tx.rehash() |
| 56 | |
| 57 | # Build the block |
| 58 | block = CBlock() |
| 59 | block.nVersion = best_block["version"] |
| 60 | block.hashPrevBlock = previousblockhash |
| 61 | block.nTime = mine_large_blocks.nTime |
| 62 | block.nBits = int('207fffff', 16) |
| 63 | block.nNonce = 0 |
| 64 | block.vtx = [coinbase_tx] |
| 65 | block.hashMerkleRoot = block.calc_merkle_root() |
| 66 | block.solve() |
| 67 | |
| 68 | # Submit to the node |
| 69 | node.submitblock(block.serialize().hex()) |
| 70 | |
| 71 | previousblockhash = block.sha256 |
| 72 | height += 1 |
| 73 | mine_large_blocks.nTime += 1 |
| 74 | |
| 75 | def calc_usage(blockdir): |
| 76 | return sum(os.path.getsize(blockdir + f) for f in os.listdir(blockdir) if os.path.isfile(os.path.join(blockdir, f))) / (1024. * 1024.) |