From 24e9a164f92e400423c3e59f9b64e16a7e3406fd Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 19 Jul 2020 21:32:52 +0200 Subject: [PATCH] paymod: Add invariant verification for constraints on shadowroute This was highlighted in #3851, so I added an assertion. After the rewrite in the next commit we would simply skip if any of the constraints were not maintained, but this serves as the canary in the coalmine, so we don't paper over. --- plugins/libplugin-pay.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index ddc838915..55769bda5 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -1784,6 +1784,11 @@ static struct command_result *shadow_route_listchannels(struct command *cmd, const jsmntok_t *sattok, *delaytok, *basefeetok, *propfeetok, *desttok, *channelstok, *chan; + /* Check the invariants on the constraints between payment and modifier. */ + assert(d->constraints.cltv_budget <= p->constraints.cltv_budget / 4); + assert(amount_msat_greater_eq(p->constraints.fee_budget, + d->constraints.fee_budget)); + channelstok = json_get_member(buf, result, "channels"); json_for_each_arr(i, chan, channelstok) { u64 v = pseudorand(UINT64_MAX);