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

Code before:

    async def pre_validate_spendbundle(
        self, spend_bundle: SpendBundle, spend_bundle_id: Optional[bytes32] = None, bls_cache: Optional[BLSCache] = None
    ) -> SpendBundleConditions:
        """
        Errors are included within the cached_result.
        This runs in another process so we don't block the main thread
        """

        if spend_bundle.coin_spends == []:
            raise ValidationError(Err.INVALID_SPEND_BUNDLE, "Empty SpendBundle")

        assert self.peak is not None

        self._worker_queue_size += 1
        try:
            flags = get_flags_for_height_and_constants(self.peak.height, self.constants)
            sbc, new_cache_entries, duration = await asyncio.get_running_loop().run_in_executor(
                self.pool,
                validate_clvm_and_signature,
                spend_bundle,
                self.max_tx_clvm_cost,
                self.constants,
                flags | MEMPOOL_MODE,
            )
        # validate_clvm_and_signature raises a TypeError with an error code
        except ValueError as e:
            # Convert that to a ValidationError
            if len(e.args) > 1:
                error = Err(e.args[1])
                raise ValidationError(error)
            else:
                raise ValidationError(Err.UNKNOWN)  # pragma: no cover
        finally:
            self._worker_queue_size -= 1

        if bls_cache is not None:
            bls_cache.update(new_cache_entries)

        ret = NPCResult(None, sbc)

        if spend_bundle_id is None:
            spend_bundle_id = spend_bundle.name()

        log.log(
            logging.DEBUG if duration < 2 else logging.WARNING,
            f"pre_validate_spendbundle took {duration:0.4f} seconds "
            f"for {spend_bundle_id} (queue-size: {self._worker_queue_size})",
        )
        if ret.error is not None:
            raise ValidationError(Err(ret.error), "pre_validate_spendbundle failed")

Review comment (suggestion):
```suggestion
        # validate_clvm_and_signature raises a ValueError with an error code
```

Code after:

    async def pre_validate_spendbundle(
        self, spend_bundle: SpendBundle, spend_bundle_id: Optional[bytes32] = None, bls_cache: Optional[BLSCache] = None
    ) -> SpendBundleConditions:
        """
        Errors are included within the cached_result.
        This runs in another process so we don't block the main thread
        """

        if spend_bundle.coin_spends == []:
            raise ValidationError(Err.INVALID_SPEND_BUNDLE, "Empty SpendBundle")

        assert self.peak is not None

        self._worker_queue_size += 1
        try:
            flags = get_flags_for_height_and_constants(self.peak.height, self.constants)
            sbc, new_cache_entries, duration = await asyncio.get_running_loop().run_in_executor(
                self.pool,
                validate_clvm_and_signature,
                spend_bundle,
                self.max_tx_clvm_cost,
                self.constants,
                flags | MEMPOOL_MODE,
            )
        # validate_clvm_and_signature raises a ValueError with an error code
        except ValueError as e:
            # Convert that to a ValidationError
            if len(e.args) > 1:
                error = Err(e.args[1])
                raise ValidationError(error)
            else:
                raise ValidationError(Err.UNKNOWN)  # pragma: no cover
        finally:
            self._worker_queue_size -= 1

        if bls_cache is not None:
            bls_cache.update(new_cache_entries)

        ret = NPCResult(None, sbc)

        if spend_bundle_id is None:
            spend_bundle_id = spend_bundle.name()

        log.log(
            logging.DEBUG if duration < 2 else logging.WARNING,
            f"pre_validate_spendbundle took {duration:0.4f} seconds "
            f"for {spend_bundle_id} (queue-size: {self._worker_queue_size})",
        )
        if ret.error is not None:
            raise ValidationError(Err(ret.error), "pre_validate_spendbundle failed")