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

Function onchain_failed_our_htlc

lightningd/peer_htlcs.c:1843–1952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1841}
1842
1843void onchain_failed_our_htlc(const struct channel *channel,
1844 const struct htlc_stub *htlc,
1845 const char *why,
1846 bool should_exist)
1847{
1848 struct lightningd *ld = channel->peer->ld;
1849 struct htlc_out *hout;
1850
1851 log_debug(channel->log, "onchain_failed_our_htlc");
1852 hout = find_htlc_out(ld->htlcs_out, channel, htlc->id);
1853 if (!hout) {
1854 /* For penalty transactions, tell onchaind about all possible
1855 * HTLCs: they may not all exist any more. */
1856 if (should_exist)
1857 log_broken(channel->log, "HTLC id %"PRIu64" not found!",
1858 htlc->id);
1859 /* Immediate corruption sanity check if this happens */
1860 htable_check(&ld->htlcs_out->raw, "onchain_failed_our_htlc out");
1861 htable_check(&ld->htlcs_in->raw, "onchain_failed_our_htlc in");
1862 return;
1863 }
1864
1865 /* We can have hout->failonion (which gets set when we process the
1866 * received commitment_signed), but not failed hin yet, because the peer
1867 * hadn't revoke_and_acked our own commitment without that htlc. */
1868 if (hout->failonion && hout->in
1869 && hout->in->badonion == 0
1870 && !hout->in->failonion
1871 && !hout->in->preimage) {
1872 log_debug(channel->log, "HTLC out %"PRIu64" can now fail HTLC upstream!",
1873 htlc->id);
1874 fail_in_htlc(hout->in, hout->failonion);
1875 }
1876
1877 /* Don't fail twice (or if already succeeded)! */
1878 if (hout->failonion || hout->failmsg || hout->preimage) {
1879 log_debug(channel->log, "HTLC id %"PRIu64" failonion = %p, failmsg = %p, preimage = %p",
1880 htlc->id,
1881 hout->failonion,
1882 hout->failmsg,
1883 hout->preimage);
1884 check_already_failed(channel, hout);
1885 return;
1886 }
1887
1888 hout->failmsg = towire_permanent_channel_failure(hout);
1889
1890 /* Force state to something which expects a failure, and save to db */
1891 hout->hstate = RCVD_REMOVE_HTLC;
1892 htlc_out_check(hout, __func__);
1893
1894 bool we_filled = false;
1895 wallet_htlc_update(ld->wallet, hout->dbid, hout->hstate,
1896 hout->preimage,
1897 max_unsigned(channel->next_index[LOCAL],
1898 channel->next_index[REMOTE]),
1899 0, hout->failonion,
1900 hout->failmsg, &we_filled,

Callers 2

Calls 12

find_htlc_outFunction · 0.85
htable_checkFunction · 0.85
fail_in_htlcFunction · 0.85
check_already_failedFunction · 0.85
htlc_out_checkFunction · 0.85
wallet_htlc_updateFunction · 0.85
payment_failedFunction · 0.85
tal_freeFunction · 0.85
fromwire_peektypeFunction · 0.85
local_fail_in_htlcFunction · 0.70

Tested by

no test coverage detected