Repository: Chia-Network/chia-blockchain
File: chia/harvester/harvester_api.py (Python)

Code before:
        """
        The harvester receives a new signage point from the farmer, this happens at the start of each slot.
        The harvester does a few things:
        1. The harvester applies the plot filter for each of the plots, to select the proportion which are eligible
        for this signage point and challenge.
        2. The harvester gets the qualities for each plot. This is approximately 7 reads per plot which qualifies.
        Note that each plot may have 0, 1, 2, etc qualities for that challenge: but on average it will have 1.
        3. Checks the required_iters for each quality and the given signage point, to see which are eligible for
        inclusion (required_iters < sp_interval_iters).
        4. Looks up the full proof of space in the plot for each quality, approximately 64 reads per quality
        5. Returns the proof of space to the farmer
        """
        if not self.harvester.plot_manager.public_keys_available():
            # This means that we have not received the handshake yet
            self.harvester.log.debug("new_signage_point_harvester received with no keys available")
            return None

        self.harvester.log.debug(
            f"new_signage_point_harvester lookup: challenge_hash: {new_challenge.challenge_hash}, "
            f"sp_hash: {new_challenge.sp_hash}, signage_point_index: {new_challenge.signage_point_index}"
        )

        start = time.monotonic()
        assert len(new_challenge.challenge_hash) == 32

        plot_strength = calculate_plot_strength(self.harvester.constants, new_challenge.last_tx_height)

        loop = asyncio.get_running_loop()

        def blocking_lookup(filename: Path, plot_info: PlotInfo) -> list[tuple[bytes32, ProofOfSpace]]:
            # Uses the Prover object to lookup qualities. This is a blocking call,
            # so it should be run in a thread pool.
            try:
                plot_id = plot_info.prover.get_id()
                sp_challenge_hash = calculate_pos_challenge(
                    plot_id,
                    new_challenge.challenge_hash,
                    new_challenge.sp_hash,
                )
                try:
                    quality_strings = plot_info.prover.get_qualities_for_challenge(sp_challenge_hash, plot_strength)
                except RuntimeError as e:
                    if str(e) == "Timeout waiting for context queue.":
                        self.harvester.log.warning(
                            f"No decompressor available. Cancelling qualities retrieving for {filename}"
                        )
                        self.harvester.log.warning(
                            f"File: {filename} Plot ID: {plot_id.hex()}, challenge: {sp_challenge_hash}, "
                            f"plot_info: {plot_info}"
                        )
                    else:

Review comment (suggestion):
i would change to calculate_requierd_strength since the plot strength itself is fixed in the plot and returned in the proof bytes, i think this name is confusing, the var name should be  requierd_strength as well

Code after:
        peer: WSChiaConnection,
    ) -> int:
        proofs_found = 0
        for filename_sublist_awaitable in asyncio.as_completed(awaitables):
            filename, sublist = await filename_sublist_awaitable
            time_taken = time.monotonic() - start_time
            if time_taken > 8:
                self.harvester.log.warning(
                    f"Looking up qualities on {filename} took: {time_taken}. This should be below 8 seconds"
                    f" to minimize risk of losing rewards."
                )
            for response in sublist:
                proofs_found += 1
                msg = make_msg(ProtocolMessageTypes.new_proof_of_space, response)
                await peer.send_message(msg)
        return proofs_found

    async def _handle_v2_responses(
        self, v2_awaitables: Sequence[Awaitable[Optional[PartialProofsData]]], start_time: float, peer: WSChiaConnection
    ) -> int:
        partial_proofs_found = 0
        for quality_awaitable in asyncio.as_completed(v2_awaitables):
            partial_proofs_data = await quality_awaitable
            if partial_proofs_data is None:
                continue
            time_taken = time.monotonic() - start_time
            if time_taken > 8:
                self.harvester.log.warning(
                    f"Looking up partial proofs on {partial_proofs_data.plot_identifier}"
                    f"took: {time_taken}. This should be below 8 seconds"
                    f"to minimize risk of losing rewards."
                )
            partial_proofs_found += len(partial_proofs_data.partial_proofs)
            msg = make_msg(ProtocolMessageTypes.partial_proofs, partial_proofs_data)
            await peer.send_message(msg)
        return partial_proofs_found

    @metadata.request(peer_required=True)
    async def harvester_handshake(
        self, harvester_handshake: harvester_protocol.HarvesterHandshake, peer: WSChiaConnection
    ) -> None:
        """
        Handshake between the harvester and farmer. The harvester receives the pool public keys,
        as well as the farmer pks, which must be put into the plots, before the plotting process begins.
        We cannot use any plots which have different keys in them.
        """
        self.harvester.plot_manager.set_public_keys(
            harvester_handshake.farmer_public_keys, harvester_handshake.pool_public_keys
        )
        self.harvester.plot_sync_sender.set_connection(peer)
        await self.harvester.plot_sync_sender.start()