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

Function gather_htlcs

channeld/full_channel.c:175–222  ·  view source on GitHub ↗

Returns up to three arrays: * committed: HTLCs currently committed. * pending_removal: HTLCs pending removal (subset of committed) * pending_addition: HTLCs pending addition (no overlap with committed) * * Also returns number of HTLCs for other side. */

Source from the content-addressed store, hash-verified

173 * Also returns number of HTLCs for other side.
174 */
175static size_t gather_htlcs(const tal_t *ctx,
176 const struct channel *channel,
177 enum side side,
178 const struct htlc ***committed,
179 const struct htlc ***pending_removal,
180 const struct htlc ***pending_addition)
181{
182 struct htlc_map_iter it;
183 const struct htlc *htlc;
184 const int committed_flag = HTLC_FLAG(side, HTLC_F_COMMITTED);
185 const int pending_flag = HTLC_FLAG(side, HTLC_F_PENDING);
186 size_t num_other_side = 0;
187
188 *committed = tal_arr(ctx, const struct htlc *, 0);
189 if (pending_removal)
190 *pending_removal = tal_arr(ctx, const struct htlc *, 0);
191 if (pending_addition)
192 *pending_addition = tal_arr(ctx, const struct htlc *, 0);
193
194 if (!channel->htlcs)
195 return num_other_side;
196
197 for (htlc = htlc_map_first(channel->htlcs, &it);
198 htlc;
199 htlc = htlc_map_next(channel->htlcs, &it)) {
200 if (htlc_has(htlc, committed_flag)) {
201#ifdef SUPERVERBOSE
202 dump_htlc(htlc, "COMMITTED");
203#endif
204 htlc_arr_append(committed, htlc);
205 if (htlc_has(htlc, pending_flag)) {
206#ifdef SUPERVERBOSE
207 dump_htlc(htlc, "REMOVING");
208#endif
209 htlc_arr_append(pending_removal, htlc);
210 } else if (htlc_owner(htlc) != side)
211 num_other_side++;
212 } else if (htlc_has(htlc, pending_flag)) {
213 htlc_arr_append(pending_addition, htlc);
214#ifdef SUPERVERBOSE
215 dump_htlc(htlc, "ADDING");
216#endif
217 if (htlc_owner(htlc) != side)
218 num_other_side++;
219 }
220 }
221 return num_other_side;
222}
223
224static bool sum_offered_msatoshis(struct amount_msat *total,
225 const struct htlc **htlcs,

Callers 5

channel_txsFunction · 0.85
add_htlcFunction · 0.85
approx_max_feerateFunction · 0.85
htlc_calculate_dustFunction · 0.85

Calls 4

htlc_hasFunction · 0.85
dump_htlcFunction · 0.85
htlc_arr_appendFunction · 0.85
htlc_ownerFunction · 0.85

Tested by

no test coverage detected