| 2191 | } |
| 2192 | |
| 2193 | static struct htlcs_info *init_reply(const tal_t *ctx, const char *what) |
| 2194 | { |
| 2195 | struct htlcs_info *htlcs_info = tal(ctx, struct htlcs_info); |
| 2196 | u8 *msg; |
| 2197 | struct htlc_with_tells *htlcs; |
| 2198 | |
| 2199 | /* commit_num is 0 for mutual close, but we don't care about HTLCs |
| 2200 | * then anyway. */ |
| 2201 | |
| 2202 | /* Send init_reply first, so billboard gets credited to ONCHAIND */ |
| 2203 | wire_sync_write(REQ_FD, |
| 2204 | take(towire_onchaind_init_reply(NULL, commit_num))); |
| 2205 | |
| 2206 | peer_billboard(true, what); |
| 2207 | |
| 2208 | /* Read in htlcs */ |
| 2209 | for (;;) { |
| 2210 | msg = wire_sync_read(queued_msgs, REQ_FD); |
| 2211 | if (fromwire_onchaind_htlcs(tmpctx, msg, |
| 2212 | &htlcs_info->htlcs, |
| 2213 | &htlcs_info->tell_if_missing, |
| 2214 | &htlcs_info->tell_immediately)) { |
| 2215 | tal_free(msg); |
| 2216 | break; |
| 2217 | } |
| 2218 | |
| 2219 | /* Process later */ |
| 2220 | tal_arr_expand(&queued_msgs, msg); |
| 2221 | } |
| 2222 | |
| 2223 | /* One convenient structure, so we sort them together! */ |
| 2224 | htlcs = tal_arr(tmpctx, struct htlc_with_tells, tal_count(htlcs_info->htlcs)); |
| 2225 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 2226 | htlcs[i].htlc = htlcs_info->htlcs[i]; |
| 2227 | htlcs[i].tell_if_missing = htlcs_info->tell_if_missing[i]; |
| 2228 | htlcs[i].tell_immediately = htlcs_info->tell_immediately[i]; |
| 2229 | } |
| 2230 | |
| 2231 | /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups) */ |
| 2232 | asort(htlcs, tal_count(htlcs), cmp_htlc_with_tells_cltv, NULL); |
| 2233 | |
| 2234 | /* Now put them back (prev were allocated off tmpctx) */ |
| 2235 | htlcs_info->htlcs = tal_arr(htlcs_info, struct htlc_stub, tal_count(htlcs)); |
| 2236 | htlcs_info->tell_if_missing = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 2237 | htlcs_info->tell_immediately = tal_arr(htlcs_info, bool, tal_count(htlcs)); |
| 2238 | for (size_t i = 0; i < tal_count(htlcs); i++) { |
| 2239 | htlcs_info->htlcs[i] = htlcs[i].htlc; |
| 2240 | htlcs_info->tell_if_missing[i] = htlcs[i].tell_if_missing; |
| 2241 | htlcs_info->tell_immediately[i] = htlcs[i].tell_immediately; |
| 2242 | } |
| 2243 | |
| 2244 | return htlcs_info; |
| 2245 | } |
| 2246 | |
| 2247 | static void handle_mutual_close(struct tracked_output **outs, |
| 2248 | const struct tx_parts *tx) |
no test coverage detected