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

Function resend_commitment

channeld/channeld.c:2370–2493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2368}
2369
2370static void resend_commitment(struct peer *peer, struct changed_htlc *last)
2371{
2372 size_t i;
2373 struct bitcoin_signature commit_sig, *htlc_sigs;
2374 u8 *msg;
2375 struct bitcoin_tx **txs;
2376 const u8 *funding_wscript;
2377 const struct htlc **htlc_map;
2378 struct wally_tx_output *direct_outputs[NUM_SIDES];
2379
2380 status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u,"
2381 " blockheight LOCAL=%u REMOTE=%u",
2382 channel_feerate(peer->channel, LOCAL),
2383 channel_feerate(peer->channel, REMOTE),
2384 channel_blockheight(peer->channel, LOCAL),
2385 channel_blockheight(peer->channel, REMOTE));
2386
2387 /* Note that HTLCs must be *added* in order. Simplest thing to do
2388 * is to sort them all into ascending ID order here (we could do
2389 * this when we save them in channel_sending_commit, but older versions
2390 * won't have them sorted in the db, so doing it here is better). */
2391 asort(last, tal_count(last), cmp_changed_htlc_id, NULL);
2392
2393 /* BOLT #2:
2394 *
2395 * - if `next_commitment_number` is equal to the commitment
2396 * number of the last `commitment_signed` message the receiving node
2397 * has sent:
2398 * - MUST reuse the same commitment number for its next
2399 * `commitment_signed`.
2400 */
2401 /* In our case, we consider ourselves already committed to this, so
2402 * retransmission is simplest. */
2403 /* We need to send fulfills/failures before adds, so we split them
2404 * up into two loops -- this is the 'fulfill/fail' loop */
2405 for (i = 0; i < tal_count(last); i++) {
2406 const struct htlc *h;
2407
2408 h = channel_get_htlc(peer->channel,
2409 htlc_state_owner(last[i].newstate),
2410 last[i].id);
2411 /* I think this can happen if we actually received revoke_and_ack
2412 * then they asked for a retransmit */
2413 if (!h)
2414 peer_failed_warn(peer->pps, &peer->channel_id,
2415 "Can't find HTLC %"PRIu64" to resend",
2416 last[i].id);
2417
2418 if (h->state == SENT_REMOVE_COMMIT)
2419 send_fail_or_fulfill(peer, h);
2420 }
2421 /* We need to send fulfills/failures before adds, so we split them
2422 * up into two loops -- this is the 'add' loop */
2423 for (i = 0; i < tal_count(last); i++) {
2424 const struct htlc *h;
2425
2426 h = channel_get_htlc(peer->channel,
2427 htlc_state_owner(last[i].newstate),

Callers 1

peer_reconnectFunction · 0.85

Calls 11

channel_feerateFunction · 0.85
channel_blockheightFunction · 0.85
channel_get_htlcFunction · 0.85
htlc_state_ownerFunction · 0.85
peer_failed_warnFunction · 0.85
send_fail_or_fulfillFunction · 0.85
abs_locktime_to_blocksFunction · 0.85
peer_writeFunction · 0.85
channel_txsFunction · 0.85
calc_commitsigsFunction · 0.85
raw_sigsFunction · 0.85

Tested by

no test coverage detected