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

Function onchain_fulfilled_htlc

lightningd/peer_htlcs.c:1683–1719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1681}
1682
1683void onchain_fulfilled_htlc(struct channel *channel,
1684 const struct preimage *preimage)
1685{
1686 struct htlc_out_map_iter outi;
1687 struct htlc_out *hout;
1688 struct sha256 payment_hash;
1689 struct lightningd *ld = channel->peer->ld;
1690
1691 sha256(&payment_hash, preimage, sizeof(*preimage));
1692
1693 /* FIXME: use db to look this up! */
1694 for (hout = htlc_out_map_first(ld->htlcs_out, &outi);
1695 hout;
1696 hout = htlc_out_map_next(ld->htlcs_out, &outi)) {
1697 if (hout->key.channel != channel)
1698 continue;
1699
1700 /* It's possible that we failed some and succeeded one,
1701 * if we got multiple errors. */
1702 if (hout->failmsg || hout->failonion)
1703 continue;
1704
1705 if (!sha256_eq(&hout->payment_hash, &payment_hash))
1706 continue;
1707
1708 /* We may have already fulfilled before going onchain, or
1709 * we can fulfill onchain multiple times. */
1710 if (!hout->preimage) {
1711 /* Force state to something which allows a preimage */
1712 hout->hstate = RCVD_REMOVE_HTLC;
1713 fulfill_our_htlc_out(channel, hout, preimage);
1714 }
1715
1716 /* We keep going: this is something of a leak, but onchain
1717 * we have no real way of distinguishing HTLCs anyway */
1718 }
1719}
1720
1721static bool peer_failed_our_htlc(struct channel *channel,
1722 const struct failed_htlc *failed)

Callers 1

Calls 2

fulfill_our_htlc_outFunction · 0.85
sha256Class · 0.70

Tested by

no test coverage detected