| 2253 | } |
| 2254 | |
| 2255 | static inline void retry_step_cb(struct retry_mod_data *rd, |
| 2256 | struct payment *p) |
| 2257 | { |
| 2258 | struct payment *subpayment, *root = payment_root(p); |
| 2259 | struct retry_mod_data *rdata = payment_mod_retry_get_data(p); |
| 2260 | struct timeabs now = time_now(); |
| 2261 | |
| 2262 | if (p->step != PAYMENT_STEP_FAILED) |
| 2263 | return payment_continue(p); |
| 2264 | |
| 2265 | if (time_after(now, p->deadline)) { |
| 2266 | paymod_log( |
| 2267 | p, LOG_INFORM, |
| 2268 | "Payment deadline expired, not retrying (partial-)payment " |
| 2269 | "%s/%d", |
| 2270 | type_to_string(tmpctx, struct sha256, p->payment_hash), |
| 2271 | p->partid); |
| 2272 | root->abort = true; |
| 2273 | return payment_continue(p); |
| 2274 | } |
| 2275 | |
| 2276 | /* If we failed to find a route, it's unlikely we can suddenly find a |
| 2277 | * new one without any other changes, so it's time to give up. */ |
| 2278 | if (p->route == NULL && !p->failroute_retry) |
| 2279 | return payment_continue(p); |
| 2280 | |
| 2281 | /* If the root is marked as abort, we do not retry anymore */ |
| 2282 | if (payment_root(p)->abort) |
| 2283 | return payment_continue(p); |
| 2284 | |
| 2285 | if (!payment_can_retry(p)) |
| 2286 | return payment_continue(p); |
| 2287 | |
| 2288 | /* If the failure was not final, and we tried a route, try again. */ |
| 2289 | if (rdata->retries > 0) { |
| 2290 | payment_set_step(p, PAYMENT_STEP_RETRY); |
| 2291 | subpayment = payment_new(p, NULL, p, p->modifiers); |
| 2292 | payment_start(subpayment); |
| 2293 | subpayment->why = |
| 2294 | tal_fmt(subpayment, "Still have %d attempts left", |
| 2295 | rdata->retries - 1); |
| 2296 | paymod_log( |
| 2297 | p, LOG_DBG, |
| 2298 | "Retrying %s/%d (%s), new partid %d. %d attempts left\n", |
| 2299 | type_to_string(tmpctx, struct sha256, p->payment_hash), |
| 2300 | p->partid, |
| 2301 | type_to_string(tmpctx, struct amount_msat, &p->amount), |
| 2302 | subpayment->partid, |
| 2303 | rdata->retries - 1); |
| 2304 | } |
| 2305 | |
| 2306 | payment_continue(p); |
| 2307 | } |
| 2308 | |
| 2309 | REGISTER_PAYMENT_MODIFIER(retry, struct retry_mod_data *, retry_data_init, |
| 2310 | retry_step_cb); |
nothing calls this directly
no test coverage detected