Skip to content

Commit 83a85b8

Browse files
authored
CHIA-3173 Leverage CoinStore's new_block in SpendSim's farm_block instead of custom coin store manipulation (#19729)
Leverage CoinStore's new_block in SpendSim's farm_block instead of custom coin store manipulation.
1 parent 6969867 commit 83a85b8

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

chia/_tests/util/spend_sim.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from chia_rs.sized_ints import uint32, uint64
2424
from typing_extensions import Self
2525

26-
from chia._tests.util.coin_store import add_coin_records_to_db
2726
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
2827
from chia.consensus.coinbase import create_farmer_coin, create_pool_coin
2928
from chia.consensus.default_constants import DEFAULT_CONSTANTS
@@ -243,22 +242,20 @@ async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[l
243242

244243
# Rewards get created
245244
next_block_height: uint32 = uint32(self.block_height + 1) if len(self.block_records) > 0 else self.block_height
246-
pool_coin: Coin = create_pool_coin(
247-
next_block_height,
248-
puzzle_hash,
249-
calculate_pool_reward(next_block_height),
250-
self.defaults.GENESIS_CHALLENGE,
251-
)
252-
farmer_coin: Coin = create_farmer_coin(
253-
next_block_height,
254-
puzzle_hash,
255-
uint64(calculate_base_farmer_reward(next_block_height) + fees),
256-
self.defaults.GENESIS_CHALLENGE,
257-
)
258-
await add_coin_records_to_db(
259-
self.coin_store.db_wrapper, [self.new_coin_record(pool_coin, True), self.new_coin_record(farmer_coin, True)]
260-
)
261-
245+
included_reward_coins = [
246+
create_pool_coin(
247+
next_block_height,
248+
puzzle_hash,
249+
calculate_pool_reward(next_block_height),
250+
self.defaults.GENESIS_CHALLENGE,
251+
),
252+
create_farmer_coin(
253+
next_block_height,
254+
puzzle_hash,
255+
uint64(calculate_base_farmer_reward(next_block_height) + fees),
256+
self.defaults.GENESIS_CHALLENGE,
257+
),
258+
]
262259
# Coin store gets updated
263260
generator_bundle: Optional[SpendBundle] = None
264261
return_additions: list[Coin] = []
@@ -282,20 +279,16 @@ async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[l
282279
return_additions = additions
283280
return_removals = bundle.removals()
284281
spent_coins_ids = [r.name() for r in return_removals]
285-
await add_coin_records_to_db(
286-
self.coin_store.db_wrapper, [self.new_coin_record(addition) for addition in additions]
287-
)
288-
await self.coin_store._set_spent(spent_coins_ids, uint32(self.block_height + 1))
289-
282+
await self.coin_store.new_block(
283+
height=uint32(self.block_height + 1),
284+
timestamp=self.timestamp,
285+
included_reward_coins=included_reward_coins,
286+
tx_additions=return_additions,
287+
tx_removals=spent_coins_ids if spent_coins_ids is not None else [],
288+
)
290289
# SimBlockRecord is created
291290
generator: Optional[BlockGenerator] = await self.generate_transaction_generator(generator_bundle)
292-
self.block_records.append(
293-
SimBlockRecord.create(
294-
[pool_coin, farmer_coin],
295-
next_block_height,
296-
self.timestamp,
297-
)
298-
)
291+
self.block_records.append(SimBlockRecord.create(included_reward_coins, next_block_height, self.timestamp))
299292
self.blocks.append(SimFullBlock(generator, next_block_height))
300293

301294
# block_height is incremented

0 commit comments

Comments
 (0)