| 1696 | } |
| 1697 | |
| 1698 | static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) |
| 1699 | { |
| 1700 | htlc_in_check(hin, __func__); |
| 1701 | assert(hin->failonion || hin->preimage || hin->badonion); |
| 1702 | |
| 1703 | log_debug(channel->log, "Removing in HTLC %"PRIu64" state %s %s", |
| 1704 | hin->key.id, htlc_state_name(hin->hstate), |
| 1705 | hin->preimage ? "FULFILLED" |
| 1706 | : hin->badonion ? onion_wire_name(hin->badonion) |
| 1707 | : "REMOTEFAIL"); |
| 1708 | |
| 1709 | /* If we fulfilled their HTLC, credit us. */ |
| 1710 | if (hin->preimage) { |
| 1711 | struct amount_msat oldamt = channel->our_msat; |
| 1712 | const struct channel_coin_mvt *mvt; |
| 1713 | |
| 1714 | if (!amount_msat_add(&channel->our_msat, channel->our_msat, |
| 1715 | hin->msat)) { |
| 1716 | channel_internal_error(channel, |
| 1717 | "Overflow our_msat %s + HTLC %s", |
| 1718 | type_to_string(tmpctx, |
| 1719 | struct amount_msat, |
| 1720 | &channel->our_msat), |
| 1721 | type_to_string(tmpctx, |
| 1722 | struct amount_msat, |
| 1723 | &hin->msat)); |
| 1724 | } |
| 1725 | log_debug(channel->log, "Balance %s -> %s", |
| 1726 | type_to_string(tmpctx, struct amount_msat, &oldamt), |
| 1727 | type_to_string(tmpctx, struct amount_msat, |
| 1728 | &channel->our_msat)); |
| 1729 | if (amount_msat_greater(channel->our_msat, |
| 1730 | channel->msat_to_us_max)) |
| 1731 | channel->msat_to_us_max = channel->our_msat; |
| 1732 | |
| 1733 | /* Coins have definitively moved, log a movement */ |
| 1734 | if (hin->we_filled && *hin->we_filled) |
| 1735 | mvt = new_channel_mvt_invoice_hin(hin, hin, channel); |
| 1736 | else |
| 1737 | mvt = new_channel_mvt_routed_hin(hin, hin, channel); |
| 1738 | |
| 1739 | if (!mvt) |
| 1740 | log_broken(channel->log, |
| 1741 | "Unable to calculate fees collected." |
| 1742 | " Not logging an inbound HTLC"); |
| 1743 | else |
| 1744 | notify_channel_mvt(channel->peer->ld, mvt); |
| 1745 | } |
| 1746 | |
| 1747 | tal_free(hin); |
| 1748 | } |
| 1749 | |
| 1750 | static void remove_htlc_out(struct channel *channel, struct htlc_out *hout) |
| 1751 | { |
no test coverage detected