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

Function remove_htlc_out

lightningd/peer_htlcs.c:2006–2057  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2004}
2005
2006static void remove_htlc_out(struct channel *channel, struct htlc_out *hout)
2007{
2008 struct lightningd *ld = channel->peer->ld;
2009
2010 htlc_out_check(hout, __func__);
2011 assert(hout->failonion || hout->preimage || hout->failmsg);
2012 log_debug(channel->log, "Removing out HTLC %"PRIu64" state %s %s",
2013 hout->key.id, htlc_state_name(hout->hstate),
2014 hout->preimage ? "FULFILLED"
2015 : hout->failmsg ? onion_wire_name(fromwire_peektype(hout->failmsg))
2016 : "REMOTEFAIL");
2017
2018 /* If it's failed, now we can forward since it's completely locked-in */
2019 if (!hout->preimage) {
2020 fail_out_htlc(hout, NULL);
2021 } else {
2022 const struct channel_coin_mvt *mvt;
2023 struct amount_msat oldamt = channel->our_msat;
2024 /* We paid for this HTLC, so deduct balance. */
2025 if (!amount_msat_deduct(&channel->our_msat, hout->msat)) {
2026 channel_internal_error(channel,
2027 "Underflow our_msat %s - HTLC %s",
2028 fmt_amount_msat(tmpctx,
2029 channel->our_msat),
2030 fmt_amount_msat(tmpctx,
2031 hout->msat));
2032 }
2033
2034 log_debug(channel->log, "Balance %s -> %s",
2035 fmt_amount_msat(tmpctx, oldamt),
2036 fmt_amount_msat(tmpctx, channel->our_msat));
2037 if (amount_msat_less(channel->our_msat, channel->msat_to_us_min))
2038 channel->msat_to_us_min = channel->our_msat;
2039
2040 /* Coins have definitively moved, log a movement */
2041 if (hout->am_origin)
2042 mvt = new_channel_mvt_invoice_hout(hout, hout, channel);
2043 else
2044 mvt = new_channel_mvt_routed_hout(hout, hout, channel);
2045
2046
2047 if (!mvt)
2048 log_broken(channel->log,
2049 "Unable to calculate fees."
2050 " Not logging an outbound HTLC");
2051 else
2052 wallet_save_channel_mvt(channel->peer->ld, mvt);
2053 }
2054
2055 tal_free(hout);
2056 check_graceful_shutdown(ld);
2057}
2058
2059static bool update_in_htlc(struct channel *channel,
2060 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