def htlc_failed(self, chan: Channel, payment_hash: bytes, htlc_id: int, error_bytes: Optional[bytes], failure_message: Optional['OnionRoutingFailure']):
    util.trigger_callback('htlc_failed', payment_hash, chan.channel_id)
    q = self.sent_htlcs.get(payment_hash)
    if q:
        key = (payment_hash, chan.short_channel_id, htlc_id)
        (route, payment_secret, amount_msat, bucket_msat, amount_receiver_msat) = self.sent_htlcs_routes[key]
        if error_bytes:
            try:
                (failure_message, sender_idx) = chan.decode_onion_error(error_bytes, route, htlc_id)
            except Exception as e:
                sender_idx = None
                failure_message = OnionRoutingFailure((- 1), str(e))
        else:
            assert (failure_message is not None)
            sender_idx = None
        self.logger.info(f'htlc_failed {failure_message}')
        if ((not self.channel_db) and (payment_secret in self.sent_buckets)):
            (amount_sent, amount_failed) = self.sent_buckets[payment_secret]
            amount_failed += amount_receiver_msat
            self.sent_buckets[payment_secret] = (amount_sent, amount_failed)
            if (amount_sent != amount_failed):
                self.logger.info('bucket still active...')
                return
            self.logger.info('bucket failed')
            amount_receiver_msat = amount_sent
        htlc_log = HtlcLog(success=False, route=route, amount_msat=amount_receiver_msat, error_bytes=error_bytes, failure_msg=failure_message, sender_idx=sender_idx)
        q.put_nowait(htlc_log)
    else:
        self.logger.info(f'received unknown htlc_failed, probably from previous session')
        key = payment_hash.hex()
        self.set_invoice_status(key, PR_UNPAID)
        util.trigger_callback('payment_failed', self.wallet, key, '')
def htlc_failed(self, chan: Channel, payment_hash: bytes, htlc_id: int, error_bytes: Optional[bytes], failure_message: Optional['OnionRoutingFailure']):
    util.trigger_callback('htlc_failed', payment_hash, chan.channel_id)
    q = self.sent_htlcs.get(payment_hash)
    if q:
        key = (payment_hash, chan.short_channel_id, htlc_id)
        (route, payment_secret, amount_msat, bucket_msat, amount_receiver_msat) = self.sent_htlcs_routes[key]
        if error_bytes:
            try:
                (failure_message, sender_idx) = chan.decode_onion_error(error_bytes, route, htlc_id)
            except Exception as e:
                sender_idx = None
                failure_message = OnionRoutingFailure((- 1), str(e))
        else:
            assert (failure_message is not None)
            sender_idx = None
        self.logger.info(f'htlc_failed {failure_message}')
        if ((not self.channel_db) and (payment_secret in self.sent_buckets)):
            (amount_sent, amount_failed) = self.sent_buckets[payment_secret]
            amount_failed += amount_receiver_msat
            self.sent_buckets[payment_secret] = (amount_sent, amount_failed)
            if (amount_sent != amount_failed):
                self.logger.info('bucket still active...')
                return
            self.logger.info('bucket failed')
            amount_receiver_msat = amount_sent
        htlc_log = HtlcLog(success=False, route=route, amount_msat=amount_receiver_msat, error_bytes=error_bytes, failure_msg=failure_message, sender_idx=sender_idx)
        q.put_nowait(htlc_log)
    else:
        self.logger.info(f'received unknown htlc_failed, probably from previous session')
        key = payment_hash.hex()
        self.set_invoice_status(key, PR_UNPAID)
        util.trigger_callback('payment_failed', self.wallet, key, )