| 270 | #define INVALID_BLOCKHEIGHT UINT32_MAX |
| 271 | |
| 272 | static |
| 273 | void payment_start_at_blockheight(struct payment *p, u32 blockheight) |
| 274 | { |
| 275 | struct payment *root = payment_root(p); |
| 276 | |
| 277 | /* Should have been set in root payment, or propagated from root |
| 278 | * payment to all child payments. */ |
| 279 | assert(p->local_id); |
| 280 | |
| 281 | p->step = PAYMENT_STEP_INITIALIZED; |
| 282 | p->current_modifier = -1; |
| 283 | |
| 284 | /* Pre-generate the getroute request, so modifiers can have their say, |
| 285 | * before we actually call `getroute` */ |
| 286 | p->getroute->destination = p->destination; |
| 287 | p->getroute->max_hops = ROUTING_MAX_HOPS; |
| 288 | p->getroute->cltv = root->min_final_cltv_expiry; |
| 289 | p->getroute->amount = p->amount; |
| 290 | |
| 291 | p->start_constraints = tal_dup(p, struct payment_constraints, &p->constraints); |
| 292 | |
| 293 | if (blockheight != INVALID_BLOCKHEIGHT) { |
| 294 | /* The caller knows the actual blockheight. */ |
| 295 | p->start_block = blockheight; |
| 296 | return payment_continue(p); |
| 297 | } |
| 298 | if (p->parent) { |
| 299 | /* The parent should have a start block. */ |
| 300 | p->start_block = p->parent->start_block; |
| 301 | return payment_continue(p); |
| 302 | } |
| 303 | |
| 304 | /* `waitblockheight 0` can be used as a query for the current |
| 305 | * block height. |
| 306 | * This is slightly better than `getinfo` since `getinfo` |
| 307 | * counts the channels and addresses and pushes more data |
| 308 | * onto the RPC but all we care about is the blockheight. |
| 309 | */ |
| 310 | struct out_req *req; |
| 311 | req = jsonrpc_request_start(p->plugin, NULL, "waitblockheight", |
| 312 | &payment_getblockheight_success, |
| 313 | &payment_rpc_failure, p); |
| 314 | json_add_u32(req->js, "blockheight", 0); |
| 315 | send_outreq(p->plugin, req); |
| 316 | } |
| 317 | void payment_start(struct payment *p) |
| 318 | { |
| 319 | payment_start_at_blockheight(p, INVALID_BLOCKHEIGHT); |
no test coverage detected