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

Function waitblockheight_cb

plugins/libplugin-pay.c:3356–3401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3354}
3355
3356static void waitblockheight_cb(void *d, struct payment *p)
3357{
3358 struct out_req *req;
3359 struct timeabs now = time_now();
3360 struct timerel remaining;
3361 u32 blockheight;
3362 if (p->step != PAYMENT_STEP_FAILED)
3363 return payment_continue(p);
3364
3365 /* If we don't have an error message to parse we can't wait for blockheight. */
3366 if (p->result == NULL)
3367 return payment_continue(p);
3368
3369 /* Check if we'd be waiting more than 0 seconds. If we have
3370 * less than a second then waitblockheight would return
3371 * immediately resulting in a loop. */
3372 if (time_after(now, p->deadline))
3373 return payment_continue(p);
3374
3375 remaining = time_between(p->deadline, now);
3376 if (time_to_sec(remaining) < 1)
3377 return payment_continue(p);
3378
3379 /* *Was* it a blockheight disagreement that caused the failure? */
3380 if (!failure_is_blockheight_disagreement(p, &blockheight))
3381 return payment_continue(p);
3382
3383 paymod_log(p, LOG_INFORM,
3384 "Remote node appears to be on a longer chain, which causes "
3385 "CLTV timeouts to be incorrect. Waiting up to %" PRIu64
3386 " seconds to catch up to block %d before retrying.",
3387 time_to_sec(remaining), blockheight);
3388
3389 /* Set temporarily set the state of the payment to not failed, so
3390 * interim status queries don't show this as terminally failed. We're
3391 * in control for this payment so nobody else could be fooled by
3392 * this. The callback will set it to retry anyway. */
3393 payment_set_step(p, PAYMENT_STEP_RETRY);
3394
3395 req = jsonrpc_request_start(p->plugin, NULL, "waitblockheight",
3396 waitblockheight_rpc_cb,
3397 waitblockheight_rpc_cb, p);
3398 json_add_u32(req->js, "blockheight", blockheight);
3399 json_add_u32(req->js, "timeout", time_to_sec(remaining));
3400 send_outreq(p->plugin, req);
3401}
3402
3403REGISTER_PAYMENT_MODIFIER(waitblockheight, void *, NULL, waitblockheight_cb);
3404

Callers

nothing calls this directly

Calls 10

time_nowFunction · 0.85
payment_continueFunction · 0.85
time_afterFunction · 0.85
time_betweenFunction · 0.85
time_to_secFunction · 0.85
paymod_logFunction · 0.85
payment_set_stepFunction · 0.85
send_outreqFunction · 0.70
json_add_u32Function · 0.50

Tested by

no test coverage detected