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

Function payment_collect_result

plugins/libplugin-pay.c:229–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229struct payment_tree_result payment_collect_result(struct payment *p)
230{
231 struct payment_tree_result res;
232 size_t numchildren = tal_count(p->children);
233 res.sent = AMOUNT_MSAT(0);
234 res.attempts = 1;
235 res.treestates = p->step;
236 res.leafstates = 0;
237 res.preimage = NULL;
238 res.failure = NULL;
239 if (p->step == PAYMENT_STEP_FAILED && p->result != NULL)
240 res.failure = p->result;
241
242 if (numchildren == 0) {
243 res.leafstates |= p->step;
244 if (p->result && p->result->state == PAYMENT_COMPLETE) {
245 res.sent = p->result->amount_sent;
246 res.preimage = p->result->payment_preimage;
247 }
248 }
249
250 for (size_t i = 0; i < numchildren; i++) {
251 struct payment_tree_result cres =
252 payment_collect_result(p->children[i]);
253
254 /* Some of our subpayments have succeeded, aggregate how much
255 * we sent in total. */
256 if (!amount_msat_accumulate(&res.sent, cres.sent))
257 paymod_err(
258 p,
259 "Number overflow summing partial payments: %s + %s",
260 fmt_amount_msat(tmpctx, res.sent),
261 fmt_amount_msat(tmpctx, cres.sent));
262
263 /* Bubble up the first preimage we see. */
264 if (res.preimage == NULL && cres.preimage != NULL)
265 res.preimage = cres.preimage;
266
267 res.leafstates |= cres.leafstates;
268 res.treestates |= cres.treestates;
269 res.attempts += cres.attempts;
270
271 /* We bubble the failure result with the highest failcode up
272 * to the root. */
273 if (res.failure == NULL ||
274 (cres.failure != NULL &&
275 cres.failure->failcode > res.failure->failcode)) {
276 res.failure = cres.failure;
277 }
278 }
279 return res;
280}
281
282static struct command_result *payment_waitblockheight_cb(struct command *cmd,
283 const char *method,

Callers 3

on_payment_successFunction · 0.85
on_payment_failureFunction · 0.85
payment_finishedFunction · 0.85

Calls 3

amount_msat_accumulateFunction · 0.85
paymod_errFunction · 0.85
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected