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

Function resend_commitment

channeld/channeld.c:5436–5588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5434}
5435
5436static void resend_commitment(struct peer *peer, struct changed_htlc *last)
5437{
5438 size_t i;
5439 u8 *msg;
5440 u8 **msgs = tal_arr(tmpctx, u8*, 1);
5441 struct local_anchor_info *local_anchor;
5442 u16 batch_size = tal_count(peer->splice_state->inflights) + 1;
5443
5444 status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u,"
5445 " blockheight LOCAL=%u REMOTE=%u",
5446 channel_feerate(peer->channel, LOCAL),
5447 channel_feerate(peer->channel, REMOTE),
5448 channel_blockheight(peer->channel, LOCAL),
5449 channel_blockheight(peer->channel, REMOTE));
5450
5451 /* Note that HTLCs must be *added* in order. Simplest thing to do
5452 * is to sort them all into ascending ID order here (we could do
5453 * this when we save them in channel_sending_commit, but older versions
5454 * won't have them sorted in the db, so doing it here is better). */
5455 if (last)
5456 asort(last, tal_count(last), cmp_changed_htlc_id, NULL);
5457
5458 /* BOLT #2:
5459 *
5460 * - if `next_commitment_number` is equal to the commitment
5461 * number of the last `commitment_signed` message the receiving node
5462 * has sent:
5463 * - MUST reuse the same commitment number for its next
5464 * `commitment_signed`.
5465 */
5466 /* In our case, we consider ourselves already committed to this, so
5467 * retransmission is simplest. */
5468 /* We need to send fulfills/failures before adds, so we split them
5469 * up into two loops -- this is the 'fulfill/fail' loop */
5470 for (i = 0; i < tal_count(last); i++) {
5471 const struct htlc *h;
5472
5473 h = channel_get_htlc(peer->channel,
5474 htlc_state_owner(last[i].newstate),
5475 last[i].id);
5476 /* I think this can happen if we actually received revoke_and_ack
5477 * then they asked for a retransmit */
5478 if (!h)
5479 peer_failed_warn(peer->pps, &peer->channel_id,
5480 "Can't find HTLC %"PRIu64" to resend",
5481 last[i].id);
5482
5483 if (h->state == SENT_REMOVE_COMMIT)
5484 send_fail_or_fulfill(peer, h);
5485 }
5486 /* We need to send fulfills/failures before adds, so we split them
5487 * up into two loops -- this is the 'add' loop */
5488 for (i = 0; i < tal_count(last); i++) {
5489 const struct htlc *h;
5490
5491 h = channel_get_htlc(peer->channel,
5492 htlc_state_owner(last[i].newstate),
5493 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