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

Function peer_failed_our_htlc

lightningd/peer_htlcs.c:1747–1823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1745}
1746
1747static bool peer_failed_our_htlc(struct channel *channel,
1748 const struct failed_htlc *failed)
1749{
1750 struct htlc_out *hout;
1751 struct lightningd *ld = channel->peer->ld;
1752
1753 hout = find_htlc_out(ld->htlcs_out, channel, failed->id);
1754 if (!hout) {
1755 channel_internal_error(channel,
1756 "failed_our_htlc unknown htlc %"PRIu64,
1757 failed->id);
1758 return false;
1759 }
1760
1761 if (!htlc_out_update_state(channel, hout, RCVD_REMOVE_COMMIT))
1762 return false;
1763
1764 if (failed->sha256_of_onion) {
1765 struct sha256 our_sha256_of_onion;
1766 u8 *failmsg;
1767
1768 /* BOLT #2:
1769 *
1770 * - if the `sha256_of_onion` in `update_fail_malformed_htlc`
1771 * doesn't match the onion it sent and is not all zero:
1772 * - MAY retry or choose an alternate error response.
1773 */
1774 sha256(&our_sha256_of_onion, hout->onion_routing_packet,
1775 sizeof(hout->onion_routing_packet));
1776 if (!sha256_eq(failed->sha256_of_onion, &our_sha256_of_onion)
1777 && !memeqzero(failed->sha256_of_onion,
1778 sizeof(failed->sha256_of_onion))) {
1779 log_unusual(channel->log,
1780 "update_fail_malformed_htlc for bad onion"
1781 " for htlc with id %"PRIu64".",
1782 hout->key.id);
1783 }
1784
1785 /* BOLT #2:
1786 *
1787 * - otherwise, a receiving node which has an outgoing HTLC
1788 * canceled by `update_fail_malformed_htlc`:
1789 *
1790 * - MUST return an error in the `update_fail_htlc`
1791 * sent to the link which originally sent the HTLC, using the
1792 * `failure_code` given and setting the data to
1793 * `sha256_of_onion`.
1794 */
1795 /* All badonion codes are the same form, so we make them
1796 * manually, which covers any unknown cases too. Grep fodder:
1797 * towire_invalid_onion_version, towire_invalid_onion_hmac,
1798 * towire_invalid_onion_key. */
1799 failmsg = tal_arr(hout, u8, 0);
1800 towire_u16(&failmsg, failed->badonion);
1801 towire_sha256(&failmsg, failed->sha256_of_onion);
1802 hout->failmsg = failmsg;
1803 } else {
1804 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