Repository: Chia-Network/chia-blockchain
File: chia/consensus/block_body_validation.py (Python)

Code before:
        """Updates `self` with `block`'s height and `header_hash`."""
        assert self.peak_height == block.height - 1
        assert len(self.block_hashes) == self.peak_height - self.fork_height
        assert block.height == self.fork_height + 1 + len(self.block_hashes)
        self.block_hashes.append(header_hash)
        self.peak_height = int(block.height)
        self.peak_hash = header_hash

    def include_reward_coins(self, block: FullBlock) -> None:
        """Updates `self` with `block`'s reward coins."""
        for coin in block.get_included_reward_coins():
            assert block.foliage_transaction_block is not None
            timestamp = block.foliage_transaction_block.timestamp
            coin_id = coin.name()
            assert coin_id not in self.additions_since_fork
            self.additions_since_fork[coin_id] = ForkAdd(coin, block.height, timestamp, None, True, False)

    def include_spends(self, conds: Optional[SpendBundleConditions], block: FullBlock, header_hash: bytes32) -> None:
        self.update_fork_peak(block, header_hash)
        if conds is not None:
            assert block.foliage_transaction_block is not None
            timestamp = block.foliage_transaction_block.timestamp
            for spend in conds.spends:
                spend_coin_id = bytes32(spend.coin_id)
                spend_ph = bytes32(spend.puzzle_hash)
                self.removals_since_fork[spend_coin_id] = ForkRem(spend_ph, block.height)
                # We're only relying on this flag here to tells us that the
                # coin has the same puzzle hash and amount as its parent and
                # the amount is odd (among other things).
                spend_same_as_parent = bool(spend.flags & ELIGIBLE_FOR_FF)
                for puzzle_hash, amount, hint in spend.create_coin:
                    child_ph = bytes32(puzzle_hash)
                    child_amount = uint64(amount)
                    child_coin = Coin(spend_coin_id, child_ph, child_amount)
                    child_coin_id = child_coin.name()
                    same_as_parent = (
                        spend_same_as_parent
                        and child_coin.puzzle_hash == spend.puzzle_hash
                        and amount == spend.coin_amount
                    )
                    self.additions_since_fork[child_coin_id] = ForkAdd(
                        child_coin, block.height, timestamp, hint, False, same_as_parent
                    )
        self.include_reward_coins(block)

    def include_block(
        self,
        additions: list[tuple[Coin, Optional[bytes]]],
        removals: list[Coin],
        block: FullBlock,
        header_hash: bytes32,

Review comment (suggestion):
I don't think you need to give this a name. This change is unrelated to the essence of this PR and, I think, makes it harder to read. I would say the same thing about `spend_ph`. It adds changes to the diff, even though it's not a material change. I don't believe these compute any hashes.

Code after:
        """Updates `self` with `block`'s height and `header_hash`."""
        assert self.peak_height == block.height - 1
        assert len(self.block_hashes) == self.peak_height - self.fork_height
        assert block.height == self.fork_height + 1 + len(self.block_hashes)
        self.block_hashes.append(header_hash)
        self.peak_height = int(block.height)
        self.peak_hash = header_hash

    def include_reward_coins(self, block: FullBlock) -> None:
        """Updates `self` with `block`'s reward coins."""
        for coin in block.get_included_reward_coins():
            assert block.foliage_transaction_block is not None
            timestamp = block.foliage_transaction_block.timestamp
            coin_id = coin.name()
            assert coin_id not in self.additions_since_fork
            self.additions_since_fork[coin_id] = ForkAdd(
                coin, block.height, timestamp, hint=None, is_coinbase=True, same_as_parent=False
            )

    def include_spends(self, conds: Optional[SpendBundleConditions], block: FullBlock, header_hash: bytes32) -> None:
        self.update_fork_peak(block, header_hash)
        if conds is not None:
            assert block.foliage_transaction_block is not None
            timestamp = block.foliage_transaction_block.timestamp
            for spend in conds.spends:
                spend_coin_id = bytes32(spend.coin_id)
                self.removals_since_fork[spend_coin_id] = ForkRem(bytes32(spend.puzzle_hash), block.height)
                for puzzle_hash, amount, hint in spend.create_coin:
                    coin = Coin(spend_coin_id, bytes32(puzzle_hash), uint64(amount))
                    same_as_parent = coin.puzzle_hash == spend.puzzle_hash and amount == spend.coin_amount
                    self.additions_since_fork[coin.name()] = ForkAdd(
                        coin, block.height, timestamp, hint=hint, is_coinbase=False, same_as_parent=same_as_parent
                    )
        self.include_reward_coins(block)

    def include_block(
        self,
        additions: list[tuple[Coin, Optional[bytes]]],
        removals: list[Coin],
        block: FullBlock,
        header_hash: bytes32,
    ) -> None:
        self.update_fork_peak(block, header_hash)
        if block.foliage_transaction_block is not None:
            timestamp = block.foliage_transaction_block.timestamp
            spent_coins: dict[bytes32, Coin] = {}
            for spend in removals:
                spend_id = bytes32(spend.name())
                spent_coins[spend_id] = spend
                self.removals_since_fork[spend_id] = ForkRem(bytes32(spend.puzzle_hash), block.height)
            for coin, hint in additions: