Returns failmsg, or NULL on success. */
| 744 | |
| 745 | /* Returns failmsg, or NULL on success. */ |
| 746 | const u8 *send_htlc_out(const tal_t *ctx, |
| 747 | struct channel *out, |
| 748 | struct amount_msat amount, u32 cltv, |
| 749 | struct amount_msat final_msat, |
| 750 | const struct sha256 *payment_hash, |
| 751 | const struct pubkey *path_key, |
| 752 | const struct tlv_field *extra_tlvs, |
| 753 | u64 partid, |
| 754 | u64 groupid, |
| 755 | const u8 *onion_routing_packet, |
| 756 | struct htlc_in *in, |
| 757 | struct htlc_out **houtp) |
| 758 | { |
| 759 | u8 *msg, *raw_tlvs = NULL; |
| 760 | |
| 761 | *houtp = NULL; |
| 762 | |
| 763 | if (!channel_state_can_add_htlc(out->state)) { |
| 764 | log_info(out->log, "Attempt to send HTLC but not ready (%s)", |
| 765 | channel_state_name(out)); |
| 766 | return towire_unknown_next_peer(ctx); |
| 767 | } |
| 768 | |
| 769 | if (!out->owner) { |
| 770 | log_info(out->log, "Attempt to send HTLC but unowned (%s)", |
| 771 | channel_state_name(out)); |
| 772 | return towire_temporary_channel_failure(ctx, |
| 773 | channel_update_for_error(tmpctx, in, out)); |
| 774 | } |
| 775 | |
| 776 | /* Note: we allow outgoing HTLCs before sync, for fast startup. */ |
| 777 | if (!topology_synced(out->peer->ld->topology)) { |
| 778 | log_debug(out->log, "Sending HTLC while still syncing" |
| 779 | " with bitcoin network (%u vs %u)", |
| 780 | get_block_height(out->peer->ld->topology), |
| 781 | get_network_blockheight(out->peer->ld->topology)); |
| 782 | } |
| 783 | |
| 784 | /* Make peer's daemon own it, catch if it dies. */ |
| 785 | *houtp = new_htlc_out(out->owner, out, amount, cltv, |
| 786 | payment_hash, onion_routing_packet, |
| 787 | path_key, extra_tlvs, |
| 788 | in == NULL, |
| 789 | final_msat, |
| 790 | partid, groupid, in); |
| 791 | tal_add_destructor(*houtp, destroy_hout_subd_died); |
| 792 | |
| 793 | /* Give channel 30 seconds to commit this htlc. */ |
| 794 | if (!out->peer->ld->dev_no_htlc_timeout) { |
| 795 | (*houtp)->timeout = new_reltimer(out->peer->ld->timers, |
| 796 | *houtp, time_from_sec(30), |
| 797 | htlc_offer_timeout, |
| 798 | *houtp); |
| 799 | } |
| 800 | |
| 801 | if (extra_tlvs) { |
| 802 | raw_tlvs = tal_arr(tmpctx, u8, 0); |
| 803 | towire_tlvstream_raw(&raw_tlvs, |
no test coverage detected