Skip to content

Commit

Permalink
libplugin-pay: incorporate gossip store.
Browse files Browse the repository at this point in the history
So we can use this for routing determinations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Oct 20, 2020
1 parent 5e47c1a commit c97236a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions common/gossip_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@
#define GOSSIP_TOKEN_TIME(dev_fast_gossip_flag) \
DEV_FAST_GOSSIP(dev_fast_gossip_flag, 1, 3600)

/* This is where we keep our gossip */
#define GOSSIP_STORE_FILENAME "gossip_store"

#endif /* LIGHTNING_COMMON_GOSSIP_CONSTANTS_H */
1 change: 0 additions & 1 deletion gossipd/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <wire/peer_wire.h>
#include <wire/wire.h>

#define GOSSIP_STORE_FILENAME "gossip_store"
#define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp"

struct gossip_store {
Expand Down
4 changes: 2 additions & 2 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PLUGIN_COMMON_OBJS := \
wire/tlvstream.o \
wire/towire.o

plugins/pay: bitcoin/chainparams.o $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/pay: bitcoin/chainparams.o $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/route.o common/dijkstra.o
$(PLUGIN_PAY_OBJS): $(PLUGIN_PAY_LIB_HEADER)

plugins/autoclean: bitcoin/chainparams.o $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
Expand All @@ -110,7 +110,7 @@ plugins/txprepare: bitcoin/chainparams.o $(PLUGIN_TXPREPARE_OBJS) $(PLUGIN_LIB_O

plugins/bcli: bitcoin/chainparams.o $(PLUGIN_BCLI_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/keysend: bitcoin/chainparams.o wire/tlvstream.o wire/onion$(EXP)_wiregen.o $(PLUGIN_KEYSEND_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/keysend: bitcoin/chainparams.o wire/tlvstream.o wire/onion$(EXP)_wiregen.o $(PLUGIN_KEYSEND_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) common/gossmap.o common/route.o common/dijkstra.o
$(PLUGIN_KEYSEND_OBJS): $(PLUGIN_PAY_LIB_HEADER)

plugins/spenderp: bitcoin/chainparams.o $(PLUGIN_SPENDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
Expand Down
15 changes: 15 additions & 0 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#include <bitcoin/preimage.h>
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <common/dijkstra.h>
#include <common/gossmap.h>
#include <common/json_helpers.h>
#include <common/json_stream.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <common/random_select.h>
#include <common/type_to_string.h>
#include <errno.h>
#include <plugins/libplugin-pay.h>

static struct gossmap *gossmap;

/* BOLT #11:
* * `c` (24): `data_length` variable.
* `min_final_cltv_expiry` to use for the last HTLC in the route.
Expand All @@ -23,6 +29,15 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,

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->parent = parent;
p->modifiers = mods;
Expand Down

0 comments on commit c97236a

Please sign in to comment.