def _assert_can_add_htlc(self, *, htlc_proposer: HTLCOwner, amount_msat: int,
                             ignore_min_htlc_value: bool = False) -> None:
        """Raises PaymentFailure if the htlc_proposer cannot add this new HTLC.
        (this is relevant both for forwarding and endpoint)
        """
        htlc_receiver = htlc_proposer.inverted()
        # note: all these tests are about the *receiver's* *next* commitment transaction,
        #       and the constraints are the ones imposed by their config
        ctn = self.get_next_ctn(htlc_receiver)
        chan_config = self.config[htlc_receiver]
        if self.get_state() != ChannelState.OPEN:
            raise PaymentFailure(f"Channel not open. {self.get_state()!r}")
        if not self.can_update_ctx(proposer=htlc_proposer):
            raise PaymentFailure(f"cannot update channel. {self.get_state()!r} {self.peer_state!r}")
        if htlc_proposer == LOCAL:
            if not self.can_send_update_add_htlc():
                raise PaymentFailure('Channel cannot add htlc')

        # check htlc raw value
        if not ignore_min_htlc_value:
            if amount_msat <= 0:
                raise PaymentFailure("HTLC value must be positive")
            if amount_msat < chan_config.htlc_minimum_msat:
                raise PaymentFailure(f'HTLC value too small: {amount_msat} msat')

        if self.htlc_slots_left(htlc_proposer) == 0:
            raise PaymentFailure('Too many HTLCs already in channel')

        if amount_msat > self.remaining_max_inflight(htlc_receiver, strict=False):
            raise PaymentFailure(
                f'HTLC value sum (sum of pending htlcs plus new htlc) '
                f'would exceed max allowed: {chan_config.max_htlc_value_in_flight_msat/1000} sat')

        # check proposer can afford htlc
        max_can_send_msat = self.available_to_spend(htlc_proposer)
        if max_can_send_msat < amount_msat:
            raise PaymentFailure(f'Not enough balance. can send: {max_can_send_msat}, tried: {amount_msat}')
Raises PaymentFailure if the htlc_proposer cannot add this new HTLC.
        (this is relevant both for forwarding and endpoint)
        
electrum/lnchannel.py