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

Function fulfill_htlc

lightningd/peer_htlcs.c:385–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage)
386{
387 u8 *msg;
388 struct channel *channel = hin->key.channel;
389
390 if (hin->hstate != RCVD_ADD_ACK_REVOCATION) {
391 log_debug(channel->log,
392 "HTLC fulfilled, but not ready any more (%s).",
393 htlc_state_name(hin->hstate));
394 return;
395 }
396
397 hin->preimage = tal_dup(hin, struct preimage, preimage);
398
399 /* We update state now to signal it's in progress, for persistence. */
400 htlc_in_update_state(channel, hin, SENT_REMOVE_HTLC);
401
402 htlc_in_check(hin, __func__);
403
404 /* Update channel stats */
405 channel_stats_incr_in_fulfilled(channel, hin->msat);
406
407 /* No owner? We'll either send to channeld in peer_htlcs, or
408 * onchaind in onchaind_tell_fulfill. */
409 if (!channel->owner) {
410 log_debug(channel->log, "HTLC fulfilled, but no owner.");
411 return;
412 }
413
414 if (streq(channel->owner->name, "onchaind")) {
415 msg = towire_onchaind_known_preimage(hin, preimage);
416 } else {
417 struct fulfilled_htlc fulfilled_htlc;
418 fulfilled_htlc.id = hin->key.id;
419 fulfilled_htlc.payment_preimage = *preimage;
420 msg = towire_channeld_fulfill_htlc(hin, &fulfilled_htlc);
421 }
422 subd_send_msg(channel->owner, take(msg));
423}
424
425/* HTLC-specific wrappers */
426static void htlc_set_fulfill_htlc(struct htlc_in *hin,

Callers 4

htlc_set_fulfill_htlcFunction · 0.70
fulfill_our_htlc_outFunction · 0.70
check_already_failedFunction · 0.70

Calls 7

htlc_in_update_stateFunction · 0.85
htlc_in_checkFunction · 0.70
subd_send_msgFunction · 0.70
htlc_state_nameFunction · 0.50

Tested by

no test coverage detected