| 5301 | } |
| 5302 | |
| 5303 | static void resend_commitment(struct peer *peer, struct changed_htlc *last) |
| 5304 | { |
| 5305 | size_t i; |
| 5306 | u8 *msg; |
| 5307 | u8 **msgs = tal_arr(tmpctx, u8*, 1); |
| 5308 | struct local_anchor_info *local_anchor; |
| 5309 | u16 batch_size = tal_count(peer->splice_state->inflights) + 1; |
| 5310 | |
| 5311 | status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u," |
| 5312 | " blockheight LOCAL=%u REMOTE=%u", |
| 5313 | channel_feerate(peer->channel, LOCAL), |
| 5314 | channel_feerate(peer->channel, REMOTE), |
| 5315 | channel_blockheight(peer->channel, LOCAL), |
| 5316 | channel_blockheight(peer->channel, REMOTE)); |
| 5317 | |
| 5318 | /* Note that HTLCs must be *added* in order. Simplest thing to do |
| 5319 | * is to sort them all into ascending ID order here (we could do |
| 5320 | * this when we save them in channel_sending_commit, but older versions |
| 5321 | * won't have them sorted in the db, so doing it here is better). */ |
| 5322 | if (last) |
| 5323 | asort(last, tal_count(last), cmp_changed_htlc_id, NULL); |
| 5324 | |
| 5325 | /* BOLT #2: |
| 5326 | * |
| 5327 | * - if `next_commitment_number` is equal to the commitment |
| 5328 | * number of the last `commitment_signed` message the receiving node |
| 5329 | * has sent: |
| 5330 | * - MUST reuse the same commitment number for its next |
| 5331 | * `commitment_signed`. |
| 5332 | */ |
| 5333 | /* In our case, we consider ourselves already committed to this, so |
| 5334 | * retransmission is simplest. */ |
| 5335 | /* We need to send fulfills/failures before adds, so we split them |
| 5336 | * up into two loops -- this is the 'fulfill/fail' loop */ |
| 5337 | for (i = 0; i < tal_count(last); i++) { |
| 5338 | const struct htlc *h; |
| 5339 | |
| 5340 | h = channel_get_htlc(peer->channel, |
| 5341 | htlc_state_owner(last[i].newstate), |
| 5342 | last[i].id); |
| 5343 | /* I think this can happen if we actually received revoke_and_ack |
| 5344 | * then they asked for a retransmit */ |
| 5345 | if (!h) |
| 5346 | peer_failed_warn(peer->pps, &peer->channel_id, |
| 5347 | "Can't find HTLC %"PRIu64" to resend", |
| 5348 | last[i].id); |
| 5349 | |
| 5350 | if (h->state == SENT_REMOVE_COMMIT) |
| 5351 | send_fail_or_fulfill(peer, h); |
| 5352 | } |
| 5353 | /* We need to send fulfills/failures before adds, so we split them |
| 5354 | * up into two loops -- this is the 'add' loop */ |
| 5355 | for (i = 0; i < tal_count(last); i++) { |
| 5356 | const struct htlc *h; |
| 5357 | |
| 5358 | h = channel_get_htlc(peer->channel, |
| 5359 | htlc_state_owner(last[i].newstate), |
| 5360 | last[i].id); |
no test coverage detected