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

Function direct_pay_override

plugins/libplugin-pay.c:3195–3240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3193 shadow_route_init, shadow_route_cb);
3194
3195static void direct_pay_override(struct payment *p) {
3196
3197 /* The root has performed the search for a direct channel. */
3198 struct payment *root = payment_root(p);
3199 struct direct_pay_data *d;
3200 struct channel_hint *hint = NULL;
3201
3202 /* If we were unable to find a direct channel we don't need to do
3203 * anything. */
3204 d = payment_mod_directpay_get_data(root);
3205
3206 if (d->chan == NULL)
3207 return payment_continue(p);
3208
3209 /* If we have a channel we need to make sure that it still has
3210 * sufficient capacity. Look it up in the channel_hints. */
3211 for (size_t i=0; i<tal_count(root->channel_hints); i++) {
3212 struct short_channel_id_dir *cur = &root->channel_hints[i].scid;
3213 if (short_channel_id_eq(&cur->scid, &d->chan->scid) &&
3214 cur->dir == d->chan->dir) {
3215 hint = &root->channel_hints[i];
3216 break;
3217 }
3218 }
3219
3220 if (hint && hint->enabled &&
3221 amount_msat_greater(hint->estimated_capacity, p->amount)) {
3222 /* Now build a route that consists only of this single hop */
3223 p->route = tal_arr(p, struct route_hop, 1);
3224 p->route[0].amount = p->amount;
3225 p->route[0].delay = p->getroute->cltv;
3226 p->route[0].scid = hint->scid.scid;
3227 p->route[0].direction = hint->scid.dir;
3228 p->route[0].node_id = *p->destination;
3229 paymod_log(p, LOG_DBG,
3230 "Found a direct channel (%s) with sufficient "
3231 "capacity, skipping route computation.",
3232 type_to_string(tmpctx, struct short_channel_id_dir,
3233 &hint->scid));
3234
3235 payment_set_step(p, PAYMENT_STEP_GOT_ROUTE);
3236 }
3237
3238
3239 payment_continue(p);
3240}
3241
3242/* Now that we have the listpeers result for the root payment, let's search
3243 * for a direct channel that is a) connected and b) in state normal. We will

Callers 1

direct_pay_listpeersFunction · 0.85

Calls 6

payment_rootFunction · 0.85
payment_continueFunction · 0.85
amount_msat_greaterFunction · 0.85
paymod_logFunction · 0.85
payment_set_stepFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected