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

Function resolve_our_htlc_ourcommit

onchaind/onchaind.c:2297–2392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2295}
2296
2297static size_t resolve_our_htlc_ourcommit(struct tracked_output *out,
2298 const size_t *matches,
2299 const struct htlc_stub *htlcs,
2300 u8 **htlc_scripts)
2301{
2302 struct bitcoin_tx *tx = NULL;
2303 struct bitcoin_signature localsig;
2304 size_t i;
2305 struct amount_msat htlc_amount;
2306 u8 **witness;
2307
2308 if (!amount_sat_to_msat(&htlc_amount, out->sat))
2309 status_failed(STATUS_FAIL_INTERNAL_ERROR,
2310 "Overflow in our_htlc output %s",
2311 type_to_string(tmpctx, struct amount_sat,
2312 &out->sat));
2313
2314 assert(tal_count(matches));
2315
2316 /* These htlcs are all possibilities, but signature will only match
2317 * one with the correct cltv: check which that is. */
2318 for (i = 0; i < tal_count(matches); i++) {
2319 /* Skip over duplicate HTLCs, since we only need one. */
2320 if (i > 0
2321 && (htlcs[matches[i]].cltv_expiry
2322 == htlcs[matches[i-1]].cltv_expiry))
2323 continue;
2324
2325 /* BOLT #5:
2326 *
2327 * ## HTLC Output Handling: Local Commitment, Local Offers
2328 * ...
2329 * - if the commitment transaction HTLC output has *timed out*
2330 * and hasn't been *resolved*:
2331 * - MUST *resolve* the output by spending it using the
2332 * HTLC-timeout transaction.
2333 */
2334 tx = htlc_timeout_tx(tmpctx, chainparams,
2335 &out->outpoint,
2336 htlc_scripts[matches[i]], htlc_amount,
2337 htlcs[matches[i]].cltv_expiry,
2338 to_self_delay[LOCAL], 0, keyset,
2339 option_anchor_outputs);
2340
2341 if (set_htlc_timeout_fee(tx, out->remote_htlc_sig,
2342 htlc_scripts[matches[i]]))
2343 break;
2344 }
2345
2346 /* Since there's been trouble with this before, we go to some length
2347 * to give details here! */
2348 if (i == tal_count(matches)) {
2349 char *cltvs, *wscripts;
2350
2351 cltvs = tal_fmt(tmpctx, "%u", htlcs[matches[0]].cltv_expiry);
2352 wscripts = tal_hex(tmpctx, htlc_scripts[matches[0]]);
2353
2354 for (i = 1; i < tal_count(matches); i++) {

Callers 2

handle_our_unilateralFunction · 0.85
mainFunction · 0.85

Calls 11

set_htlc_timeout_feeFunction · 0.85
tal_hexFunction · 0.85
tal_append_fmtFunction · 0.85
hsm_sign_local_htlc_txFunction · 0.85
amount_sat_to_msatFunction · 0.50
status_failedFunction · 0.50
type_to_stringClass · 0.50
htlc_timeout_txFunction · 0.50

Tested by 1

mainFunction · 0.68