From 187d8a14f00ec073bf1eb7a0941d420772101378 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 6 Jul 2020 19:21:33 +0200 Subject: [PATCH] paymod: Allow callers to opt out of shadow routing amount fuzzing With MPP we require that the sum of parts is equal to the `total_msat` amount declared in the onion. Since that can't be changed once the first part arrives we need a way to disable amount fuzzing for MPP. --- plugins/libplugin-pay.c | 17 ++++++++++++----- plugins/libplugin-pay.h | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index c9b8ff92b..c9d6ca077 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -1700,10 +1700,13 @@ REGISTER_PAYMENT_MODIFIER(exemptfee, struct exemptfee_data *, static struct shadow_route_data *shadow_route_init(struct payment *p) { - if (p->parent != NULL) + if (p->parent != NULL) { return payment_mod_shadowroute_get_data(p->parent); - else - return tal(p, struct shadow_route_data); + } else { + struct shadow_route_data *d = tal(p, struct shadow_route_data); + d->fuzz_amount = true; + return d; + } } /* Mutual recursion */ @@ -1810,8 +1813,12 @@ static struct command_result *shadow_route_listchannels(struct command *cmd, /* And now the thing that caused all of this: adjust the call * to getroute. */ - ok &= amount_msat_add(&p->getroute->amount, p->getroute->amount, - best_fee); + if (d->fuzz_amount) { + /* Only fuzz the amount to route to the destination if + * we didn't opt-out earlier. */ + ok &= amount_msat_add(&p->getroute->amount, + p->getroute->amount, best_fee); + } p->getroute->cltv += best->cltv_expiry_delta; assert(ok); } diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index 25bcb83bc..fa7db3907 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -307,6 +307,11 @@ struct shadow_route_data { struct payment_constraints constraints; struct node_id destination; struct route_hop *route; + + /* multi-part payments require the sum of parts to be the exact + * amount, so we allow the payment flow to opt out of fuzzing the + * amount. */ + bool fuzz_amount; }; struct direct_pay_data {