From 9aff885828fa3433a35f64ef6efc467a29b93af2 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 28 May 2020 12:25:58 +0200 Subject: [PATCH] paymod Collect the final failure when aggregating the tree results We're lucky that we can distinguish the severity of the failure based on the failcode, so we bubble up the one with the maximum failcode, and let callers inspect details if they need more information. --- plugins/libplugin-pay.c | 11 +++++++++++ plugins/libplugin-pay.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 22154f133..42795f9e0 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -91,6 +91,9 @@ struct payment_tree_result payment_collect_result(struct payment *p) res.treestates = p->step; res.leafstates = 0; res.preimage = NULL; + res.failure = NULL; + if (p->step == PAYMENT_STEP_FAILED && p->result != NULL) + res.failure = p->result; if (numchildren == 0) { res.leafstates |= p->step; @@ -122,6 +125,14 @@ struct payment_tree_result payment_collect_result(struct payment *p) res.leafstates |= cres.leafstates; res.treestates |= cres.treestates; res.attempts += cres.attempts; + + /* We bubble the failure result with the highest failcode up + * to the root. */ + if (res.failure == NULL || + (cres.failure != NULL && + cres.failure->failcode > res.failure->failcode)) { + res.failure = cres.failure; + } } return res; } diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index aee08af4b..1520e7047 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -137,6 +137,11 @@ struct payment_tree_result { struct preimage *preimage; u32 attempts; + + /* Pointer to the failure that caused the payment to fail. We just + * take the one with the highest failcode, since that happen to match + * the severity of the error. */ + struct payment_result *failure; }; struct payment {