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

Function free_htlcs

lightningd/peer_htlcs.c:2917–2948  ·  view source on GitHub ↗

If channel is NULL, free them all (for shutdown) */

Source from the content-addressed store, hash-verified

2915
2916/* If channel is NULL, free them all (for shutdown) */
2917void free_htlcs(struct lightningd *ld, const struct channel *channel)
2918{
2919 struct htlc_out_map_iter outi;
2920 struct htlc_out *hout;
2921 struct htlc_in_map_iter ini;
2922 struct htlc_in *hin;
2923 bool deleted;
2924
2925 /* FIXME: Implement check_htlcs to ensure no dangling hout->in ptrs! */
2926
2927 do {
2928 deleted = false;
2929 for (hout = htlc_out_map_first(ld->htlcs_out, &outi);
2930 hout;
2931 hout = htlc_out_map_next(ld->htlcs_out, &outi)) {
2932 if (channel && hout->key.channel != channel)
2933 continue;
2934 tal_free(hout);
2935 deleted = true;
2936 }
2937
2938 for (hin = htlc_in_map_first(ld->htlcs_in, &ini);
2939 hin;
2940 hin = htlc_in_map_next(ld->htlcs_in, &ini)) {
2941 if (channel && hin->key.channel != channel)
2942 continue;
2943 tal_free(hin);
2944 deleted = true;
2945 }
2946 /* Can skip over elements due to iterating while deleting. */
2947 } while (deleted);
2948}
2949
2950/* BOLT #2:
2951 *

Callers 3

drop_to_chainFunction · 0.70
free_all_channelsFunction · 0.70

Calls 1

tal_freeFunction · 0.85

Tested by

no test coverage detected