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

Function peer_htlcs

lightningd/peer_htlcs.c:2741–2815  ·  view source on GitHub ↗

FIXME: Load direct from db. */

Source from the content-addressed store, hash-verified

2739
2740/* FIXME: Load direct from db. */
2741const struct existing_htlc **peer_htlcs(const tal_t *ctx,
2742 const struct channel *channel)
2743{
2744 struct existing_htlc **htlcs;
2745 struct htlc_in_map_iter ini;
2746 struct htlc_out_map_iter outi;
2747 struct htlc_in *hin;
2748 struct htlc_out *hout;
2749 struct lightningd *ld = channel->peer->ld;
2750
2751 htlcs = tal_arr(ctx, struct existing_htlc *, 0);
2752
2753 for (hin = htlc_in_map_first(ld->htlcs_in, &ini);
2754 hin;
2755 hin = htlc_in_map_next(ld->htlcs_in, &ini)) {
2756 struct failed_htlc *f;
2757 struct existing_htlc *existing;
2758
2759 if (hin->key.channel != channel)
2760 continue;
2761
2762 if (hin->badonion)
2763 f = take(mk_failed_htlc_badonion(NULL, hin, hin->badonion));
2764 else if (hin->failonion)
2765 f = take(mk_failed_htlc(NULL, hin, hin->failonion));
2766 else
2767 f = NULL;
2768
2769
2770 existing = new_existing_htlc(htlcs, hin->key.id, hin->hstate,
2771 hin->msat, &hin->payment_hash,
2772 hin->cltv_expiry,
2773 hin->onion_routing_packet,
2774 hin->path_key,
2775 hin->preimage,
2776 f,
2777 hin->extra_tlvs);
2778 tal_arr_expand(&htlcs, existing);
2779 }
2780
2781 for (hout = htlc_out_map_first(ld->htlcs_out, &outi);
2782 hout;
2783 hout = htlc_out_map_next(ld->htlcs_out, &outi)) {
2784 struct failed_htlc *f;
2785 struct existing_htlc *existing;
2786
2787 if (hout->key.channel != channel)
2788 continue;
2789
2790 /* Note that channeld doesn't actually care *why* outgoing
2791 * HTLCs failed, so just use a dummy here. */
2792 if (hout->failonion || hout->failmsg) {
2793 f = take(tal(NULL, struct failed_htlc));
2794 f->id = hout->key.id;
2795 f->sha256_of_onion = tal(f, struct sha256);
2796 memset(f->sha256_of_onion, 0,
2797 sizeof(*f->sha256_of_onion));
2798 f->badonion = BADONION;

Callers 1

peer_start_channeldFunction · 0.85

Calls 3

mk_failed_htlc_badonionFunction · 0.85
mk_failed_htlcFunction · 0.85
new_existing_htlcFunction · 0.85

Tested by

no test coverage detected