Repository: Chia-Network/chia-blockchain
File: chia/_tests/util/spend_sim.py (Python)

Code before:
    async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[list[Coin], list[Coin]]:
        # Fees get calculated
        fees = uint64(0)
        for item in self.mempool_manager.mempool.all_items():
            fees = uint64(fees + item.fee)

        # Rewards get created
        next_block_height: uint32 = uint32(self.block_height + 1) if len(self.block_records) > 0 else self.block_height
        included_reward_coins = [
            create_pool_coin(
                next_block_height,
                puzzle_hash,
                calculate_pool_reward(next_block_height),
                self.defaults.GENESIS_CHALLENGE,
            ),
            create_farmer_coin(
                next_block_height,
                puzzle_hash,
                uint64(calculate_base_farmer_reward(next_block_height) + fees),
                self.defaults.GENESIS_CHALLENGE,
            ),
        ]
        # Coin store gets updated
        generator_bundle: Optional[SpendBundle] = None
        tx_additions = []
        return_removals: list[Coin] = []
        spent_coins_ids = None
        if (len(self.block_records) > 0) and (self.mempool_manager.mempool.size() > 0):
            peak = self.mempool_manager.peak
            if peak is not None:
                result = self.mempool_manager.create_bundle_from_mempool(last_tb_header_hash=peak.header_hash)
                if result is not None:
                    bundle, additions = result
                    generator_bundle = bundle
                    spent_coins_ids = []
                    for spend in generator_bundle.coin_spends:
                        hint_dict, _ = compute_spend_hints_and_additions(spend)
                        hints: list[tuple[bytes32, bytes]] = []
                        hint_obj: HintedCoin
                        for coin_name, hint_obj in hint_dict.items():
                            if hint_obj.hint is not None:
                                hints.append((coin_name, bytes(hint_obj.hint)))
                        await self.hint_store.add_hints(hints)
                        spent_coins_ids.append(spend.coin.name())
                        return_removals.append(spend.coin)
                    tx_additions = additions
        await self.coin_store.new_block(
            height=uint32(self.block_height + 1),
            timestamp=self.timestamp,
            included_reward_coins=included_reward_coins,
            tx_additions=tx_additions,

Review comment (suggestion):
```suggestion
        additions = []
        removals = []
```

It looks like you could just call this `additions` and have it be assigned if there is a block.

Code after:
    async def farm_block(self, puzzle_hash: bytes32 = bytes32(b"0" * 32)) -> tuple[list[Coin], list[Coin]]:
        # Fees get calculated
        fees = uint64(0)
        for item in self.mempool_manager.mempool.all_items():
            fees = uint64(fees + item.fee)

        # Rewards get created
        next_block_height: uint32 = uint32(self.block_height + 1) if len(self.block_records) > 0 else self.block_height
        included_reward_coins = [
            create_pool_coin(
                next_block_height,
                puzzle_hash,
                calculate_pool_reward(next_block_height),
                self.defaults.GENESIS_CHALLENGE,
            ),
            create_farmer_coin(
                next_block_height,
                puzzle_hash,
                uint64(calculate_base_farmer_reward(next_block_height) + fees),
                self.defaults.GENESIS_CHALLENGE,
            ),
        ]
        # Coin store gets updated
        generator_bundle: Optional[SpendBundle] = None
        tx_additions = []
        tx_removals = []
        spent_coins_ids = None
        if (len(self.block_records) > 0) and (self.mempool_manager.mempool.size() > 0):
            peak = self.mempool_manager.peak
            if peak is not None:
                result = self.mempool_manager.create_bundle_from_mempool(last_tb_header_hash=peak.header_hash)
                if result is not None:
                    bundle, additions = result
                    generator_bundle = bundle
                    spent_coins_ids = []
                    for spend in generator_bundle.coin_spends:
                        hint_dict, _ = compute_spend_hints_and_additions(spend)
                        hints: list[tuple[bytes32, bytes]] = []
                        hint_obj: HintedCoin
                        for coin_name, hint_obj in hint_dict.items():
                            if hint_obj.hint is not None:
                                hints.append((coin_name, bytes(hint_obj.hint)))
                        await self.hint_store.add_hints(hints)
                        spent_coins_ids.append(spend.coin.name())
                        tx_removals.append(spend.coin)
                    tx_additions = additions
        await self.coin_store.new_block(
            height=uint32(self.block_height + 1),
            timestamp=self.timestamp,
            included_reward_coins=included_reward_coins,
            tx_additions=tx_additions,