Skip to content

Commit f11a50f

Browse files
committed
update generate_chain to support new changes
correct spends and additions amounts
1 parent 8ee0147 commit f11a50f

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

tools/generate_chain.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import click
1414
import zstd
15-
from chia_rs import SpendBundle
15+
from chia_rs.sized_bytes import bytes32
1616
from chia_rs.sized_ints import uint32, uint64
1717

1818
from chia._tests.util.constants import test_constants
@@ -83,6 +83,11 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
8383
initialize_logging(
8484
"generate_chain", {"log_level": "DEBUG", "log_stdout": False, "log_syslog": False}, root_path=root_path
8585
)
86+
farmer_puzzlehash: bytes32 = bt.farmer_ph
87+
pool_puzzlehash: bytes32 = bt.farmer_ph
88+
unspent_coins: set[Coin] = bt.available_coins
89+
num_spends: int = bt.prev_num_spends
90+
num_additions: int = bt.prev_num_additions
8691

8792
print(f"writing blockchain to {output}")
8893
with closing(sqlite3.connect(output)) as db:
@@ -95,9 +100,6 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
95100
"block blob)"
96101
)
97102

98-
wallet = bt.get_farmer_wallet_tool()
99-
farmer_puzzlehash = wallet.get_new_puzzlehash()
100-
pool_puzzlehash = wallet.get_new_puzzlehash()
101103
transaction_blocks: list[uint32] = []
102104

103105
blocks = bt.get_consecutive_blocks(
@@ -108,12 +110,7 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
108110
genesis_timestamp=uint64(1234567890),
109111
)
110112

111-
unspent_coins: list[Coin] = []
112-
113113
for b in blocks:
114-
for coin in b.get_included_reward_coins():
115-
if coin.puzzle_hash in {farmer_puzzlehash, pool_puzzlehash}:
116-
unspent_coins.append(coin)
117114
db.execute(
118115
"INSERT INTO full_blocks VALUES(?, ?, ?, ?, ?)",
119116
(
@@ -128,41 +125,26 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
128125

129126
b = blocks[-1]
130127

131-
num_tx_per_block = int(1010 * fill_rate / 100)
132-
133128
while True:
134129
with enable_profiler(profile, b.height):
135130
start_time = time.monotonic()
136131

137-
new_coins: list[Coin] = []
138-
spend_bundles: list[SpendBundle] = []
139-
i = 0
140-
for i in range(num_tx_per_block):
141-
if unspent_coins == []:
142-
break
143-
c = unspent_coins.pop(random.randrange(len(unspent_coins)))
144-
receiver = wallet.get_new_puzzlehash()
145-
bundle = wallet.generate_signed_transaction(uint64(c.amount // 2), receiver, c)
146-
new_coins.extend(bundle.additions())
147-
spend_bundles.append(bundle)
148-
149132
block_references: list[uint32]
150133
if block_refs:
151134
block_references = random.sample(transaction_blocks, min(len(transaction_blocks), 512))
152135
random.shuffle(block_references)
153136
else:
154137
block_references = []
155138

156-
farmer_puzzlehash = wallet.get_new_puzzlehash()
157-
pool_puzzlehash = wallet.get_new_puzzlehash()
158139
prev_num_blocks = len(blocks)
159140
blocks = bt.get_consecutive_blocks(
160141
1,
161142
blocks,
162143
farmer_reward_puzzle_hash=farmer_puzzlehash,
163144
pool_reward_puzzle_hash=pool_puzzlehash,
164145
keep_going_until_tx_block=True,
165-
transaction_data=SpendBundle.aggregate(spend_bundles),
146+
include_transactions=True,
147+
block_fillrate=fill_rate,
166148
block_refs=block_references,
167149
)
168150
prev_tx_block = b
@@ -171,11 +153,8 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
171153
height = b.height
172154
assert b.is_transaction_block()
173155
transaction_blocks.append(height)
174-
175-
for bl in blocks[prev_num_blocks:]:
176-
for coin in bl.get_included_reward_coins():
177-
unspent_coins.append(coin)
178-
unspent_coins.extend(new_coins)
156+
num_spends += bt.prev_num_spends
157+
num_additions += bt.prev_num_additions
179158

180159
if b.transactions_info:
181160
actual_fill_rate = b.transactions_info.cost / test_constants.MAX_BLOCK_COST_CLVM
@@ -194,10 +173,10 @@ def main(length: int, fill_rate: int, profile: bool, block_refs: bool, output: O
194173

195174
print(
196175
f"height: {b.height} "
197-
f"spends: {i + 1} "
176+
f"spends: {num_spends} "
198177
f"refs: {len(block_references)} "
199178
f"fill_rate: {actual_fill_rate * 100:.1f}% "
200-
f"new coins: {len(new_coins)} "
179+
f"new coins: {num_additions} "
201180
f"unspent: {len(unspent_coins)} "
202181
f"difficulty: {b.weight - prev_block.weight} "
203182
f"timestamp: {ts} "

0 commit comments

Comments
 (0)