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

Function remove_htlc_in

lightningd/peer_htlcs.c:2024–2074  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2022}
2023
2024static void remove_htlc_in(struct channel *channel, struct htlc_in *hin)
2025{
2026 struct lightningd *ld = channel->peer->ld;
2027
2028 htlc_in_check(hin, __func__);
2029 assert(hin->failonion || hin->preimage || hin->badonion);
2030
2031 log_debug(channel->log, "Removing in HTLC %"PRIu64" state %s %s",
2032 hin->key.id, htlc_state_name(hin->hstate),
2033 hin->preimage ? "FULFILLED"
2034 : hin->badonion ? onion_wire_name(hin->badonion)
2035 : "REMOTEFAIL");
2036
2037 /* If we fulfilled their HTLC, credit us. */
2038 if (hin->preimage) {
2039 struct amount_msat oldamt = channel->our_msat;
2040 const struct channel_coin_mvt *mvt;
2041
2042 if (!amount_msat_accumulate(&channel->our_msat,
2043 hin->msat)) {
2044 channel_internal_error(channel,
2045 "Overflow our_msat %s + HTLC %s",
2046 fmt_amount_msat(tmpctx,
2047 channel->our_msat),
2048 fmt_amount_msat(tmpctx,
2049 hin->msat));
2050 }
2051 log_debug(channel->log, "Balance %s -> %s",
2052 fmt_amount_msat(tmpctx, oldamt),
2053 fmt_amount_msat(tmpctx, channel->our_msat));
2054 if (amount_msat_greater(channel->our_msat,
2055 channel->msat_to_us_max))
2056 channel->msat_to_us_max = channel->our_msat;
2057
2058 /* Coins have definitively moved, log a movement */
2059 if (hin->we_filled && *hin->we_filled)
2060 mvt = new_channel_mvt_invoice_hin(hin, hin, channel);
2061 else
2062 mvt = new_channel_mvt_routed_hin(hin, hin, channel);
2063
2064 if (!mvt)
2065 log_broken(channel->log,
2066 "Unable to calculate fees collected."
2067 " Not logging an inbound HTLC");
2068 else
2069 wallet_save_channel_mvt(channel->peer->ld, mvt);
2070 }
2071
2072 tal_free(hin);
2073 check_graceful_shutdown(ld);
2074}
2075
2076static void remove_htlc_out(struct channel *channel, struct htlc_out *hout)
2077{

Callers 1

update_in_htlcFunction · 0.85

Calls 11

amount_msat_accumulateFunction · 0.85
amount_msat_greaterFunction · 0.85
wallet_save_channel_mvtFunction · 0.85
tal_freeFunction · 0.85
check_graceful_shutdownFunction · 0.85
htlc_in_checkFunction · 0.70
channel_internal_errorFunction · 0.70
htlc_state_nameFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected