renepay: payment state machine (mods)

Add a new implementation of the payment state machine.
This is based in the `pay` plugin concept of payment modifiers,
but here we take it to the next level.
The payment goes through a virtual machine that includes calling
functions and evaluating conditions.
This commit is contained in:
Lagrang3 2024-04-08 15:13:02 +01:00 committed by Rusty Russell
parent 4b9fe23293
commit 6766acbcdf
2 changed files with 1084 additions and 0 deletions

1048
plugins/renepay/mods.c Normal file

File diff suppressed because it is too large Load Diff

36
plugins/renepay/mods.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef LIGHTNING_PLUGINS_RENEPAY_MODS_H
#define LIGHTNING_PLUGINS_RENEPAY_MODS_H
#include "config.h"
struct payment;
struct command_result;
struct payment_modifier {
const char *name;
struct command_result *(*step_cb)(struct payment *p);
};
struct payment_condition {
const char *name;
bool (*condition_cb)(const struct payment *p);
};
struct command_result *payment_continue(struct payment *p);
#define REGISTER_PAYMENT_MODIFIER(name, step_cb) \
struct payment_modifier name##_pay_mod = { \
stringify(name), \
typesafe_cb_cast(struct command_result * (*)(struct payment *), \
struct command_result * (*)(struct payment *), \
step_cb), \
};
#define REGISTER_PAYMENT_CONDITION(name, condition_cb) \
struct payment_condition name##_pay_cond = { \
stringify(name), \
typesafe_cb_cast(bool (*)(const struct payment *), \
bool (*)(const struct payment *), condition_cb), \
};
#endif /* LIGHTNING_PLUGINS_RENEPAY_MODS_H */