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

Function adaptive_splitter_cb

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

Source from the content-addressed store, hash-verified

3684}
3685
3686static struct command_result *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. */
3701 int children = tal_count(p->children);
3702 d->htlc_budget = payment_max_htlcs(p);
3703 if (children > d->htlc_budget) {
3704 p->abort = true;
3705 return payment_fail(
3706 p,
3707 "Cannot add %d HTLCs to our channels, we "
3708 "only have %d HTLCs available.",
3709 children, d->htlc_budget);
3710 }
3711 d->htlc_budget -= children;
3712 }
3713
3714 if (p->step == PAYMENT_STEP_ONION_PAYLOAD) {
3715 /* We need to tell the last hop the total we're going
3716 * to send. MPP disables amount fuzzing, so we should
3717 * always get the exact value through. */
3718 size_t lastidx = tal_count(p->createonion_request->hops) - 1;
3719 struct createonion_hop *hop = &p->createonion_request->hops[lastidx];
3720 struct tlv_field **fields = &hop->tlv_payload->fields;
3721 tlvstream_set_tlv_payload_data(
3722 fields, root->payment_secret,
3723 root->final_amount.millisatoshis); /* Raw: onion payload */
3724 } else if (p->step == PAYMENT_STEP_FAILED && !p->abort) {
3725 if (amount_msat_greater(p->our_amount, MPP_ADAPTIVE_LOWER_LIMIT)) {
3726 struct payment *a, *b;
3727 /* Random number in the range [90%, 110%] */
3728 double rand = pseudorand_double() * 0.2 + 0.9;
3729 u64 mid = p->our_amount.millisatoshis / 2 * rand; /* Raw: multiplication */
3730 bool ok;
3731 /* Use the start constraints, not the ones updated by routes and shadow-routes. */
3732 struct payment_constraints *pconstraints = p->start_constraints;
3733
3734 /* First check that splitting doesn't exceed our HTLC budget */
3735 if (root_data->htlc_budget == 0) {
3736 root->abort = true;
3737 return payment_fail(
3738 p,
3739 "Cannot split payment any further without "
3740 "exceeding the maximum number of HTLCs "
3741 "allowed by our channels");
3742 }
3743

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