From e108ebe559fe2f80287100f67578dcae9941f33d Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 8 May 2020 14:42:29 +0200 Subject: [PATCH] paymod: Add base state-machine for payment flow --- plugins/libplugin-pay.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index 7dcf7a38d..21238fab8 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -28,6 +28,37 @@ struct payment_result { struct channel_status { }; +/* Each payment goes through a number of steps that are always processed in + * the same order, and some modifiers are called with the payment, and the + * modifier's data before and after certain steps, allowing customization. The + * following enum represents the normal workflow of processing a payment, and + * is used by `payment_continue` to re-enter the state machine from a + * modifier. The values are powers of two in order to make aggregating of + * subtree states in the root easy. + */ +enum payment_step { + PAYMENT_STEP_INITIALIZED = 1, + + /* We just called getroute and got a resulting route, allow modifiers + * to amend the route. */ + PAYMENT_STEP_GOT_ROUTE = 2, + + /* We just computed the onion payload, allow modifiers to amend, + * before constructing the onion packet. */ + PAYMENT_STEP_ONION_PAYLOAD = 4, + + /* The following states mean that the current payment failed, but a + * child payment is still running, and we can't say yet whether the + * overall payment will fail or succeed. */ + PAYMENT_STEP_SPLIT = 8, + PAYMENT_STEP_RETRY = 16, + + /* The payment state-machine has terminated, these are the final + * states that a payment can be in. */ + PAYMENT_STEP_FAILED = 32, + PAYMENT_STEP_SUCCESS = 64, +}; + struct payment { /* Real destination we want to route to */