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

Function adaptive_splitter_cb

plugins/libplugin-pay.c:3686–3800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

payment_rootFunction · 0.85
payment_continueFunction · 0.85
payment_supports_mppFunction · 0.85
payment_max_htlcsFunction · 0.85
payment_failFunction · 0.85
amount_msat_greaterFunction · 0.85
pseudorand_doubleFunction · 0.85
payment_newFunction · 0.85
amount_msat_ratioFunction · 0.85
amount_msat_scaleFunction · 0.85
abortFunction · 0.85

Tested by

no test coverage detected