core-lightning/plugins/renepay/routetracker.h
Lagrang3 07d4451a40 renepay: bugfix reading pending sendpays
When renepay starts, one of the first operations it does is to check for
pending sendpays for the same invoice. Those are added up to an internal
database to keep track of. Also the amount they deliver to the
destination is computed so that the current payment rpc call would try
to complete the payment for whatever amount remains to pay.
For an incomplete payment after calling the RPC renepay I found this in
the logs:

2024-05-22T19:44:19.853Z DEBUG   plugin-cln-renepay: There are pending sendpays to this invoice. groupid = 6 delivering = 0msat, last_partid = 10

Where delivering should be the sum of the amounts delivered by pending routes.
2024-08-09 14:38:17 +09:30

63 lines
2.3 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{
struct payment *payment;
struct route_map *sent_routes;
struct route_map *pending_routes;
struct route **finalized_routes;
};
struct routetracker *new_routetracker(const tal_t *ctx, struct payment *payment);
// bool routetracker_is_ready(const struct routetracker *routetracker);
void routetracker_cleanup(struct routetracker *routetracker);
size_t routetracker_count_sent(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);
/* Announce that this route is pending and needs to be kept in the waiting list
* for notifications. */
void route_pending_register(struct routetracker *routetracker,
struct route *route);
/* 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);
/* How much is the amount being tracked. */
bool routetracker_get_amount(struct routetracker *routetracker,
struct amount_msat *amount,
struct amount_msat *amount_sent);
// 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 */