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

Function send_htlc_out

lightningd/peer_htlcs.c:702–771  ·  view source on GitHub ↗

Returns failmsg, or NULL on success. */

Source from the content-addressed store, hash-verified

700
701/* Returns failmsg, or NULL on success. */
702const u8 *send_htlc_out(const tal_t *ctx,
703 struct channel *out,
704 struct amount_msat amount, u32 cltv,
705 struct amount_msat final_msat,
706 const struct sha256 *payment_hash,
707 const struct pubkey *path_key,
708 const struct tlv_field *extra_tlvs,
709 u64 partid,
710 u64 groupid,
711 const u8 *onion_routing_packet,
712 struct htlc_in *in,
713 struct htlc_out **houtp)
714{
715 u8 *msg, *raw_tlvs = NULL;
716
717 *houtp = NULL;
718
719 if (!channel_state_can_add_htlc(out->state)) {
720 log_info(out->log, "Attempt to send HTLC but not ready (%s)",
721 channel_state_name(out));
722 return towire_unknown_next_peer(ctx);
723 }
724
725 if (!out->owner) {
726 log_info(out->log, "Attempt to send HTLC but unowned (%s)",
727 channel_state_name(out));
728 return towire_temporary_channel_failure(ctx,
729 channel_update_for_error(tmpctx, in, out));
730 }
731
732 /* Note: we allow outgoing HTLCs before sync, for fast startup. */
733 if (!topology_synced(out->peer->ld->topology)) {
734 log_debug(out->log, "Sending HTLC while still syncing"
735 " with bitcoin network (%u vs %u)",
736 get_block_height(out->peer->ld->topology),
737 get_network_blockheight(out->peer->ld->topology));
738 }
739
740 /* Make peer's daemon own it, catch if it dies. */
741 *houtp = new_htlc_out(out->owner, out, amount, cltv,
742 payment_hash, onion_routing_packet,
743 path_key, extra_tlvs,
744 in == NULL,
745 final_msat,
746 partid, groupid, in);
747 tal_add_destructor(*houtp, destroy_hout_subd_died);
748
749 /* Give channel 30 seconds to commit this htlc. */
750 if (!out->peer->ld->dev_no_htlc_timeout) {
751 (*houtp)->timeout = new_reltimer(out->peer->ld->timers,
752 *houtp, time_from_sec(30),
753 htlc_offer_timeout,
754 *houtp);
755 }
756
757 if (extra_tlvs) {
758 raw_tlvs = tal_arr(tmpctx, u8, 0);
759 towire_tlvstream_raw(&raw_tlvs,

Callers 3

send_onionFunction · 0.85
json_injectpaymentonionFunction · 0.85
forward_htlcFunction · 0.85

Calls 12

log_infoClass · 0.85
channel_update_for_errorFunction · 0.85
topology_syncedFunction · 0.85
new_htlc_outFunction · 0.85
time_from_secFunction · 0.85
towire_tlvstream_rawFunction · 0.85
channel_state_nameFunction · 0.70
get_block_heightFunction · 0.70
get_network_blockheightFunction · 0.70
subd_reqClass · 0.70

Tested by

no test coverage detected