Repository: Chia-Network/chia-blockchain
File: chia/full_node/coin_store.py (Python)

Code before:
        for coin in tx_additions:
            db_values_to_insert.append(
                (
                    coin.name(),
                    height,
                    0,
                    0,
                    coin.puzzle_hash,
                    coin.parent_coin_info,
                    coin.amount.stream_to_bytes(),
                    timestamp,
                )
            )

        if height == 0:
            assert len(included_reward_coins) == 0
        else:
            assert len(included_reward_coins) >= 2

        for coin in included_reward_coins:
            db_values_to_insert.append(
                (
                    coin.name(),
                    height,
                    0,
                    1,
                    coin.puzzle_hash,
                    coin.parent_coin_info,
                    coin.amount.stream_to_bytes(),
                    timestamp,
                )
            )

        async with self.db_wrapper.writer_maybe_transaction() as conn:
            await conn.executemany("INSERT INTO coin_record VALUES(?, ?, ?, ?, ?, ?, ?, ?)", db_values_to_insert)
        await self._set_spent(tx_removals, height)

        end = time.monotonic()
        log.log(
            logging.WARNING if end - start > 10 else logging.DEBUG,
            f"Height {height}: It took {end - start:0.2f}s to apply {len(tx_additions)} additions and "
            + f"{len(tx_removals)} removals to the coin store. Make sure "
            + "blockchain database is on a fast drive",
        )

    # Checks DB and DiffStores for CoinRecord with coin_name and returns it
    async def get_coin_record(self, coin_name: bytes32) -> Optional[CoinRecord]:
        async with self.db_wrapper.reader_no_transaction() as conn:
            async with conn.execute(
                "SELECT confirmed_index, spent_index, coinbase, puzzle_hash, "
                "coin_parent, amount, timestamp FROM coin_record WHERE coin_name=?",

Review comment (suggestion):
can you remove `_add_coin_records()` now? If it's only used by tests, it should be pulled out of the class

Code after:
        for coin in tx_additions:
            db_values_to_insert.append(
                (
                    coin.name(),
                    # confirmed_index
                    height,
                    # spent_index
                    0,
                    # coinbase
                    0,
                    coin.puzzle_hash,
                    coin.parent_coin_info,
                    coin.amount.stream_to_bytes(),
                    timestamp,
                )
            )

        if height == 0:
            assert len(included_reward_coins) == 0
        else:
            assert len(included_reward_coins) >= 2

        for coin in included_reward_coins:
            db_values_to_insert.append(
                (
                    coin.name(),
                    # confirmed_index
                    height,
                    # spent_index
                    0,
                    # coinbase
                    1,
                    coin.puzzle_hash,
                    coin.parent_coin_info,
                    coin.amount.stream_to_bytes(),
                    timestamp,
                )
            )

        async with self.db_wrapper.writer_maybe_transaction() as conn:
            await conn.executemany("INSERT INTO coin_record VALUES(?, ?, ?, ?, ?, ?, ?, ?)", db_values_to_insert)
        await self._set_spent(tx_removals, height)

        end = time.monotonic()
        log.log(
            logging.WARNING if end - start > 10 else logging.DEBUG,
            f"Height {height}: It took {end - start:0.2f}s to apply {len(tx_additions)} additions and "
            + f"{len(tx_removals)} removals to the coin store. Make sure "
            + "blockchain database is on a fast drive",
        )