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

Function remove_htlc_out

lightningd/peer_htlcs.c:2076–2127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2074}
2075
2076static void remove_htlc_out(struct channel *channel, struct htlc_out *hout)
2077{
2078 struct lightningd *ld = channel->peer->ld;
2079
2080 htlc_out_check(hout, __func__);
2081 assert(hout->failonion || hout->preimage || hout->failmsg);
2082 log_debug(channel->log, "Removing out HTLC %"PRIu64" state %s %s",
2083 hout->key.id, htlc_state_name(hout->hstate),
2084 hout->preimage ? "FULFILLED"
2085 : hout->failmsg ? onion_wire_name(fromwire_peektype(hout->failmsg))
2086 : "REMOTEFAIL");
2087
2088 /* If it's failed, now we can forward since it's completely locked-in */
2089 if (!hout->preimage) {
2090 fail_out_htlc(hout, NULL);
2091 } else {
2092 const struct channel_coin_mvt *mvt;
2093 struct amount_msat oldamt = channel->our_msat;
2094 /* We paid for this HTLC, so deduct balance. */
2095 if (!amount_msat_deduct(&channel->our_msat, hout->msat)) {
2096 channel_internal_error(channel,
2097 "Underflow our_msat %s - HTLC %s",
2098 fmt_amount_msat(tmpctx,
2099 channel->our_msat),
2100 fmt_amount_msat(tmpctx,
2101 hout->msat));
2102 }
2103
2104 log_debug(channel->log, "Balance %s -> %s",
2105 fmt_amount_msat(tmpctx, oldamt),
2106 fmt_amount_msat(tmpctx, channel->our_msat));
2107 if (amount_msat_less(channel->our_msat, channel->msat_to_us_min))
2108 channel->msat_to_us_min = channel->our_msat;
2109
2110 /* Coins have definitively moved, log a movement */
2111 if (hout->am_origin)
2112 mvt = new_channel_mvt_invoice_hout(hout, hout, channel);
2113 else
2114 mvt = new_channel_mvt_routed_hout(hout, hout, channel);
2115
2116
2117 if (!mvt)
2118 log_broken(channel->log,
2119 "Unable to calculate fees."
2120 " Not logging an outbound HTLC");
2121 else
2122 wallet_save_channel_mvt(channel->peer->ld, mvt);
2123 }
2124
2125 tal_free(hout);
2126 check_graceful_shutdown(ld);
2127}
2128
2129static bool update_in_htlc(struct channel *channel,
2130 u64 id, enum htlc_state newstate)

Callers 1

update_out_htlcFunction · 0.85

Calls 13

htlc_out_checkFunction · 0.85
fromwire_peektypeFunction · 0.85
fail_out_htlcFunction · 0.85
amount_msat_deductFunction · 0.85
wallet_save_channel_mvtFunction · 0.85
tal_freeFunction · 0.85
check_graceful_shutdownFunction · 0.85
channel_internal_errorFunction · 0.70
htlc_state_nameFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected