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

Function on_payment_failure

plugins/pay.c:343–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343static void on_payment_failure(struct payment *payment)
344{
345 struct payment *p, *nxt;
346 struct payment_tree_result result = payment_collect_result(payment);
347 list_for_each_safe(&payments, p, nxt, list)
348 {
349 struct json_stream *ret;
350 struct command *cmd;
351 const char *msg;
352 /* The result for the active payment is returned in
353 * `payment_finished`. */
354 if (payment == p)
355 continue;
356
357 /* When we suspended we've set the groupid to match so
358 * we'd know which calls were duplicates. */
359 if (!sha256_eq(payment->payment_hash, p->payment_hash) ||
360 payment->groupid != p->groupid)
361 continue;
362 if (p->finished)
363 continue;
364
365 cmd = p->cmd;
366 p->cmd = aux_command(cmd);
367 p->finished = true;
368 if (p->aborterror != NULL) {
369 /* We set an explicit toplevel error message,
370 * so let's report that. */
371 ret = jsonrpc_stream_fail(cmd, PAY_STOPPED_RETRYING,
372 p->aborterror);
373 payment_json_add_attempts(ret, "attempts", p);
374
375 if (command_finished(cmd, ret)) {/* Ignore result. */}
376 } else if (result.failure == NULL || result.failure->failcode < NODE) {
377 /* This is failing because we have no more routes to try */
378 msg = tal_fmt(cmd,
379 "Ran out of routes to try after "
380 "%d attempt%s: see `paystatus`",
381 result.attempts,
382 result.attempts == 1 ? "" : "s");
383 ret = jsonrpc_stream_fail(cmd, PAY_STOPPED_RETRYING,
384 msg);
385 payment_json_add_attempts(ret, "attempts", p);
386
387 if (command_finished(cmd, ret)) {/* Ignore result. */}
388
389 } else {
390 struct payment_result *failure = result.failure;
391 assert(failure!= NULL);
392
393 ret = jsonrpc_stream_fail(cmd, failure->code,
394 failure->message);
395
396 json_add_u64(ret, "id", failure->id);
397
398 json_add_u32(ret, "failcode", failure->failcode);
399 json_add_string(ret, "failcodename",
400 failure->failcodename);

Callers

nothing calls this directly

Calls 15

payment_collect_resultFunction · 0.85
json_add_u64Function · 0.85
json_add_u32Function · 0.85
json_add_invstringFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_add_numFunction · 0.85
json_add_node_idFunction · 0.85
json_add_sha256Function · 0.85
json_add_amount_msatFunction · 0.85
aux_commandFunction · 0.70
jsonrpc_stream_failFunction · 0.70

Tested by

no test coverage detected