| 3528 | } |
| 3529 | |
| 3530 | static void presplit_cb(struct presplit_mod_data *d, struct payment *p) |
| 3531 | { |
| 3532 | struct payment *root = payment_root(p); |
| 3533 | |
| 3534 | if (d->disable || p->parent != NULL || !payment_supports_mpp(p)) |
| 3535 | return payment_continue(p); |
| 3536 | |
| 3537 | if (p->step == PAYMENT_STEP_ONION_PAYLOAD) { |
| 3538 | /* We need to tell the last hop the total we're going to |
| 3539 | * send. Presplit disables amount fuzzing, so we should always |
| 3540 | * get the exact value through. */ |
| 3541 | size_t lastidx = tal_count(p->createonion_request->hops) - 1; |
| 3542 | struct createonion_hop *hop = &p->createonion_request->hops[lastidx]; |
| 3543 | struct tlv_field **fields = &hop->tlv_payload->fields; |
| 3544 | tlvstream_set_tlv_payload_data( |
| 3545 | fields, root->payment_secret, |
| 3546 | root->amount.millisatoshis); /* Raw: onion payload */ |
| 3547 | } else if (p->step == PAYMENT_STEP_INITIALIZED) { |
| 3548 | /* The presplitter only acts on the root and only in the first |
| 3549 | * step. */ |
| 3550 | size_t count = 0; |
| 3551 | u32 htlcs; |
| 3552 | struct amount_msat target, amt = p->amount; |
| 3553 | char *partids = tal_strdup(tmpctx, ""); |
| 3554 | u64 target_amount = MPP_TARGET_SIZE; |
| 3555 | |
| 3556 | /* We aim for at most PRESPLIT_MAX_SPLITS parts, even for |
| 3557 | * large values. To achieve this we take the base amount and |
| 3558 | * multiply it by the number of targetted parts until the |
| 3559 | * total amount divided by part amount gives us at most that |
| 3560 | * number of parts. */ |
| 3561 | while (amount_msat_less(amount_msat(target_amount * PRESPLIT_MAX_SPLITS), |
| 3562 | p->amount)) |
| 3563 | target_amount *= PRESPLIT_MAX_SPLITS; |
| 3564 | |
| 3565 | /* We need to opt-in to the MPP sending facility no matter |
| 3566 | * what we do. That means setting all partids to a non-zero |
| 3567 | * value. */ |
| 3568 | root->partid++; |
| 3569 | |
| 3570 | /* Bump the next_partid as well so we don't have duplicate |
| 3571 | * partids. Not really necessary since the root payment whose |
| 3572 | * id could be reused will never reach the `sendonion` step, |
| 3573 | * but makes debugging a bit easier. */ |
| 3574 | root->next_partid++; |
| 3575 | |
| 3576 | htlcs = payment_max_htlcs(p); |
| 3577 | /* Divide it up if we can, but it might be v low already */ |
| 3578 | if (htlcs >= PRESPLIT_MAX_HTLC_SHARE) |
| 3579 | htlcs /= PRESPLIT_MAX_HTLC_SHARE; |
| 3580 | |
| 3581 | int targethtlcs = |
| 3582 | p->amount.millisatoshis / target_amount; /* Raw: division */ |
| 3583 | if (htlcs == 0) { |
| 3584 | p->abort = true; |
| 3585 | return payment_fail( |
| 3586 | p, "Cannot attempt payment, we have no channel to " |
| 3587 | "which we can add an HTLC"); |
nothing calls this directly
no test coverage detected