From 7b4e70effa183f5f63d8f2852a21b7825f2e2c21 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 19 Jul 2020 21:39:53 +0200 Subject: [PATCH] paymod: Consolidate step selection and changes in presplit modifier We skip most payment steps and all sub-payments, so consolidate the skip conditions in one if-statement. We also not use `payment_set_step` to skip any modifiers after us after the step change. --- plugins/libplugin-pay.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index ebb013198..b97ad6d9e 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -2192,10 +2192,7 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) struct payment *root = payment_root(p); struct amount_msat amt = root->amount; - if (d->disable) - return payment_continue(p); - - if (!payment_supports_mpp(p)) + if (d->disable || p->parent != NULL || !payment_supports_mpp(p)) return payment_continue(p); if (p->step == PAYMENT_STEP_ONION_PAYLOAD) { @@ -2210,7 +2207,7 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) fields, root->payment_secret, root->amount.millisatoshis); /* Raw: onion payload */ } - } else if (p == root && p->step == PAYMENT_STEP_INITIALIZED) { + } else if (p->step == PAYMENT_STEP_INITIALIZED) { /* The presplitter only acts on the root and only in the first * step. */ size_t count = 0; @@ -2261,8 +2258,9 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) payment_start(c); count++; } - p->step = PAYMENT_STEP_SPLIT; - p->end_time = time_now(); + + p->result = NULL; + p->route = NULL; p->why = tal_fmt( p, "Split into %zu sub-payments due to initial size (%s > " @@ -2270,9 +2268,8 @@ static void presplit_cb(struct presplit_mod_data *d, struct payment *p) count, type_to_string(tmpctx, struct amount_msat, &root->amount), MPP_TARGET_SIZE); + payment_set_step(p, PAYMENT_STEP_SPLIT); plugin_log(p->plugin, LOG_INFORM, "%s", p->why); - p->result = NULL; - p->route = NULL; } payment_continue(p); }