| 361 | } |
| 362 | |
| 363 | static void fail(struct info *info, |
| 364 | struct fake_htlc *htlc STEALS, |
| 365 | const struct onion_payload *payload, |
| 366 | enum onion_wire failcode) |
| 367 | { |
| 368 | struct failed_htlc *failed; |
| 369 | const struct failed_htlc **failed_arr; |
| 370 | u8 *msg; |
| 371 | struct changed_htlc *changed; |
| 372 | enum channel_remove_err err; |
| 373 | |
| 374 | msg = tal_arr(tmpctx, u8, 0); |
| 375 | towire_u16(&msg, failcode); |
| 376 | |
| 377 | status_debug("Failing payment at %s due to %s", |
| 378 | fmt_node_id(tmpctx, ¤t_node->id), |
| 379 | onion_wire_name(failcode)); |
| 380 | |
| 381 | err = channel_fail_htlc(info->channel, |
| 382 | LOCAL, |
| 383 | htlc->htlc_id, |
| 384 | NULL); |
| 385 | assert(err == CHANNEL_ERR_REMOVE_OK); |
| 386 | |
| 387 | failed_arr = tal_arr(tmpctx, const struct failed_htlc *, 1); |
| 388 | failed_arr[0] = failed = tal(failed_arr, struct failed_htlc); |
| 389 | failed->id = htlc->htlc_id; |
| 390 | failed->sha256_of_onion = NULL; |
| 391 | failed->onion = create_onionreply(failed, &htlc->secrets[tal_count(htlc->secrets) - 1], msg); |
| 392 | |
| 393 | /* We create backwards, using shared secrets to wrap */ |
| 394 | for (int i = tal_count(htlc->secrets) - 1; i >= 0; i--) |
| 395 | failed->onion = wrap_onionreply(failed, &htlc->secrets[i], failed->onion); |
| 396 | |
| 397 | msg = towire_channeld_got_commitsig(NULL, |
| 398 | info->commit_num, |
| 399 | info->fee_states, |
| 400 | info->blockheight_states, |
| 401 | &info->fakesig, |
| 402 | NULL, |
| 403 | NULL, |
| 404 | NULL, |
| 405 | failed_arr, |
| 406 | NULL, |
| 407 | info->commit_tx, |
| 408 | NULL); |
| 409 | daemon_conn_send(info->dc, take(msg)); |
| 410 | |
| 411 | changed = tal_arr(tmpctx, struct changed_htlc, 1); |
| 412 | changed->id = htlc->htlc_id; |
| 413 | changed->newstate = SENT_REMOVE_ACK_COMMIT; |
| 414 | |
| 415 | /* Tell it we committed, too */ |
| 416 | msg = towire_channeld_sending_commitsig(NULL, |
| 417 | info->commit_num, |
| 418 | NULL, |
| 419 | info->fee_states, |
| 420 | info->blockheight_states, |