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

Code before:
                        spend_id = spend.coin.name()
                        spent_coins[spend_id] = spend.coin
                        spent_coins_ids.append(spend_id)
                        tx_removals.append(spend.coin)
                    for addition in additions:
                        same_as_parent = (
                            addition.amount % 2 == 1
                            and addition.parent_coin_info in spent_coins
                            and addition.puzzle_hash == spent_coins[addition.parent_coin_info].puzzle_hash
                            and addition.amount == spent_coins[addition.parent_coin_info].amount
                        )
                        tx_additions.append((addition.name(), addition, same_as_parent))
        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,
            tx_removals=spent_coins_ids if spent_coins_ids is not None else [],
        )
        # SimBlockRecord is created
        generator: Optional[BlockGenerator] = await self.generate_transaction_generator(generator_bundle)
        self.block_records.append(SimBlockRecord.create(included_reward_coins, next_block_height, self.timestamp))
        self.blocks.append(SimFullBlock(generator, next_block_height))

        # block_height is incremented
        self.block_height = next_block_height

        # mempool is reset
        await self.new_peak(spent_coins_ids)

        # return some debugging data
        return [a for _, a, _ in tx_additions], tx_removals

    def get_height(self) -> uint32:
        return self.block_height

    def pass_time(self, time: uint64) -> None:
        self.timestamp = uint64(self.timestamp + time)

    def pass_blocks(self, blocks: uint32) -> None:
        self.block_height = uint32(self.block_height + blocks)

    async def rewind(self, block_height: uint32) -> None:
        new_br_list = list(filter(lambda br: br.height <= block_height, self.block_records))
        new_block_list = list(filter(lambda block: block.height <= block_height, self.blocks))
        self.block_records = new_br_list
        self.blocks = new_block_list
        await self.coin_store.rollback_to_block(block_height)
        old_pool = self.mempool_manager.mempool
        self.mempool_manager.mempool = Mempool(old_pool.mempool_info, old_pool.fee_estimator)
        self.block_height = block_height

Review comment (suggestion):
it seems that you don't need `spent_coins_ids` anymore, now that you have `spent_coins`. I would think this could just be:
```suggestion
        await self.new_peak(spent_coins.keys())
```

Code after:
                        spend_id = spend.coin.name()
                        spent_coins[spend_id] = spend.coin
                        spent_coins_ids.append(spend_id)
                        tx_removals.append(spend.coin)
                    for child in additions:
                        parent = spent_coins.get(child.parent_coin_info)
                        assert parent is not None
                        same_as_parent = child.puzzle_hash == parent.puzzle_hash and child.amount == parent.amount
                        tx_additions.append((child.name(), child, same_as_parent))
        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,
            tx_removals=spent_coins_ids if spent_coins_ids is not None else [],
        )
        # SimBlockRecord is created
        generator: Optional[BlockGenerator] = await self.generate_transaction_generator(generator_bundle)
        self.block_records.append(SimBlockRecord.create(included_reward_coins, next_block_height, self.timestamp))
        self.blocks.append(SimFullBlock(generator, next_block_height))

        # block_height is incremented
        self.block_height = next_block_height

        # mempool is reset
        await self.new_peak(spent_coins_ids)

        # return some debugging data
        return [a for _, a, _ in tx_additions], tx_removals

    def get_height(self) -> uint32:
        return self.block_height

    def pass_time(self, time: uint64) -> None:
        self.timestamp = uint64(self.timestamp + time)

    def pass_blocks(self, blocks: uint32) -> None:
        self.block_height = uint32(self.block_height + blocks)

    async def rewind(self, block_height: uint32) -> None:
        new_br_list = list(filter(lambda br: br.height <= block_height, self.block_records))
        new_block_list = list(filter(lambda block: block.height <= block_height, self.blocks))
        self.block_records = new_br_list
        self.blocks = new_block_list
        await self.coin_store.rollback_to_block(block_height)
        old_pool = self.mempool_manager.mempool
        self.mempool_manager.mempool = Mempool(old_pool.mempool_info, old_pool.fee_estimator)
        self.block_height = block_height
        if new_br_list:
            self.timestamp = new_br_list[-1].timestamp
        else: