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

Function onchain_fulfilled_htlc

lightningd/peer_htlcs.c:1417–1453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415}
1416
1417void onchain_fulfilled_htlc(struct channel *channel,
1418 const struct preimage *preimage)
1419{
1420 struct htlc_out_map_iter outi;
1421 struct htlc_out *hout;
1422 struct sha256 payment_hash;
1423 struct lightningd *ld = channel->peer->ld;
1424
1425 sha256(&payment_hash, preimage, sizeof(*preimage));
1426
1427 /* FIXME: use db to look this up! */
1428 for (hout = htlc_out_map_first(&ld->htlcs_out, &outi);
1429 hout;
1430 hout = htlc_out_map_next(&ld->htlcs_out, &outi)) {
1431 if (hout->key.channel != channel)
1432 continue;
1433
1434 /* It's possible that we failed some and succeeded one,
1435 * if we got multiple errors. */
1436 if (hout->failmsg || hout->failonion)
1437 continue;
1438
1439 if (!sha256_eq(&hout->payment_hash, &payment_hash))
1440 continue;
1441
1442 /* We may have already fulfilled before going onchain, or
1443 * we can fulfill onchain multiple times. */
1444 if (!hout->preimage) {
1445 /* Force state to something which allows a preimage */
1446 hout->hstate = RCVD_REMOVE_HTLC;
1447 fulfill_our_htlc_out(channel, hout, preimage);
1448 }
1449
1450 /* We keep going: this is something of a leak, but onchain
1451 * we have no real way of distinguishing HTLCs anyway */
1452 }
1453}
1454
1455static bool peer_failed_our_htlc(struct channel *channel,
1456 const struct failed_htlc *failed)

Callers 1

Calls 2

fulfill_our_htlc_outFunction · 0.85
sha256Class · 0.70

Tested by

no test coverage detected