2023-07-31 11:21:22 +09:30
|
|
|
#ifndef LIGHTNING_PLUGINS_RENEPAY_PAYMENT_H
|
|
|
|
#define LIGHTNING_PLUGINS_RENEPAY_PAYMENT_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <common/gossmap.h>
|
|
|
|
#include <plugins/libplugin.h>
|
2024-05-04 10:36:45 +01:00
|
|
|
#include <plugins/renepay/disabledmap.h>
|
2024-05-04 10:48:13 +01:00
|
|
|
#include <plugins/renepay/payment_info.h>
|
2024-01-25 07:13:43 +01:00
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
enum payment_status { PAYMENT_PENDING, PAYMENT_SUCCESS, PAYMENT_FAIL };
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
#define INVALID_STATE UINT64_MAX
|
2023-07-31 11:21:22 +09:30
|
|
|
|
|
|
|
struct payment {
|
2023-08-10 09:30:45 +09:30
|
|
|
/* Inside pay_plugin->payments list */
|
2024-04-08 14:56:46 +01:00
|
|
|
// TODO: probably not necessary after we store all payments in a
|
|
|
|
// hashtable instead of a list
|
2023-08-10 09:30:45 +09:30
|
|
|
struct list_node list;
|
2024-05-06 10:13:45 +01:00
|
|
|
|
2024-05-04 10:48:13 +01:00
|
|
|
struct payment_info payment_info;
|
2023-08-10 09:30:45 +09:30
|
|
|
|
2024-05-06 10:13:45 +01:00
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* === Public State === */
|
|
|
|
/* TODO: these properties should be private and only changed through
|
|
|
|
* payment_ methods. */
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* Overall, how are we going? */
|
|
|
|
enum payment_status status;
|
|
|
|
|
|
|
|
/* Payment preimage, in case of success. */
|
|
|
|
struct preimage *preimage;
|
|
|
|
|
|
|
|
/* Final error code and message, in case of failure. */
|
|
|
|
enum jsonrpc_errcode error_code;
|
|
|
|
const char *error_msg;
|
|
|
|
|
|
|
|
/* Total sent, including fees. */
|
|
|
|
struct amount_msat total_sent;
|
|
|
|
|
|
|
|
/* Total that is delivering (i.e. without fees) */
|
|
|
|
struct amount_msat total_delivering;
|
|
|
|
|
|
|
|
/* Chatty description of attempts. */
|
|
|
|
const char **paynotes;
|
2023-07-31 11:21:22 +09:30
|
|
|
|
|
|
|
/* Groupid, so listpays() can group them back together */
|
|
|
|
u64 groupid;
|
|
|
|
|
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* === Hidden State === */
|
|
|
|
/* Position in the payment virtual machine */
|
|
|
|
u64 exec_state;
|
|
|
|
|
|
|
|
/* Used in get_payflows to set ids to each pay_flow. */
|
|
|
|
u64 next_partid;
|
|
|
|
|
|
|
|
/* Running commands that want this payment */
|
|
|
|
struct command **cmd_array;
|
|
|
|
|
|
|
|
/* Localmods to apply to gossip_map for our own use. */
|
|
|
|
struct gossmap_localmods *local_gossmods;
|
|
|
|
|
2024-05-04 10:36:45 +01:00
|
|
|
struct disabledmap *disabledmap;
|
2024-04-08 14:56:46 +01:00
|
|
|
|
|
|
|
/* Flag to indicate wether we have collected enough results to make a
|
|
|
|
* decision on the payment progress. */
|
|
|
|
bool have_results;
|
|
|
|
|
|
|
|
/* Flag to indicate wether we would like to retry the payment. */
|
|
|
|
bool retry;
|
|
|
|
|
|
|
|
/* Timer we use to wait for results. */
|
|
|
|
struct plugin_timer *waitresult_timer;
|
|
|
|
|
|
|
|
struct route **routes_computed;
|
|
|
|
struct routetracker *routetracker;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct sha256 payment_hash(const struct payment *p)
|
|
|
|
{
|
2024-05-04 10:48:13 +01:00
|
|
|
return p->payment_info.payment_hash;
|
2024-04-08 14:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t payment_hash64(const struct sha256 h)
|
|
|
|
{
|
|
|
|
return ((u64)h.u.u32[1] << 32) ^ h.u.u32[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool payment_hash_eq(const struct payment *p,
|
|
|
|
const struct sha256 h)
|
|
|
|
{
|
2024-05-04 10:48:13 +01:00
|
|
|
return p->payment_info.payment_hash.u.u32[0] == h.u.u32[0] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[1] == h.u.u32[1] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[2] == h.u.u32[2] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[3] == h.u.u32[3] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[4] == h.u.u32[4] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[5] == h.u.u32[5] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[6] == h.u.u32[6] &&
|
|
|
|
p->payment_info.payment_hash.u.u32[7] == h.u.u32[7];
|
2024-04-08 14:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct payment, payment_hash, payment_hash64,
|
|
|
|
payment_hash_eq, payment_map);
|
|
|
|
|
|
|
|
struct payment *payment_new(
|
|
|
|
const tal_t *ctx,
|
|
|
|
const struct sha256 *payment_hash,
|
|
|
|
const char *invstr TAKES,
|
|
|
|
const char *label TAKES,
|
|
|
|
const char *description TAKES,
|
|
|
|
const struct secret *payment_secret TAKES,
|
|
|
|
const u8 *payment_metadata TAKES,
|
|
|
|
const struct route_info **routehints TAKES,
|
|
|
|
const struct node_id *destination,
|
|
|
|
struct amount_msat amount,
|
|
|
|
struct amount_msat maxfee,
|
|
|
|
unsigned int maxdelay,
|
|
|
|
u64 retryfor,
|
|
|
|
u16 final_cltv,
|
|
|
|
/* Tweakable in --developer mode */
|
|
|
|
u64 base_fee_penalty_millionths,
|
|
|
|
u64 prob_cost_factor_millionths,
|
|
|
|
u64 riskfactor_millionths,
|
|
|
|
u64 min_prob_success_millionths,
|
|
|
|
bool use_shadow);
|
|
|
|
|
|
|
|
bool payment_update(
|
|
|
|
struct payment *p,
|
|
|
|
struct amount_msat maxfee,
|
|
|
|
unsigned int maxdelay,
|
|
|
|
u64 retryfor,
|
|
|
|
u16 final_cltv,
|
|
|
|
/* Tweakable in --developer mode */
|
|
|
|
u64 base_fee_penalty_millionths,
|
|
|
|
u64 prob_cost_factor_millionths,
|
|
|
|
u64 riskfactor_millionths,
|
|
|
|
u64 min_prob_success_millionths,
|
|
|
|
bool use_shadow);
|
2023-08-10 09:30:43 +09:30
|
|
|
|
2023-07-31 11:21:25 +09:30
|
|
|
struct amount_msat payment_sent(const struct payment *p);
|
|
|
|
struct amount_msat payment_delivered(const struct payment *p);
|
|
|
|
struct amount_msat payment_amount(const struct payment *p);
|
|
|
|
struct amount_msat payment_fees(const struct payment *p);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2023-08-10 11:29:44 +09:30
|
|
|
u64 payment_parts(const struct payment *payment);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* attach a command to this payment */
|
|
|
|
bool payment_register_command(struct payment *p, struct command *cmd);
|
|
|
|
/* are there pending commands on this payment? */
|
|
|
|
bool payment_commands_empty(const struct payment *p);
|
|
|
|
struct command *payment_command(struct payment *p);
|
2023-08-21 15:09:05 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* get me the result of this payment, not necessarily a completed payment */
|
|
|
|
struct json_stream *payment_result(struct payment *p, struct command *cmd);
|
2023-08-21 15:09:05 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* flag the payment as success and write the preimage as proof */
|
|
|
|
struct command_result *payment_success(struct payment *payment,
|
|
|
|
const struct preimage *preimage TAKES);
|
2024-01-25 07:13:43 +01:00
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
/* flag the payment as failed and write the reason */
|
|
|
|
struct command_result *payment_fail(struct payment *payment,
|
|
|
|
enum jsonrpc_errcode code, const char *fmt,
|
|
|
|
...);
|
|
|
|
|
|
|
|
/* These log at LOG_DBG, append to notes, and send command notification */
|
|
|
|
void payment_note(struct payment *p, enum log_level lvl, const char *fmt, ...);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 14:56:46 +01:00
|
|
|
void payment_disable_chan(struct payment *p, struct short_channel_id scid,
|
|
|
|
enum log_level lvl, const char *fmt, ...);
|
2023-11-27 14:56:07 +01:00
|
|
|
|
2024-04-25 08:41:32 +01:00
|
|
|
void payment_warn_chan(struct payment *p, struct short_channel_id scid,
|
|
|
|
enum log_level lvl, const char *fmt, ...);
|
|
|
|
|
|
|
|
void payment_disable_node(struct payment *p, struct node_id node,
|
|
|
|
enum log_level lvl, const char *fmt, ...);
|
|
|
|
|
2023-07-31 11:21:22 +09:30
|
|
|
#endif /* LIGHTNING_PLUGINS_RENEPAY_PAYMENT_H */
|