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.
This commit is contained in:
Christian Decker
2020-05-28 12:25:58 +02:00
parent 2acb86bfe3
commit 9aff885828
2 changed files with 16 additions and 0 deletions

View File

@@ -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;
}