| 244 | }; |
| 245 | |
| 246 | void run(const u8 *data, size_t size) |
| 247 | { |
| 248 | struct pubkey local_per_commitment_point; |
| 249 | struct bitcoin_outpoint funding; |
| 250 | struct amount_sat funding_amount; |
| 251 | struct channel *lchannel, *rchannel; |
| 252 | const struct htlc **htlc_map; |
| 253 | const u8 *funding_wscript_alt; |
| 254 | int anchor; |
| 255 | struct pending_htlc *pending_htlcs = tal_arr(tmpctx, struct pending_htlc, 0); |
| 256 | u64 next_htlc_id = 0; |
| 257 | u32 current_blockheight = fromwire_u32(&data, &size); |
| 258 | |
| 259 | init_channels(tmpctx, &data, &size, &local_per_commitment_point, &funding, &funding_amount, |
| 260 | ¤t_blockheight, &lchannel, &rchannel); |
| 261 | |
| 262 | if (!lchannel || !rchannel) |
| 263 | goto cleanup; |
| 264 | |
| 265 | while (size > 0) { |
| 266 | enum side commit_side = LOCAL; |
| 267 | int op = fromwire_u8(&data, &size) % 7; |
| 268 | switch (op) { |
| 269 | case 0: /* ADD_HTLC */ |
| 270 | { |
| 271 | if (tal_count(pending_htlcs) > MAX_HTLCS) |
| 272 | break; |
| 273 | |
| 274 | enum side sender = (fromwire_u8(&data, &size) % 2) ? REMOTE : LOCAL; |
| 275 | struct amount_msat msat = fromwire_amount_msat_bounded(&data, &size); |
| 276 | u32 cltv = current_blockheight + fromwire_u16(&data, &size); |
| 277 | struct pending_htlc p_htlc; |
| 278 | |
| 279 | p_htlc.sender = sender; |
| 280 | p_htlc.id = next_htlc_id; |
| 281 | memset(&p_htlc.preimage, (int)p_htlc.id, sizeof(p_htlc.preimage)); |
| 282 | |
| 283 | if (add_htlc(lchannel, sender, p_htlc.id, &p_htlc.preimage, msat, cltv)) { |
| 284 | add_htlc(rchannel, sender, p_htlc.id, &p_htlc.preimage, msat, cltv); |
| 285 | tal_arr_expand(&pending_htlcs, p_htlc); |
| 286 | next_htlc_id++; |
| 287 | } |
| 288 | commit_side = sender; |
| 289 | break; |
| 290 | } |
| 291 | case 1: /* FULFILL_HTLC */ |
| 292 | { |
| 293 | if (tal_count(pending_htlcs) == 0) |
| 294 | break; |
| 295 | |
| 296 | size_t idx = fromwire_u64(&data, &size) % tal_count(pending_htlcs); |
| 297 | struct pending_htlc p_htlc = pending_htlcs[idx]; |
| 298 | |
| 299 | if (fromwire_u8(&data, &size) % 2) { |
| 300 | if (fulfill_htlc(lchannel, p_htlc.sender, p_htlc.id, &p_htlc.preimage)) { |
| 301 | fulfill_htlc(rchannel, p_htlc.sender, p_htlc.id, &p_htlc.preimage); |
| 302 | tal_arr_remove(&pending_htlcs, idx); |
| 303 | } |
nothing calls this directly
no test coverage detected