core-lightning/plugins/askrene/reserve.h
Rusty Russell 990bbdde27 askrene: fast lookup for capacities.
We don't know anything about most channels, so we create an array of
fp16_t containing them.  We zero out ones where we do know something,
and use the previous code as the slow path.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-07 20:35:30 +09:30

43 lines
1.6 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>
/* We reserve a path being used. This records how many and how much */
struct reserve {
size_t num_htlcs;
struct short_channel_id_dir scidd;
struct amount_msat amount;
};
/* Initialize hash table for reservations */
struct reserve_hash *new_reserve_hash(const tal_t *ctx);
/* Find a reservation for this scidd (if any!) */
const struct reserve *find_reserve(const struct reserve_hash *reserved,
const struct short_channel_id_dir *scidd);
/* Atomically add to reserves, or fail.
* Returns offset of failure, or num on success */
size_t reserves_add(struct reserve_hash *reserved,
const struct short_channel_id_dir *scidds,
const struct amount_msat *amounts,
size_t num);
/* Atomically remove from reserves, to fail.
* Returns offset of failure or tal_count(scidds) */
size_t reserves_remove(struct reserve_hash *reserved,
const struct short_channel_id_dir *scidds,
const struct amount_msat *amounts,
size_t num);
/* Clear capacities array where we have reserves */
void reserves_clear_capacities(struct reserve_hash *reserved,
const struct gossmap *gossmap,
fp16_t *capacities);
#endif /* LIGHTNING_PLUGINS_ASKRENE_RESERVE_H */