Returns failmsg, or NULL on success. */
| 575 | |
| 576 | /* Returns failmsg, or NULL on success. */ |
| 577 | const u8 *send_htlc_out(const tal_t *ctx, |
| 578 | struct channel *out, |
| 579 | struct amount_msat amount, u32 cltv, |
| 580 | struct amount_msat final_msat, |
| 581 | const struct sha256 *payment_hash, |
| 582 | const struct pubkey *blinding, |
| 583 | u64 partid, |
| 584 | u64 groupid, |
| 585 | const u8 *onion_routing_packet, |
| 586 | struct htlc_in *in, |
| 587 | struct htlc_out **houtp) |
| 588 | { |
| 589 | u8 *msg; |
| 590 | |
| 591 | *houtp = NULL; |
| 592 | |
| 593 | if (!channel_can_add_htlc(out)) { |
| 594 | log_info(out->log, "Attempt to send HTLC but not ready (%s)", |
| 595 | channel_state_name(out)); |
| 596 | return towire_unknown_next_peer(ctx); |
| 597 | } |
| 598 | |
| 599 | if (!out->owner) { |
| 600 | log_info(out->log, "Attempt to send HTLC but unowned (%s)", |
| 601 | channel_state_name(out)); |
| 602 | return towire_temporary_channel_failure(ctx, |
| 603 | get_channel_update(out)); |
| 604 | } |
| 605 | |
| 606 | if (!topology_synced(out->peer->ld->topology)) { |
| 607 | log_info(out->log, "Attempt to send HTLC but still syncing" |
| 608 | " with bitcoin network"); |
| 609 | return towire_temporary_node_failure(ctx); |
| 610 | } |
| 611 | |
| 612 | /* Make peer's daemon own it, catch if it dies. */ |
| 613 | *houtp = new_htlc_out(out->owner, out, amount, cltv, |
| 614 | payment_hash, onion_routing_packet, |
| 615 | blinding, in == NULL, |
| 616 | final_msat, |
| 617 | partid, groupid, in); |
| 618 | tal_add_destructor(*houtp, destroy_hout_subd_died); |
| 619 | |
| 620 | /* Give channel 30 seconds to commit this htlc. */ |
| 621 | if (!IFDEV(out->peer->ld->dev_no_htlc_timeout, 0)) { |
| 622 | (*houtp)->timeout = new_reltimer(out->peer->ld->timers, |
| 623 | *houtp, time_from_sec(30), |
| 624 | htlc_offer_timeout, |
| 625 | *houtp); |
| 626 | } |
| 627 | |
| 628 | msg = towire_channeld_offer_htlc(out, amount, cltv, payment_hash, |
| 629 | onion_routing_packet, blinding); |
| 630 | subd_req(out->peer->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply, |
| 631 | *houtp); |
| 632 | |
| 633 | return NULL; |
| 634 | } |
no test coverage detected