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

Function resolve_our_htlc_ourcommit

onchaind/onchaind.c:1981–2086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1979}
1980
1981static size_t resolve_our_htlc_ourcommit(struct tracked_output *out,
1982 const size_t *matches,
1983 const struct htlc_stub *htlcs,
1984 u8 **htlc_scripts)
1985{
1986 struct bitcoin_tx *tx = NULL;
1987 size_t i;
1988 struct amount_sat fee;
1989 struct amount_msat htlc_amount;
1990 const u8 *msg, *htlc_wscript;
1991
1992 if (!amount_sat_to_msat(&htlc_amount, out->sat))
1993 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1994 "Overflow in our_htlc output %s",
1995 fmt_amount_sat(tmpctx, out->sat));
1996
1997 assert(tal_count(matches));
1998
1999 /* These htlcs are all possibilities, but signature will only match
2000 * one with the correct cltv: check which that is. */
2001 for (i = 0; i < tal_count(matches); i++) {
2002 /* Skip over duplicate HTLCs, since we only need one. */
2003 if (i > 0
2004 && (htlcs[matches[i]].cltv_expiry
2005 == htlcs[matches[i-1]].cltv_expiry))
2006 continue;
2007
2008 /* BOLT #5:
2009 *
2010 * A node:
2011 * ...
2012 * - if the commitment transaction HTLC output has *timed out*
2013 * and hasn't been *resolved*:
2014 * - MUST *resolve* the output by spending it using the
2015 * HTLC-timeout transaction.
2016 */
2017 tx = htlc_timeout_tx(tmpctx, chainparams,
2018 &out->outpoint,
2019 htlc_scripts[matches[i]], htlc_amount,
2020 htlcs[matches[i]].cltv_expiry,
2021 to_self_delay[LOCAL], 0, keyset,
2022 option_anchor_outputs,
2023 option_anchors_zero_fee_htlc_tx);
2024
2025 if (set_htlc_timeout_fee(tx, out->remote_htlc_sig,
2026 htlc_scripts[matches[i]]))
2027 break;
2028 }
2029
2030 /* Since there's been trouble with this before, we go to some length
2031 * to give details here! */
2032 if (i == tal_count(matches)) {
2033 char *cltvs, *wscripts;
2034
2035 cltvs = tal_fmt(tmpctx, "%u", htlcs[matches[0]].cltv_expiry);
2036 wscripts = tal_hex(tmpctx, htlc_scripts[matches[0]]);
2037
2038 for (i = 1; i < tal_count(matches); i++) {

Callers 2

handle_our_unilateralFunction · 0.85
mainFunction · 0.85

Calls 13

set_htlc_timeout_feeFunction · 0.85
tal_hexFunction · 0.85
tal_append_fmtFunction · 0.85
fmt_bitcoin_txFunction · 0.85
fmt_bitcoin_signatureFunction · 0.85
bitcoin_wscript_htlc_txFunction · 0.85
bitcoin_tx_compute_feeFunction · 0.85
amount_sat_to_msatFunction · 0.50
status_failedFunction · 0.50
fmt_amount_satFunction · 0.50

Tested by 1

mainFunction · 0.68