core-lightning/plugins/renepay/routetracker.h
Lagrang3 a339e553e8 renepay: listsendpay before computing routes
It feels unsafe to rely on the internal state of the plugin's database
to tell how many pending sendpays there are for the current payment.
The safest way is to assume lightningd knows and thus use listsendpay
before computing routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00

56 lines
2 KiB
C

#ifndef LIGHTNING_PLUGINS_RENEPAY_ROUTETRACKER_H
#define LIGHTNING_PLUGINS_RENEPAY_ROUTETRACKER_H
/* This module provides entry points for the management of a route thread. */
#include "config.h"
#include <plugins/renepay/route.h>
struct routetracker{
/* Routes that we sendpay and are still waiting for rpc returning
* success. */
struct route_map *sent_routes;
/* Routes that have concluded (either SENDPAY_FAILED or
* SENDPAY_COMPLETE). */
struct route **finalized_routes;
};
struct routetracker *new_routetracker(const tal_t *ctx, struct payment *payment);
void routetracker_cleanup(struct routetracker *routetracker);
bool routetracker_have_results(struct routetracker *routetracker);
/* The payment has a list of route that have "returned". Calling this function
* payment will look through that list and process those routes' results:
* - update the commited amounts,
* - update the uncertainty network,
* - and free the allocated memory. */
void payment_collect_results(struct payment *payment,
struct preimage **payment_preimage,
enum jsonrpc_errcode *final_error,
const char **final_msg);
/* Sends a sendpay request for this route. */
struct command_result *route_sendpay_request(struct command *cmd,
struct route *route,
struct payment *payment);
struct command_result *notification_sendpay_failure(struct command *cmd,
const char *buf,
const jsmntok_t *params);
struct command_result *notification_sendpay_success(struct command *cmd,
const char *buf,
const jsmntok_t *params);
/* Notify the tracker that this route has failed. */
void route_failure_register(struct routetracker *routetracker,
struct route *route);
// FIXME: double-check that we actually get one notification for each sendpay,
// ie. that after some time we don't have yet pending sendpays for old failed or
// successful payments that we havent processed because we haven't received the
// notification
#endif /* LIGHTNING_PLUGINS_RENEPAY_ROUTETRACKER_H */