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

Function update_out_htlc

lightningd/peer_htlcs.c:1826–1876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1824}
1825
1826static bool update_out_htlc(struct channel *channel,
1827 u64 id, enum htlc_state newstate)
1828{
1829 struct lightningd *ld = channel->peer->ld;
1830 struct htlc_out *hout;
1831 struct wallet_payment *payment;
1832
1833 hout = find_htlc_out(&ld->htlcs_out, channel, id);
1834 if (!hout) {
1835 channel_internal_error(channel, "Can't find out HTLC %"PRIu64, id);
1836 return false;
1837 }
1838
1839 if (!hout->dbid) {
1840 wallet_htlc_save_out(ld->wallet, channel, hout);
1841 /* Update channel stats */
1842 wallet_channel_stats_incr_out_offered(ld->wallet,
1843 channel->dbid,
1844 hout->msat);
1845
1846 if (hout->in) {
1847 wallet_forwarded_payment_add(ld->wallet, hout->in,
1848 FORWARD_STYLE_TLV,
1849 channel_scid_or_local_alias(channel), hout,
1850 FORWARD_OFFERED, 0);
1851 }
1852
1853 /* For our own HTLCs, we commit payment to db lazily */
1854 if (hout->am_origin) {
1855 payment = wallet_payment_by_hash(tmpctx, ld->wallet,
1856 &hout->payment_hash,
1857 hout->partid,
1858 hout->groupid);
1859 assert(payment);
1860 payment_store(ld, take(payment));
1861 }
1862 }
1863
1864 if (!htlc_out_update_state(channel, hout, newstate))
1865 return false;
1866
1867 /* First transition into commitment; now it outlives peer. */
1868 if (newstate == SENT_ADD_COMMIT) {
1869 tal_del_destructor(hout, destroy_hout_subd_died);
1870 hout->timeout = tal_free(hout->timeout);
1871 tal_steal(ld, hout);
1872 } else if (newstate == RCVD_REMOVE_ACK_REVOCATION) {
1873 remove_htlc_out(channel, hout);
1874 }
1875 return true;
1876}
1877
1878static bool changed_htlc(struct channel *channel,
1879 const struct changed_htlc *changed)

Callers 2

changed_htlcFunction · 0.85
peer_sending_revocationFunction · 0.85

Calls 11

find_htlc_outFunction · 0.85
wallet_htlc_save_outFunction · 0.85
wallet_payment_by_hashFunction · 0.85
htlc_out_update_stateFunction · 0.85
tal_freeFunction · 0.85
remove_htlc_outFunction · 0.85
channel_internal_errorFunction · 0.70
payment_storeFunction · 0.70

Tested by

no test coverage detected