| 1952 | } |
| 1953 | |
| 1954 | static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) |
| 1955 | { |
| 1956 | struct lightningd *ld = channel->peer->ld; |
| 1957 | |
| 1958 | htlc_in_check(hin, __func__); |
| 1959 | assert(hin->failonion || hin->preimage || hin->badonion); |
| 1960 | |
| 1961 | log_debug(channel->log, "Removing in HTLC %"PRIu64" state %s %s", |
| 1962 | hin->key.id, htlc_state_name(hin->hstate), |
| 1963 | hin->preimage ? "FULFILLED" |
| 1964 | : hin->badonion ? onion_wire_name(hin->badonion) |
| 1965 | : "REMOTEFAIL"); |
| 1966 | |
| 1967 | /* If we fulfilled their HTLC, credit us. */ |
| 1968 | if (hin->preimage) { |
| 1969 | struct amount_msat oldamt = channel->our_msat; |
| 1970 | const struct channel_coin_mvt *mvt; |
| 1971 | |
| 1972 | if (!amount_msat_accumulate(&channel->our_msat, |
| 1973 | hin->msat)) { |
| 1974 | channel_internal_error(channel, |
| 1975 | "Overflow our_msat %s + HTLC %s", |
| 1976 | fmt_amount_msat(tmpctx, |
| 1977 | channel->our_msat), |
| 1978 | fmt_amount_msat(tmpctx, |
| 1979 | hin->msat)); |
| 1980 | } |
| 1981 | log_debug(channel->log, "Balance %s -> %s", |
| 1982 | fmt_amount_msat(tmpctx, oldamt), |
| 1983 | fmt_amount_msat(tmpctx, channel->our_msat)); |
| 1984 | if (amount_msat_greater(channel->our_msat, |
| 1985 | channel->msat_to_us_max)) |
| 1986 | channel->msat_to_us_max = channel->our_msat; |
| 1987 | |
| 1988 | /* Coins have definitively moved, log a movement */ |
| 1989 | if (hin->we_filled && *hin->we_filled) |
| 1990 | mvt = new_channel_mvt_invoice_hin(hin, hin, channel); |
| 1991 | else |
| 1992 | mvt = new_channel_mvt_routed_hin(hin, hin, channel); |
| 1993 | |
| 1994 | if (!mvt) |
| 1995 | log_broken(channel->log, |
| 1996 | "Unable to calculate fees collected." |
| 1997 | " Not logging an inbound HTLC"); |
| 1998 | else |
| 1999 | wallet_save_channel_mvt(channel->peer->ld, mvt); |
| 2000 | } |
| 2001 | |
| 2002 | tal_free(hin); |
| 2003 | check_graceful_shutdown(ld); |
| 2004 | } |
| 2005 | |
| 2006 | static void remove_htlc_out(struct channel *channel, struct htlc_out *hout) |
| 2007 | { |
no test coverage detected