Files
palladum-lightning/plugins/askrene/reserve.h
Rusty Russell 1102d8063e askrene: add optional layers to reservations.
We have the issue of aliases: xpay uses scids like 0x0x0 for
routehints and blinded paths, and then can apply reservations to them.  But
generally, reservations are *global*, so we need to differentiate.

Changelog-Added: Plugins: `askrene-reserve` and `askrene-unreserve` can take an optional `layer` inside `path` elements.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-17 13:52:54 +10:30

60 lines
2.0 KiB
C

#ifndef LIGHTNING_PLUGINS_ASKRENE_RESERVE_H
#define LIGHTNING_PLUGINS_ASKRENE_RESERVE_H
/* We have to know what payments are in progress, so we can take into
* account the reduced capacity of channels. We do this by telling
* everyone to reserve / unreserve paths as they use them. */
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <common/amount.h>
#include <common/fp16.h>
/* Initialize hash table for reservations */
struct reserve_htable *new_reserve_htable(const tal_t *ctx);
struct reserve_hop {
struct short_channel_id_dir scidd;
struct amount_msat amount;
/* If non-NULL, only applies to this layer */
const struct layer *layer;
};
/* Add a reservation. */
void reserve_add(struct reserve_htable *reserved,
const struct reserve_hop *rhop,
const char *cmd_id TAKES);
/* Try to remove a reservation, if it exists. */
bool reserve_remove(struct reserve_htable *reserved,
const struct reserve_hop *rhop);
/* Clear capacities array where we have reserves */
void reserves_clear_capacities(struct reserve_htable *reserved,
const struct gossmap *gossmap,
fp16_t *capacities);
/* Subtract any reserves for scidd from this amount */
void reserve_sub(const struct reserve_htable *reserved,
const struct short_channel_id_dir *scidd,
const struct layer **layers,
struct amount_msat *amount);
/* Add any reserves for scidd to this amount */
bool reserve_accumulate(const struct reserve_htable *reserved,
const struct short_channel_id_dir *scidd,
const struct layer *layer,
struct amount_msat *amount);
/* To explain why we couldn't route */
const char *fmt_reservations(const tal_t *ctx,
const struct reserve_htable *reserved,
const struct short_channel_id_dir *scidd,
const struct layer **layers);
/* Print out a json object for all reservations */
void json_add_reservations(struct json_stream *js,
const struct reserve_htable *reserved,
const char *fieldname,
const struct layer **layers);
#endif /* LIGHTNING_PLUGINS_ASKRENE_RESERVE_H */