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

Function resend_commitment

channeld/channeld.c:5510–5662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5508}
5509
5510static void resend_commitment(struct peer *peer, struct changed_htlc *last)
5511{
5512 size_t i;
5513 u8 *msg;
5514 u8 **msgs = tal_arr(tmpctx, u8*, 1);
5515 struct local_anchor_info *local_anchor;
5516 u16 batch_size = tal_count(peer->splice_state->inflights) + 1;
5517
5518 status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u,"
5519 " blockheight LOCAL=%u REMOTE=%u",
5520 channel_feerate(peer->channel, LOCAL),
5521 channel_feerate(peer->channel, REMOTE),
5522 channel_blockheight(peer->channel, LOCAL),
5523 channel_blockheight(peer->channel, REMOTE));
5524
5525 /* Note that HTLCs must be *added* in order. Simplest thing to do
5526 * is to sort them all into ascending ID order here (we could do
5527 * this when we save them in channel_sending_commit, but older versions
5528 * won't have them sorted in the db, so doing it here is better). */
5529 if (last)
5530 asort(last, tal_count(last), cmp_changed_htlc_id, NULL);
5531
5532 /* BOLT #2:
5533 *
5534 * - if `next_commitment_number` is equal to the commitment
5535 * number of the last `commitment_signed` message the receiving node
5536 * has sent:
5537 * - MUST reuse the same commitment number for its next
5538 * `commitment_signed`.
5539 */
5540 /* In our case, we consider ourselves already committed to this, so
5541 * retransmission is simplest. */
5542 /* We need to send fulfills/failures before adds, so we split them
5543 * up into two loops -- this is the 'fulfill/fail' loop */
5544 for (i = 0; i < tal_count(last); i++) {
5545 const struct htlc *h;
5546
5547 h = channel_get_htlc(peer->channel,
5548 htlc_state_owner(last[i].newstate),
5549 last[i].id);
5550 /* I think this can happen if we actually received revoke_and_ack
5551 * then they asked for a retransmit */
5552 if (!h)
5553 peer_failed_warn(peer->pps, &peer->channel_id,
5554 "Can't find HTLC %"PRIu64" to resend",
5555 last[i].id);
5556
5557 if (h->state == SENT_REMOVE_COMMIT)
5558 send_fail_or_fulfill(peer, h);
5559 }
5560 /* We need to send fulfills/failures before adds, so we split them
5561 * up into two loops -- this is the 'add' loop */
5562 for (i = 0; i < tal_count(last); i++) {
5563 const struct htlc *h;
5564
5565 h = channel_get_htlc(peer->channel,
5566 htlc_state_owner(last[i].newstate),
5567 last[i].id);

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
send_commit_partFunction · 0.85
sats_diffFunction · 0.85
send_message_batchFunction · 0.85

Tested by

no test coverage detected