mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
plugins/libplugin-pay: expose gossmap for plugin special effects.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
neil saitug
parent
695a8bd868
commit
c5a2e64fd4
@@ -13,7 +13,26 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <plugins/libplugin-pay.h>
|
#include <plugins/libplugin-pay.h>
|
||||||
|
|
||||||
static struct gossmap *gossmap;
|
static struct gossmap *global_gossmap;
|
||||||
|
|
||||||
|
static void init_gossmap(struct plugin *plugin)
|
||||||
|
{
|
||||||
|
global_gossmap
|
||||||
|
= notleak_with_children(gossmap_load(NULL,
|
||||||
|
GOSSIP_STORE_FILENAME));
|
||||||
|
if (!global_gossmap)
|
||||||
|
plugin_err(plugin, "Could not load gossmap %s: %s",
|
||||||
|
GOSSIP_STORE_FILENAME, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gossmap *get_gossmap(struct plugin *plugin)
|
||||||
|
{
|
||||||
|
if (!global_gossmap)
|
||||||
|
init_gossmap(plugin);
|
||||||
|
else
|
||||||
|
gossmap_refresh(global_gossmap);
|
||||||
|
return global_gossmap;
|
||||||
|
}
|
||||||
|
|
||||||
struct payment *payment_new(tal_t *ctx, struct command *cmd,
|
struct payment *payment_new(tal_t *ctx, struct command *cmd,
|
||||||
struct payment *parent,
|
struct payment *parent,
|
||||||
@@ -23,15 +42,6 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
|
|||||||
|
|
||||||
static u64 next_id = 0;
|
static u64 next_id = 0;
|
||||||
|
|
||||||
/* Now we're actually creating a payment, load gossip store */
|
|
||||||
if (!gossmap) {
|
|
||||||
gossmap = notleak_with_children(gossmap_load(NULL,
|
|
||||||
GOSSIP_STORE_FILENAME));
|
|
||||||
if (!gossmap)
|
|
||||||
plugin_err(cmd->plugin, "Could not load gossmap %s: %s",
|
|
||||||
GOSSIP_STORE_FILENAME, strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
p->children = tal_arr(p, struct payment *, 0);
|
p->children = tal_arr(p, struct payment *, 0);
|
||||||
p->parent = parent;
|
p->parent = parent;
|
||||||
p->modifiers = mods;
|
p->modifiers = mods;
|
||||||
@@ -593,7 +603,7 @@ static const struct channel_hint *find_hint(const struct channel_hint *hints,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: This is slow! */
|
/* FIXME: This is slow! */
|
||||||
static bool dst_is_excluded(const struct gossmap *gossmmap,
|
static bool dst_is_excluded(const struct gossmap *gossmap,
|
||||||
const struct gossmap_chan *c,
|
const struct gossmap_chan *c,
|
||||||
int dir,
|
int dir,
|
||||||
const struct node_id *nodes)
|
const struct node_id *nodes)
|
||||||
@@ -679,6 +689,7 @@ static struct route_hop *route_hops_from_route(const tal_t *ctx,
|
|||||||
{
|
{
|
||||||
struct route_hop *hops = tal_arr(ctx, struct route_hop, tal_count(r));
|
struct route_hop *hops = tal_arr(ctx, struct route_hop, tal_count(r));
|
||||||
struct amount_msat amt;
|
struct amount_msat amt;
|
||||||
|
struct gossmap *gossmap = get_gossmap(p->plugin);
|
||||||
u32 delay;
|
u32 delay;
|
||||||
|
|
||||||
for (size_t i = 0; i < tal_count(hops); i++) {
|
for (size_t i = 0; i < tal_count(hops); i++) {
|
||||||
@@ -721,14 +732,14 @@ static struct command_result *payment_getroute(struct payment *p)
|
|||||||
const struct gossmap_node *dst, *src;
|
const struct gossmap_node *dst, *src;
|
||||||
struct route **r;
|
struct route **r;
|
||||||
struct amount_msat fee;
|
struct amount_msat fee;
|
||||||
|
struct gossmap *gossmap;
|
||||||
bool (*can_carry)(const struct gossmap *,
|
bool (*can_carry)(const struct gossmap *,
|
||||||
const struct gossmap_chan *,
|
const struct gossmap_chan *,
|
||||||
int,
|
int,
|
||||||
struct amount_msat,
|
struct amount_msat,
|
||||||
struct payment *);
|
struct payment *);
|
||||||
|
|
||||||
/* Make sure we're up-to-date with any new entries */
|
gossmap = get_gossmap(p->plugin);
|
||||||
gossmap_refresh(gossmap);
|
|
||||||
|
|
||||||
dst = gossmap_find_node(gossmap, p->getroute->destination);
|
dst = gossmap_find_node(gossmap, p->getroute->destination);
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
|
|||||||
@@ -435,4 +435,7 @@ void payment_fail(struct payment *p, const char *fmt, ...) PRINTF_FMT(2,3);
|
|||||||
struct payment *payment_root(struct payment *p);
|
struct payment *payment_root(struct payment *p);
|
||||||
struct payment_tree_result payment_collect_result(struct payment *p);
|
struct payment_tree_result payment_collect_result(struct payment *p);
|
||||||
|
|
||||||
|
/* For special effects, like inspecting your own routes. */
|
||||||
|
struct gossmap *get_gossmap(struct plugin *plugin);
|
||||||
|
|
||||||
#endif /* LIGHTNING_PLUGINS_LIBPLUGIN_PAY_H */
|
#endif /* LIGHTNING_PLUGINS_LIBPLUGIN_PAY_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user