From 157e70ffe820098f5064f6b412364ba9205887bc Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 19 Jul 2020 21:31:41 +0200 Subject: [PATCH] paymod: Add a comment about how we derive errors from erring_index Mainly to help my future self remember --- plugins/libplugin-pay.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index a13dcacac..ddc838915 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -684,6 +684,22 @@ payment_waitsendpay_finished(struct command *cmd, const char *buffer, root = payment_root(p); payment_chanhints_apply_route(p, true); + /* Either we have no erring_index, or it must be a correct index into + * p->route. From the docs: + * + * - *erring_index*: The index of the node along the route that + * reported the error. 0 for the local node, 1 for the first hop, + * and so on. + * + * The only difficulty is mapping the erring_index to the correct hop, + * since the hop consists of the processing node, but the payload for + * the next hop. In addition there is a class of onion-related errors + * that are reported by the previous hop to the one erring, since the + * erring node couldn't read the onion in the first place. + */ + assert(p->result->erring_index == NULL || + *p->result->erring_index - 1 < tal_count(p->route)); + switch (p->result->failcode) { case WIRE_PERMANENT_CHANNEL_FAILURE: case WIRE_CHANNEL_DISABLED: