MCPcopy Create free account
hub / github.com/ElementsProject/lightning / remove_htlc_out

Function remove_htlc_out

lightningd/peer_htlcs.c:1750–1802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1748}
1749
1750static void remove_htlc_out(struct channel *channel, struct htlc_out *hout)
1751{
1752 htlc_out_check(hout, __func__);
1753 assert(hout->failonion || hout->preimage || hout->failmsg);
1754 log_debug(channel->log, "Removing out HTLC %"PRIu64" state %s %s",
1755 hout->key.id, htlc_state_name(hout->hstate),
1756 hout->preimage ? "FULFILLED"
1757 : hout->failmsg ? onion_wire_name(fromwire_peektype(hout->failmsg))
1758 : "REMOTEFAIL");
1759
1760 /* If it's failed, now we can forward since it's completely locked-in */
1761 if (!hout->preimage) {
1762 fail_out_htlc(hout, NULL);
1763 } else {
1764 const struct channel_coin_mvt *mvt;
1765 struct amount_msat oldamt = channel->our_msat;
1766 /* We paid for this HTLC, so deduct balance. */
1767 if (!amount_msat_sub(&channel->our_msat, channel->our_msat,
1768 hout->msat)) {
1769 channel_internal_error(channel,
1770 "Underflow our_msat %s - HTLC %s",
1771 type_to_string(tmpctx,
1772 struct amount_msat,
1773 &channel->our_msat),
1774 type_to_string(tmpctx,
1775 struct amount_msat,
1776 &hout->msat));
1777 }
1778
1779 log_debug(channel->log, "Balance %s -> %s",
1780 type_to_string(tmpctx, struct amount_msat, &oldamt),
1781 type_to_string(tmpctx, struct amount_msat,
1782 &channel->our_msat));
1783 if (amount_msat_less(channel->our_msat, channel->msat_to_us_min))
1784 channel->msat_to_us_min = channel->our_msat;
1785
1786 /* Coins have definitively moved, log a movement */
1787 if (hout->am_origin)
1788 mvt = new_channel_mvt_invoice_hout(hout, hout, channel);
1789 else
1790 mvt = new_channel_mvt_routed_hout(hout, hout, channel);
1791
1792
1793 if (!mvt)
1794 log_broken(channel->log,
1795 "Unable to calculate fees."
1796 " Not logging an outbound HTLC");
1797 else
1798 notify_channel_mvt(channel->peer->ld, mvt);
1799 }
1800
1801 tal_free(hout);
1802}
1803
1804static bool update_in_htlc(struct channel *channel,
1805 u64 id, enum htlc_state newstate)

Callers 1

update_out_htlcFunction · 0.85

Calls 13

htlc_out_checkFunction · 0.85
onion_wire_nameFunction · 0.85
fail_out_htlcFunction · 0.85
amount_msat_subFunction · 0.85
amount_msat_lessFunction · 0.85
tal_freeFunction · 0.85
channel_internal_errorFunction · 0.70
notify_channel_mvtFunction · 0.70
htlc_state_nameFunction · 0.50
fromwire_peektypeFunction · 0.50

Tested by

no test coverage detected