MCPcopy Create free account
hub / github.com/ElementsProject/lightning / peer_failed_our_htlc

Function peer_failed_our_htlc

lightningd/peer_htlcs.c:1791–1867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1789}
1790
1791static 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);

Callers 1

peer_got_commitsigFunction · 0.85

Calls 12

find_htlc_outFunction · 0.85
htlc_out_update_stateFunction · 0.85
memeqzeroFunction · 0.85
dup_onionreplyFunction · 0.85
fromwire_peektypeFunction · 0.85
htlc_out_checkFunction · 0.85
channel_internal_errorFunction · 0.70
sha256Class · 0.70
towire_u16Function · 0.50
towire_sha256Function · 0.50

Tested by

no test coverage detected