Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Askrene: an EXPERIMENTAL MCF plugin and infrastructure #7517

Merged
merged 28 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0180ad9
doc: document askrene.
rustyrussell Aug 7, 2024
1034c6f
gossmap: don't process channel_announcement until amount is present.
rustyrussell Aug 7, 2024
df08615
libplugin: add data pointer for plugin convenience.
rustyrussell Aug 7, 2024
ad2ac92
common: new parameter parsing routines.
rustyrussell Aug 7, 2024
60f0189
bitcoin: add short_channel_id_dir_eq.
rustyrussell Aug 7, 2024
cfe5f05
common: promote useful routines from renepay.
rustyrussell Aug 7, 2024
a611ec2
askrene: skeleton which does JSON API.
rustyrussell Aug 7, 2024
d786110
askrene: add layers infrastructure.
rustyrussell Aug 7, 2024
11fd784
askrene: reservation implementation.
rustyrussell Aug 7, 2024
99ad986
askrene: flesh out getroutes() a little.
rustyrussell Aug 7, 2024
0e7073b
askrene: always set a dummy constraint when we add a local channel.
rustyrussell Aug 7, 2024
f93324e
askrene: fast lookup for capacities.
rustyrussell Aug 7, 2024
15cbc14
pytest: test file for askrene.
rustyrussell Aug 7, 2024
46d00ed
askrene: copy mcf.[ch] from renepay with minimal modifications.
rustyrussell Aug 7, 2024
5393432
askrene: simplify minflow()
rustyrussell Aug 7, 2024
4cd80da
askrene: copy flow and dijkstra from renepay.
rustyrussell Aug 7, 2024
19e3495
askrene/flow: don't omit initial hop in flow_spend.
rustyrussell Aug 7, 2024
a28759b
askrene: remove code which tries to handle tal failures.
rustyrussell Aug 7, 2024
2c92d23
askrene: simply fail if a flow amount exceeds 64 bits.
rustyrussell Aug 7, 2024
86f5dc5
askrene: make the flow.[ch] files compile.
rustyrussell Aug 7, 2024
10bfb88
askrene: include the mcf and flow routines.
rustyrussell Aug 7, 2024
79bbb04
plugins/askrene: remove local contexts.
rustyrussell Aug 7, 2024
ee4dba7
plugins/askrene: attach getroutes call to MCF code.
rustyrussell Aug 7, 2024
6702563
pytest: simple getroutes tests.
rustyrussell Aug 7, 2024
b3b885b
plugin/askrene: add "auto.sourcefree" layer.
rustyrussell Aug 7, 2024
61c314a
devtools/gossmap-compress: allow setting the nodeid explicitly for ge…
rustyrussell Aug 7, 2024
4f6c88e
askrene: split json_getroutes into two parts.
rustyrussell Aug 7, 2024
3d3a5f9
askrene: add "auto.localchans" layer.
rustyrussell Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bitcoin/short_channel_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ struct short_channel_id_dir {
int dir;
};

static inline bool short_channel_id_dir_eq(const struct short_channel_id_dir *a,
const struct short_channel_id_dir *b)
{
return short_channel_id_eq(a->scid, b->scid) && a->dir == b->dir;
}

static inline u32 short_channel_id_blocknum(struct short_channel_id scid)
{
return scid.u64 >> 40;
Expand Down
13 changes: 13 additions & 0 deletions common/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ bool amount_msat_eq_sat(struct amount_msat msat, struct amount_sat sat);
/* a / b */
double amount_msat_ratio(struct amount_msat a, struct amount_msat b);

/* min(a,b) and max(a,b) */
static inline struct amount_msat amount_msat_min(struct amount_msat a,
struct amount_msat b)
{
return amount_msat_less(a, b) ? a : b;
}

static inline struct amount_msat amount_msat_max(struct amount_msat a,
struct amount_msat b)
{
return amount_msat_greater(a, b) ? a : b;
}

/* Check whether this asset is actually the main / fee-paying asset of the
* current chain. */
bool amount_asset_is_main(struct amount_asset *asset);
Expand Down
21 changes: 15 additions & 6 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ void gossmap_remove_node(struct gossmap *map, struct gossmap_node *node)
* * [`point`:`node_id_2`]
*/
static struct gossmap_chan *add_channel(struct gossmap *map,
size_t cannounce_off)
size_t cannounce_off,
size_t msglen)
{
/* Note that first two bytes are message type */
const size_t feature_len_off = 2 + (64 + 64 + 64 + 64);
Expand Down Expand Up @@ -473,6 +474,12 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
return NULL;
}

/* gossipd writes WIRE_GOSSIP_STORE_CHANNEL_AMOUNT after this (not for
* local channels), so ignore channel_announcement until that appears */
if (msglen
&& (map->map_size < cannounce_off + msglen + sizeof(struct gossip_hdr) + sizeof(u16) + sizeof(u64)))
return NULL;

/* We carefully map pointers to indexes, since new_node can move them! */
n[0] = gossmap_find_node(map, &node_id[0]);
if (n[0])
Expand Down Expand Up @@ -668,9 +675,11 @@ static bool map_catchup(struct gossmap *map, bool *changed)

off = map->map_end + sizeof(ghdr);
type = map_be16(map, off);
if (type == WIRE_CHANNEL_ANNOUNCEMENT)
add_channel(map, off);
else if (type == WIRE_CHANNEL_UPDATE)
if (type == WIRE_CHANNEL_ANNOUNCEMENT) {
/* Don't read yet if amount field is not there! */
if (!add_channel(map, off, be16_to_cpu(ghdr.len)))
break;
} else if (type == WIRE_CHANNEL_UPDATE)
update_channel(map, off);
else if (type == WIRE_GOSSIP_STORE_DELETE_CHAN)
remove_channel_by_deletemsg(map, off);
Expand Down Expand Up @@ -944,7 +953,7 @@ void gossmap_apply_localmods(struct gossmap *map,
continue;

/* Create new channel, pointing into local. */
chan = add_channel(map, map->map_size + mod->local_off);
chan = add_channel(map, map->map_size + mod->local_off, 0);
}

/* Save old, overwrite (keep nodeidx) */
Expand Down Expand Up @@ -1144,7 +1153,7 @@ bool gossmap_chan_get_capacity(const struct gossmap *map,
off += sizeof(ghdr) + be16_to_cpu(ghdr.len);

/* Partial write, this can happen. */
if (off + sizeof(ghdr) + 2 > map->map_size)
if (off + sizeof(ghdr) + sizeof(u16) + sizeof(u64) > map->map_size)
return false;

/* Get type of next field. */
Expand Down
15 changes: 14 additions & 1 deletion common/gossmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static inline bool gossmap_chan_set(const struct gossmap_chan *chan, int dir)
return chan->cupdate_off[dir] != 0;
}

/* Return capacity if it's known (fails only on race condition, or a local mod) */
/* Return capacity if it's known (fails on a local mod) */
bool gossmap_chan_get_capacity(const struct gossmap *map,
const struct gossmap_chan *c,
struct amount_sat *amount);
Expand Down Expand Up @@ -242,6 +242,19 @@ bool gossmap_chan_has_capacity(const struct gossmap_chan *chan,
int direction,
struct amount_msat amount);

/* Convenience routines to get htlc min/max as amount_msat */
static inline struct amount_msat
gossmap_chan_htlc_max(const struct gossmap_chan *chan, const int dir)
{
return amount_msat(fp16_to_u64(chan->half[dir].htlc_max));
}

static inline struct amount_msat
gossmap_chan_htlc_min(const struct gossmap_chan *chan, const int dir)
{
return amount_msat(fp16_to_u64(chan->half[dir].htlc_min));
}

/* Remove a channel from the map (warning! realloc can move gossmap_chan
* and gossmap_node ptrs!) */
void gossmap_remove_chan(struct gossmap *map, struct gossmap_chan *chan);
Expand Down
12 changes: 12 additions & 0 deletions common/json_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ struct command_result *param_sha256(struct command *cmd, const char *name,
"should be a 32 byte hex value");
}

struct command_result *param_u16(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
uint16_t **num)
{
*num = tal(cmd, uint16_t);
if (json_to_u16(buffer, tok, *num))
return NULL;

return command_fail_badparam(cmd, name, buffer, tok,
"should be an unsigned 16 bit integer");
}

struct command_result *param_u32(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
uint32_t **num)
Expand Down
5 changes: 5 additions & 0 deletions common/json_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ struct command_result *param_sha256(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
struct sha256 **hash);

/* Extract number from this (may be a string, or a number literal) */
struct command_result *param_u16(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
uint16_t **num);

/* Extract number from this (may be a string, or a number literal) */
struct command_result *param_u32(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
Expand Down
Loading
Loading