| 1789 | } |
| 1790 | |
| 1791 | static bool peer_failed_our_htlc(struct channel *channel, |
| 1792 | const struct failed_htlc *failed) |
| 1793 | { |
| 1794 | struct htlc_out *hout; |
| 1795 | struct lightningd *ld = channel->peer->ld; |
| 1796 | |
| 1797 | hout = find_htlc_out(ld->htlcs_out, channel, failed->id); |
| 1798 | if (!hout) { |
| 1799 | channel_internal_error(channel, |
| 1800 | "failed_our_htlc unknown htlc %"PRIu64, |
| 1801 | failed->id); |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
| 1805 | if (!htlc_out_update_state(channel, hout, RCVD_REMOVE_COMMIT)) |
| 1806 | return false; |
| 1807 | |
| 1808 | if (failed->sha256_of_onion) { |
| 1809 | struct sha256 our_sha256_of_onion; |
| 1810 | u8 *failmsg; |
| 1811 | |
| 1812 | /* BOLT #2: |
| 1813 | * |
| 1814 | * - if the `sha256_of_onion` in `update_fail_malformed_htlc` |
| 1815 | * doesn't match the onion it sent and is not all zero: |
| 1816 | * - MAY retry or choose an alternate error response. |
| 1817 | */ |
| 1818 | sha256(&our_sha256_of_onion, hout->onion_routing_packet, |
| 1819 | sizeof(hout->onion_routing_packet)); |
| 1820 | if (!sha256_eq(failed->sha256_of_onion, &our_sha256_of_onion) |
| 1821 | && !memeqzero(failed->sha256_of_onion, |
| 1822 | sizeof(failed->sha256_of_onion))) { |
| 1823 | log_unusual(channel->log, |
| 1824 | "update_fail_malformed_htlc for bad onion" |
| 1825 | " for htlc with id %"PRIu64".", |
| 1826 | hout->key.id); |
| 1827 | } |
| 1828 | |
| 1829 | /* BOLT #2: |
| 1830 | * |
| 1831 | * - otherwise, a receiving node which has an outgoing HTLC |
| 1832 | * canceled by `update_fail_malformed_htlc`: |
| 1833 | * |
| 1834 | * - MUST return an error in the `update_fail_htlc` |
| 1835 | * sent to the link which originally sent the HTLC, using the |
| 1836 | * `failure_code` given and setting the data to |
| 1837 | * `sha256_of_onion`. |
| 1838 | */ |
| 1839 | /* All badonion codes are the same form, so we make them |
| 1840 | * manually, which covers any unknown cases too. Grep fodder: |
| 1841 | * towire_invalid_onion_version, towire_invalid_onion_hmac, |
| 1842 | * towire_invalid_onion_key. */ |
| 1843 | failmsg = tal_arr(hout, u8, 0); |
| 1844 | towire_u16(&failmsg, failed->badonion); |
| 1845 | towire_sha256(&failmsg, failed->sha256_of_onion); |
| 1846 | hout->failmsg = failmsg; |
| 1847 | } else { |
| 1848 | hout->failonion = dup_onionreply(hout, failed->onion); |
no test coverage detected