| 1873 | } |
| 1874 | |
| 1875 | static struct htlcs_info *init_reply(const tal_t *ctx, const char *what, |
| 1876 | bool our_commitment) |
| 1877 | { |
| 1878 | struct htlcs_info *htlcs_info = tal(ctx, struct htlcs_info); |
| 1879 | const u8 *msg; |
| 1880 | struct htlc_with_tells *htlcs; |
| 1881 | |
| 1882 | /* commit_num is 0 for mutual close, but we don't care about HTLCs |
| 1883 | * then anyway. */ |
| 1884 | |
| 1885 | /* Send init_reply first, so billboard gets credited to ONCHAIND */ |
| 1886 | wire_sync_write(REQ_FD, |
| 1887 | take(towire_onchaind_init_reply(NULL, commit_num, |
| 1888 | our_commitment))); |
| 1889 | |
| 1890 | peer_billboard(true, "%s", what); |
| 1891 | |
| 1892 | /* Read in htlcs (ignoring everything else for now) */ |
| 1893 | msg = queue_until_msg(tmpctx, WIRE_ONCHAIND_HTLCS); |
| 1894 | if (!fromwire_onchaind_htlcs(htlcs_info, msg, |
| 1895 | &htlcs_info->htlcs, |
| 1896 | &htlcs_info->tell_if_missing, |
| 1897 | &htlcs_info->tell_immediately, |
| 1898 | &htlcs_info->present)) |
| 1899 | master_badmsg(WIRE_ONCHAIND_HTLCS, msg); |
| 1900 | |
| 1901 | /* One convenient structure, so we sort them together! */ |
| 1902 | htlcs = tal_arr(tmpctx, struct htlc_with_tells, tal_count(htlcs_info->htlcs)); |
| 1903 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 1904 | htlcs[i].htlc = htlcs_info->htlcs[i]; |
| 1905 | htlcs[i].tell_if_missing = htlcs_info->tell_if_missing[i]; |
| 1906 | htlcs[i].tell_immediately = htlcs_info->tell_immediately[i]; |
| 1907 | htlcs[i].present = htlcs_info->present[i]; |
| 1908 | } |
| 1909 | |
| 1910 | /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups), |
| 1911 | * with the ones which are really in this tx first. */ |
| 1912 | asort(htlcs, tal_count(htlcs), cmp_htlc_with_tells_cltv, NULL); |
| 1913 | |
| 1914 | /* Now put them back (prev were allocated off tmpctx) */ |
| 1915 | htlcs_info->htlcs = tal_arr(htlcs_info, struct htlc_stub, tal_count(htlcs)); |
| 1916 | htlcs_info->tell_if_missing = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 1917 | htlcs_info->tell_immediately = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 1918 | htlcs_info->present = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 1919 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 1920 | htlcs_info->htlcs[i] = htlcs[i].htlc; |
| 1921 | htlcs_info->tell_if_missing[i] = htlcs[i].tell_if_missing; |
| 1922 | htlcs_info->tell_immediately[i] = htlcs[i].tell_immediately; |
| 1923 | htlcs_info->present[i] = htlcs[i].present; |
| 1924 | } |
| 1925 | |
| 1926 | return htlcs_info; |
| 1927 | } |
| 1928 | |
| 1929 | static void handle_mutual_close(struct tracked_output **outs, |
| 1930 | const struct tx_parts *tx) |
no test coverage detected