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

Function adaptive_splitter_cb

plugins/libplugin-pay.c:3670–3780  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3668}
3669
3670static struct command_result *adaptive_splitter_cb(struct adaptive_split_mod_data *d, struct payment *p)
3671{
3672 struct payment *root = payment_root(p);
3673 struct adaptive_split_mod_data *root_data =
3674 payment_mod_adaptive_splitter_get_data(root);
3675 if (d->disable)
3676 return payment_continue(p);
3677
3678 if (!payment_supports_mpp(p) || root->abort)
3679 return payment_continue(p);
3680
3681 if (p->parent == NULL && d->htlc_budget == 0) {
3682 /* Now that we potentially had an early splitter run, let's
3683 * update our htlc_budget that we own exclusively from now
3684 * on. */
3685 int children = tal_count(p->children);
3686 d->htlc_budget = payment_max_htlcs(p);
3687 if (children > d->htlc_budget) {
3688 p->abort = true;
3689 return payment_fail(
3690 p,
3691 "Cannot add %d HTLCs to our channels, we "
3692 "only have %d HTLCs available.",
3693 children, d->htlc_budget);
3694 }
3695 d->htlc_budget -= children;
3696 }
3697
3698 if (p->step == PAYMENT_STEP_ONION_PAYLOAD) {
3699 /* We need to tell the last hop the total we're going
3700 * to send. MPP disables amount fuzzing, so we should
3701 * always get the exact value through. */
3702 size_t lastidx = tal_count(p->createonion_request->hops) - 1;
3703 struct createonion_hop *hop = &p->createonion_request->hops[lastidx];
3704 struct tlv_field **fields = &hop->tlv_payload->fields;
3705 tlvstream_set_tlv_payload_data(
3706 fields, root->payment_secret,
3707 root->final_amount.millisatoshis); /* Raw: onion payload */
3708 } else if (p->step == PAYMENT_STEP_FAILED && !p->abort) {
3709 if (amount_msat_greater(p->our_amount, MPP_ADAPTIVE_LOWER_LIMIT)) {
3710 struct payment *a, *b;
3711 /* Random number in the range [90%, 110%] */
3712 double rand = pseudorand_double() * 0.2 + 0.9;
3713 u64 mid = p->our_amount.millisatoshis / 2 * rand; /* Raw: multiplication */
3714 bool ok;
3715 /* Use the start constraints, not the ones updated by routes and shadow-routes. */
3716 struct payment_constraints *pconstraints = p->start_constraints;
3717
3718 /* First check that splitting doesn't exceed our HTLC budget */
3719 if (root_data->htlc_budget == 0) {
3720 root->abort = true;
3721 return payment_fail(
3722 p,
3723 "Cannot split payment any further without "
3724 "exceeding the maximum number of HTLCs "
3725 "allowed by our channels");
3726 }
3727

Callers

nothing calls this directly

Calls 15

payment_rootFunction · 0.85
payment_supports_mppFunction · 0.85
payment_max_htlcsFunction · 0.85
amount_msat_greaterFunction · 0.85
amount_msat_ratioFunction · 0.85
amount_msat_scaleFunction · 0.85
abortFunction · 0.85
amount_msat_subFunction · 0.85
paymod_logFunction · 0.85
payment_continueFunction · 0.70
payment_failFunction · 0.70

Tested by

no test coverage detected