| 341 | } |
| 342 | |
| 343 | static 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); |
nothing calls this directly
no test coverage detected