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

Function htlcs_notify_new_block

lightningd/peer_htlcs.c:2585–2679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2583}
2584
2585void htlcs_notify_new_block(struct lightningd *ld, u32 height)
2586{
2587 bool removed;
2588
2589 /* BOLT #2:
2590 *
2591 * - if an HTLC which it offered is in either node's current
2592 * commitment transaction, AND is past this timeout deadline:
2593 * - SHOULD send an `error` to the receiving peer (if connected).
2594 * - MUST fail the channel.
2595 */
2596 /* FIXME: use db to look this up in one go (earliest deadline per-peer) */
2597 do {
2598 struct htlc_out *hout;
2599 struct htlc_out_map_iter outi;
2600
2601 removed = false;
2602
2603 for (hout = htlc_out_map_first(&ld->htlcs_out, &outi);
2604 hout;
2605 hout = htlc_out_map_next(&ld->htlcs_out, &outi)) {
2606 /* Not timed out yet? */
2607 if (height < htlc_out_deadline(hout))
2608 continue;
2609
2610 /* Peer on chain already? */
2611 if (channel_on_chain(hout->key.channel))
2612 continue;
2613
2614 /* Peer already failed, or we hit it? */
2615 if (hout->key.channel->error)
2616 continue;
2617
2618 channel_fail_permanent(hout->key.channel,
2619 REASON_PROTOCOL,
2620 "Offered HTLC %"PRIu64
2621 " %s cltv %u hit deadline",
2622 hout->key.id,
2623 htlc_state_name(hout->hstate),
2624 hout->cltv_expiry);
2625 removed = true;
2626 }
2627 /* Iteration while removing is safe, but can skip entries! */
2628 } while (removed);
2629
2630
2631 /* BOLT #2:
2632 *
2633 * - for each HTLC it is attempting to fulfill:
2634 * - MUST estimate a fulfillment deadline.
2635 *...
2636 * - if an HTLC it has fulfilled is in either node's current commitment
2637 * transaction, AND is past this fulfillment deadline:
2638 * - SHOULD send an `error` to the offering peer (if connected).
2639 * - MUST fail the channel.
2640 */
2641 do {
2642 struct htlc_in *hin;

Callers 1

notify_new_blockFunction · 0.70

Calls 5

htlc_out_deadlineFunction · 0.85
channel_on_chainFunction · 0.85
htlc_in_deadlineFunction · 0.85
channel_fail_permanentFunction · 0.70
htlc_state_nameFunction · 0.50

Tested by

no test coverage detected