MCPcopy Create free account
hub / github.com/ElementsProject/elements / mine_large_blocks

Function mine_large_blocks

test/functional/feature_pruning.py:32–73  ·  view source on GitHub ↗
(node, n)

Source from the content-addressed store, hash-verified

30TIMESTAMP_WINDOW = 2 * 60 * 60
31
32def 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
75def 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.)

Callers 4

create_big_chainMethod · 0.85
test_height_minMethod · 0.85
reorg_testMethod · 0.85

Calls 8

calc_merkle_rootMethod · 0.95
solveMethod · 0.95
serializeMethod · 0.95
CScriptClass · 0.90
create_coinbaseFunction · 0.90
CBlockClass · 0.90
hexMethod · 0.80
rehashMethod · 0.45

Tested by 1

test_height_minMethod · 0.68