| 1719 | } |
| 1720 | |
| 1721 | static bool peer_failed_our_htlc(struct channel *channel, |
| 1722 | const struct failed_htlc *failed) |
| 1723 | { |
| 1724 | struct htlc_out *hout; |
| 1725 | struct lightningd *ld = channel->peer->ld; |
| 1726 | |
| 1727 | hout = find_htlc_out(ld->htlcs_out, channel, failed->id); |
| 1728 | if (!hout) { |
| 1729 | channel_internal_error(channel, |
| 1730 | "failed_our_htlc unknown htlc %"PRIu64, |
| 1731 | failed->id); |
| 1732 | return false; |
| 1733 | } |
| 1734 | |
| 1735 | if (!htlc_out_update_state(channel, hout, RCVD_REMOVE_COMMIT)) |
| 1736 | return false; |
| 1737 | |
| 1738 | if (failed->sha256_of_onion) { |
| 1739 | struct sha256 our_sha256_of_onion; |
| 1740 | u8 *failmsg; |
| 1741 | |
| 1742 | /* BOLT #2: |
| 1743 | * |
| 1744 | * - if the `sha256_of_onion` in `update_fail_malformed_htlc` |
| 1745 | * doesn't match the onion it sent and is not all zero: |
| 1746 | * - MAY retry or choose an alternate error response. |
| 1747 | */ |
| 1748 | sha256(&our_sha256_of_onion, hout->onion_routing_packet, |
| 1749 | sizeof(hout->onion_routing_packet)); |
| 1750 | if (!sha256_eq(failed->sha256_of_onion, &our_sha256_of_onion) |
| 1751 | && !memeqzero(failed->sha256_of_onion, |
| 1752 | sizeof(failed->sha256_of_onion))) { |
| 1753 | log_unusual(channel->log, |
| 1754 | "update_fail_malformed_htlc for bad onion" |
| 1755 | " for htlc with id %"PRIu64".", |
| 1756 | hout->key.id); |
| 1757 | } |
| 1758 | |
| 1759 | /* BOLT #2: |
| 1760 | * |
| 1761 | * - otherwise, a receiving node which has an outgoing HTLC |
| 1762 | * canceled by `update_fail_malformed_htlc`: |
| 1763 | * |
| 1764 | * - MUST return an error in the `update_fail_htlc` |
| 1765 | * sent to the link which originally sent the HTLC, using the |
| 1766 | * `failure_code` given and setting the data to |
| 1767 | * `sha256_of_onion`. |
| 1768 | */ |
| 1769 | /* All badonion codes are the same form, so we make them |
| 1770 | * manually, which covers any unknown cases too. Grep fodder: |
| 1771 | * towire_invalid_onion_version, towire_invalid_onion_hmac, |
| 1772 | * towire_invalid_onion_key. */ |
| 1773 | failmsg = tal_arr(hout, u8, 0); |
| 1774 | towire_u16(&failmsg, failed->badonion); |
| 1775 | towire_sha256(&failmsg, failed->sha256_of_onion); |
| 1776 | hout->failmsg = failmsg; |
| 1777 | } else { |
| 1778 | hout->failonion = dup_onionreply(hout, failed->onion); |
no test coverage detected