| 1719 | } |
| 1720 | |
| 1721 | static struct htlcs_info *init_reply(const tal_t *ctx, const char *what) |
| 1722 | { |
| 1723 | struct htlcs_info *htlcs_info = tal(ctx, struct htlcs_info); |
| 1724 | const u8 *msg; |
| 1725 | struct htlc_with_tells *htlcs; |
| 1726 | |
| 1727 | /* commit_num is 0 for mutual close, but we don't care about HTLCs |
| 1728 | * then anyway. */ |
| 1729 | |
| 1730 | /* Send init_reply first, so billboard gets credited to ONCHAIND */ |
| 1731 | wire_sync_write(REQ_FD, |
| 1732 | take(towire_onchaind_init_reply(NULL, commit_num))); |
| 1733 | |
| 1734 | peer_billboard(true, what); |
| 1735 | |
| 1736 | /* Read in htlcs (ignoring everything else for now) */ |
| 1737 | msg = queue_until_msg(tmpctx, WIRE_ONCHAIND_HTLCS); |
| 1738 | if (!fromwire_onchaind_htlcs(htlcs_info, msg, |
| 1739 | &htlcs_info->htlcs, |
| 1740 | &htlcs_info->tell_if_missing, |
| 1741 | &htlcs_info->tell_immediately)) |
| 1742 | master_badmsg(WIRE_ONCHAIND_HTLCS, msg); |
| 1743 | |
| 1744 | /* One convenient structure, so we sort them together! */ |
| 1745 | htlcs = tal_arr(tmpctx, struct htlc_with_tells, tal_count(htlcs_info->htlcs)); |
| 1746 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 1747 | htlcs[i].htlc = htlcs_info->htlcs[i]; |
| 1748 | htlcs[i].tell_if_missing = htlcs_info->tell_if_missing[i]; |
| 1749 | htlcs[i].tell_immediately = htlcs_info->tell_immediately[i]; |
| 1750 | } |
| 1751 | |
| 1752 | /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups) */ |
| 1753 | asort(htlcs, tal_count(htlcs), cmp_htlc_with_tells_cltv, NULL); |
| 1754 | |
| 1755 | /* Now put them back (prev were allocated off tmpctx) */ |
| 1756 | htlcs_info->htlcs = tal_arr(htlcs_info, struct htlc_stub, tal_count(htlcs)); |
| 1757 | htlcs_info->tell_if_missing = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 1758 | htlcs_info->tell_immediately = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 1759 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 1760 | htlcs_info->htlcs[i] = htlcs[i].htlc; |
| 1761 | htlcs_info->tell_if_missing[i] = htlcs[i].tell_if_missing; |
| 1762 | htlcs_info->tell_immediately[i] = htlcs[i].tell_immediately; |
| 1763 | } |
| 1764 | |
| 1765 | return htlcs_info; |
| 1766 | } |
| 1767 | |
| 1768 | static void handle_mutual_close(struct tracked_output **outs, |
| 1769 | const struct tx_parts *tx) |
no test coverage detected