2018-03-22 11:36:25 +01:00
|
|
|
#ifndef LIGHTNING_GOSSIPD_ROUTING_H
|
|
|
|
#define LIGHTNING_GOSSIPD_ROUTING_H
|
2016-06-28 23:19:21 +02:00
|
|
|
#include "config.h"
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <bitcoin/pubkey.h>
|
2018-02-23 01:00:00 +01:00
|
|
|
#include <ccan/crypto/siphash24/siphash24.h>
|
2017-01-21 15:13:10 +01:00
|
|
|
#include <ccan/htable/htable_type.h>
|
2019-06-03 20:22:25 +02:00
|
|
|
#include <ccan/intmap/intmap.h>
|
2018-02-05 20:41:10 +01:00
|
|
|
#include <ccan/time/time.h>
|
2019-02-21 03:39:21 +01:00
|
|
|
#include <common/amount.h>
|
2019-09-22 04:07:43 +02:00
|
|
|
#include <common/gossip_constants.h>
|
2019-04-08 11:58:32 +02:00
|
|
|
#include <common/node_id.h>
|
2017-08-29 06:12:04 +02:00
|
|
|
#include <gossipd/broadcast.h>
|
2018-03-18 15:01:22 +01:00
|
|
|
#include <gossipd/gossip_store.h>
|
2018-01-18 00:32:36 +01:00
|
|
|
#include <wire/gen_onion_wire.h>
|
2017-08-28 18:04:01 +02:00
|
|
|
#include <wire/wire.h>
|
2016-06-28 23:19:21 +02:00
|
|
|
|
2019-10-08 03:13:24 +02:00
|
|
|
struct daemon;
|
|
|
|
struct peer;
|
2019-06-03 20:22:25 +02:00
|
|
|
struct routing_state;
|
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
struct half_chan {
|
2016-06-28 23:19:21 +02:00
|
|
|
/* millisatoshi. */
|
|
|
|
u32 base_fee;
|
|
|
|
/* millionths */
|
2017-12-18 05:15:38 +01:00
|
|
|
u32 proportional_fee;
|
2016-06-28 23:19:21 +02:00
|
|
|
|
|
|
|
/* Delay for HTLC in blocks.*/
|
|
|
|
u32 delay;
|
2016-12-12 14:55:46 +01:00
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/* Timestamp and index into store file */
|
|
|
|
struct broadcastable bcast;
|
2017-01-04 04:39:20 +01:00
|
|
|
|
2016-12-12 14:55:46 +01:00
|
|
|
/* Flags as specified by the `channel_update`s, among other
|
|
|
|
* things indicated direction wrt the `channel_id` */
|
2018-09-20 02:59:46 +02:00
|
|
|
u8 channel_flags;
|
|
|
|
|
|
|
|
/* Flags as specified by the `channel_update`s, indicates
|
|
|
|
* optional fields. */
|
|
|
|
u8 message_flags;
|
2019-04-10 09:31:29 +02:00
|
|
|
|
2019-09-16 12:44:00 +02:00
|
|
|
/* Token bucket */
|
|
|
|
u8 tokens;
|
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/* Minimum and maximum number of msatoshi in an HTLC */
|
|
|
|
struct amount_msat htlc_minimum, htlc_maximum;
|
2016-06-28 23:19:21 +02:00
|
|
|
};
|
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
struct chan {
|
|
|
|
struct short_channel_id scid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* half[0]->src == nodes[0] half[0]->dst == nodes[1]
|
|
|
|
* half[1]->src == nodes[1] half[1]->dst == nodes[0]
|
|
|
|
*/
|
|
|
|
struct half_chan half[2];
|
|
|
|
/* node[0].id < node[1].id */
|
|
|
|
struct node *nodes[2];
|
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/* Timestamp and index into store file */
|
|
|
|
struct broadcastable bcast;
|
2018-03-04 03:26:59 +01:00
|
|
|
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat;
|
2018-03-04 03:26:59 +01:00
|
|
|
};
|
|
|
|
|
2019-09-16 12:43:51 +02:00
|
|
|
/* Shadow structure for local channels: owned by the chan above, but kept
|
|
|
|
* separately to keep `struct chan` minimal since there may be millions
|
|
|
|
* of non-local channels. */
|
|
|
|
struct local_chan {
|
|
|
|
struct chan *chan;
|
|
|
|
int direction;
|
|
|
|
|
|
|
|
/* We soft-disable local channels when a peer disconnects */
|
|
|
|
bool local_disabled;
|
2019-09-16 12:43:59 +02:00
|
|
|
|
|
|
|
/* Timer if we're deferring an update. */
|
|
|
|
struct oneshot *channel_update_timer;
|
2019-09-16 12:43:51 +02:00
|
|
|
};
|
|
|
|
|
2019-05-21 09:13:28 +02:00
|
|
|
/* Use this instead of tal_free(chan)! */
|
|
|
|
void free_chan(struct routing_state *rstate, struct chan *chan);
|
|
|
|
|
2019-06-03 20:07:25 +02:00
|
|
|
/* A local channel can exist which isn't announced: we abuse timestamp
|
|
|
|
* to indicate this. */
|
2018-05-10 16:00:38 +02:00
|
|
|
static inline bool is_chan_public(const struct chan *chan)
|
2018-09-04 07:22:47 +02:00
|
|
|
{
|
2019-06-03 20:07:25 +02:00
|
|
|
return chan->bcast.timestamp != 0;
|
2018-09-04 07:22:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-10 16:00:38 +02:00
|
|
|
static inline bool is_halfchan_defined(const struct half_chan *hc)
|
|
|
|
{
|
2019-04-11 07:16:30 +02:00
|
|
|
return hc->bcast.index != 0;
|
2018-05-10 16:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool is_halfchan_enabled(const struct half_chan *hc)
|
|
|
|
{
|
2018-09-20 02:59:46 +02:00
|
|
|
return is_halfchan_defined(hc) && !(hc->channel_flags & ROUTING_FLAGS_DISABLED);
|
2018-05-10 16:00:38 +02:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:51:30 +02:00
|
|
|
/* Container for per-node channel pointers. Better cache performance
|
2019-09-16 12:43:51 +02:00
|
|
|
* than uintmap, and we don't need ordering. */
|
2019-04-08 01:51:30 +02:00
|
|
|
static inline const struct short_channel_id *chan_map_scid(const struct chan *c)
|
|
|
|
{
|
|
|
|
return &c->scid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t hash_scid(const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
/* scids cost money to generate, so simple hash works here */
|
|
|
|
return (scid->u64 >> 32) ^ (scid->u64 >> 16) ^ scid->u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool chan_eq_scid(const struct chan *c,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
return short_channel_id_eq(scid, &c->scid);
|
|
|
|
}
|
2019-04-08 17:31:59 +02:00
|
|
|
|
2019-04-08 01:51:30 +02:00
|
|
|
HTABLE_DEFINE_TYPE(struct chan, chan_map_scid, hash_scid, chan_eq_scid, chan_map);
|
|
|
|
|
2019-09-16 12:43:51 +02:00
|
|
|
/* Container for local channel pointers. */
|
|
|
|
static inline const struct short_channel_id *local_chan_map_scid(const struct local_chan *local_chan)
|
|
|
|
{
|
|
|
|
return &local_chan->chan->scid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool local_chan_eq_scid(const struct local_chan *local_chan,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
return short_channel_id_eq(scid, &local_chan->chan->scid);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct local_chan,
|
|
|
|
local_chan_map_scid, hash_scid, local_chan_eq_scid,
|
|
|
|
local_chan_map);
|
|
|
|
|
2019-04-08 06:44:43 +02:00
|
|
|
/* For a small number of channels (by far the most common) we use a simple
|
|
|
|
* array, with empty buckets NULL. For larger, we use a proper hash table,
|
|
|
|
* with the extra allocation that implies. */
|
2019-04-08 06:43:43 +02:00
|
|
|
#define NUM_IMMEDIATE_CHANS (sizeof(struct chan_map) / sizeof(struct chan *) - 1)
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
struct node {
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id id;
|
2016-09-28 16:52:03 +02:00
|
|
|
|
2019-04-10 09:31:29 +02:00
|
|
|
/* Timestamp and index into store file */
|
|
|
|
struct broadcastable bcast;
|
2017-09-01 06:18:54 +02:00
|
|
|
|
2019-09-16 12:44:00 +02:00
|
|
|
/* Token bucket */
|
|
|
|
u8 tokens;
|
|
|
|
|
2018-03-02 09:59:16 +01:00
|
|
|
/* Channels connecting us to other nodes */
|
2019-04-08 06:43:43 +02:00
|
|
|
union {
|
|
|
|
struct chan_map map;
|
|
|
|
struct chan *arr[NUM_IMMEDIATE_CHANS+1];
|
|
|
|
} chans;
|
2016-06-28 23:19:21 +02:00
|
|
|
|
|
|
|
/* Temporary data for routefinding. */
|
2019-04-17 09:35:33 +02:00
|
|
|
struct {
|
|
|
|
/* Total to get to here from target. */
|
|
|
|
struct amount_msat total;
|
|
|
|
/* Total risk premium of this route. */
|
|
|
|
struct amount_msat risk;
|
|
|
|
} dijkstra;
|
2016-06-28 23:19:21 +02:00
|
|
|
};
|
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *node_map_keyof_node(const struct node *n);
|
|
|
|
size_t node_map_hash_key(const struct node_id *pc);
|
|
|
|
bool node_map_node_eq(const struct node *n, const struct node_id *pc);
|
2017-01-21 15:13:10 +01:00
|
|
|
HTABLE_DEFINE_TYPE(struct node, node_map_keyof_node, node_map_hash_key, node_map_node_eq, node_map);
|
|
|
|
|
2019-04-08 17:31:59 +02:00
|
|
|
/* We've unpacked and checked its signatures, now we wait for master to tell
|
|
|
|
* us the txout to check */
|
|
|
|
struct pending_cannouncement {
|
|
|
|
/* Unpacked fields here */
|
|
|
|
|
|
|
|
/* also the key in routing_state->pending_cannouncements */
|
|
|
|
struct short_channel_id short_channel_id;
|
|
|
|
struct node_id node_id_1;
|
|
|
|
struct node_id node_id_2;
|
|
|
|
struct pubkey bitcoin_key_1;
|
|
|
|
struct pubkey bitcoin_key_2;
|
|
|
|
|
2019-10-08 03:13:24 +02:00
|
|
|
/* Automagically turns to NULL of peer freed */
|
|
|
|
struct peer *peer_softref;
|
|
|
|
|
2019-04-08 17:31:59 +02:00
|
|
|
/* The raw bits */
|
|
|
|
const u8 *announce;
|
|
|
|
|
|
|
|
/* Deferred updates, if we received them while waiting for
|
|
|
|
* this (one for each direction) */
|
|
|
|
const u8 *updates[2];
|
2019-10-08 03:13:24 +02:00
|
|
|
/* Peers responsible: turns to NULL if they're freed */
|
|
|
|
struct peer *update_peer_softref[2];
|
2019-04-08 17:31:59 +02:00
|
|
|
|
|
|
|
/* Only ever replace with newer updates */
|
|
|
|
u32 update_timestamps[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct short_channel_id *panding_cannouncement_map_scid(
|
|
|
|
const struct pending_cannouncement *pending_ann)
|
|
|
|
{
|
|
|
|
return &pending_ann->short_channel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t hash_pending_cannouncement_scid(
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
/* like hash_scid() for struct chan above */
|
|
|
|
return (scid->u64 >> 32) ^ (scid->u64 >> 16) ^ scid->u64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool pending_cannouncement_eq_scid(
|
|
|
|
const struct pending_cannouncement *pending_ann,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
|
|
|
return short_channel_id_eq(scid, &pending_ann->short_channel_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct pending_cannouncement, panding_cannouncement_map_scid,
|
|
|
|
hash_pending_cannouncement_scid, pending_cannouncement_eq_scid,
|
|
|
|
pending_cannouncement_map);
|
|
|
|
|
2018-02-02 19:49:12 +01:00
|
|
|
struct pending_node_map;
|
2019-04-11 07:15:13 +02:00
|
|
|
struct unupdated_channel;
|
2018-02-02 19:49:12 +01:00
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
/* Fast versions: if you know n is one end of the channel */
|
2018-09-27 07:29:17 +02:00
|
|
|
static inline struct node *other_node(const struct node *n,
|
|
|
|
const struct chan *chan)
|
2018-03-04 03:23:32 +01:00
|
|
|
{
|
|
|
|
int idx = (chan->nodes[1] == n);
|
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
2018-03-04 03:23:32 +01:00
|
|
|
return chan->nodes[!idx];
|
|
|
|
}
|
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
/* If you know n is one end of the channel, get connection src == n */
|
2018-03-04 03:26:59 +01:00
|
|
|
static inline struct half_chan *half_chan_from(const struct node *n,
|
|
|
|
struct chan *chan)
|
2018-03-02 09:59:16 +01:00
|
|
|
{
|
|
|
|
int idx = (chan->nodes[1] == n);
|
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
2018-03-04 03:26:59 +01:00
|
|
|
return &chan->half[idx];
|
2018-03-02 09:59:16 +01:00
|
|
|
}
|
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
/* If you know n is one end of the channel, get index dst == n */
|
2018-09-27 07:29:17 +02:00
|
|
|
static inline int half_chan_to(const struct node *n, const struct chan *chan)
|
2018-03-02 09:59:16 +01:00
|
|
|
{
|
|
|
|
int idx = (chan->nodes[1] == n);
|
|
|
|
|
2018-03-04 03:26:58 +01:00
|
|
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
2018-03-04 03:23:32 +01:00
|
|
|
return !idx;
|
2018-03-02 09:59:16 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 23:46:07 +01:00
|
|
|
struct routing_state {
|
2018-11-21 04:10:03 +01:00
|
|
|
/* Which chain we're on */
|
|
|
|
const struct chainparams *chainparams;
|
|
|
|
|
2019-09-27 02:04:34 +02:00
|
|
|
/* TImers base from struct gossipd. */
|
|
|
|
struct timers *timers;
|
|
|
|
|
2017-01-19 23:46:07 +01:00
|
|
|
/* All known nodes. */
|
|
|
|
struct node_map *nodes;
|
|
|
|
|
2018-03-02 09:59:13 +01:00
|
|
|
/* node_announcements which are waiting on pending_cannouncement */
|
2018-02-02 19:49:12 +01:00
|
|
|
struct pending_node_map *pending_node_map;
|
|
|
|
|
2018-01-04 12:40:58 +01:00
|
|
|
/* channel_announcement which are pending short_channel_id lookup */
|
2019-04-08 17:31:59 +02:00
|
|
|
struct pending_cannouncement_map pending_cannouncements;
|
2018-01-04 12:40:58 +01:00
|
|
|
|
2019-06-03 20:22:25 +02:00
|
|
|
/* Gossip store */
|
|
|
|
struct gossip_store *gs;
|
2017-08-22 07:25:01 +02:00
|
|
|
|
2017-11-24 15:47:14 +01:00
|
|
|
/* Our own ID so we can identify local channels */
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id local_id;
|
2018-01-30 19:46:07 +01:00
|
|
|
|
|
|
|
/* A map of channels indexed by short_channel_ids */
|
2018-03-04 03:26:59 +01:00
|
|
|
UINTMAP(struct chan *) chanmap;
|
2018-06-04 06:15:25 +02:00
|
|
|
|
2019-04-11 07:15:13 +02:00
|
|
|
/* A map of channel_announcements indexed by short_channel_ids:
|
|
|
|
* we haven't got a channel_update for these yet. */
|
|
|
|
UINTMAP(struct unupdated_channel *) unupdated_chanmap;
|
|
|
|
|
2018-06-04 06:15:25 +02:00
|
|
|
/* Has one of our own channels been announced? */
|
|
|
|
bool local_channel_announced;
|
2019-03-27 15:40:25 +01:00
|
|
|
|
|
|
|
/* Cache for txout queries that failed. Allows us to skip failed
|
|
|
|
* checks if we get another announcement for the same scid. */
|
2019-09-27 02:04:34 +02:00
|
|
|
size_t num_txout_failures;
|
|
|
|
UINTMAP(bool) txout_failures, txout_failures_old;
|
|
|
|
struct oneshot *txout_failure_timer;
|
2019-04-08 01:51:30 +02:00
|
|
|
|
2019-09-16 12:43:51 +02:00
|
|
|
/* A map of local channels by short_channel_ids */
|
|
|
|
struct local_chan_map local_chan_map;
|
2019-04-11 07:15:22 +02:00
|
|
|
|
2019-04-08 01:51:30 +02:00
|
|
|
#if DEVELOPER
|
|
|
|
/* Override local time for gossip messages */
|
|
|
|
struct timeabs *gossip_time;
|
2019-09-18 03:05:05 +02:00
|
|
|
|
|
|
|
/* Speed up gossip. */
|
|
|
|
bool dev_fast_gossip;
|
2019-09-26 04:00:20 +02:00
|
|
|
|
|
|
|
/* Speed up pruning. */
|
|
|
|
bool dev_fast_gossip_prune;
|
2019-04-08 01:51:30 +02:00
|
|
|
#endif
|
2017-01-19 23:46:07 +01:00
|
|
|
};
|
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
static inline struct chan *
|
2018-03-01 10:22:28 +01:00
|
|
|
get_channel(const struct routing_state *rstate,
|
|
|
|
const struct short_channel_id *scid)
|
|
|
|
{
|
2018-03-04 03:26:59 +01:00
|
|
|
return uintmap_get(&rstate->chanmap, scid->u64);
|
2018-03-01 10:22:28 +01:00
|
|
|
}
|
|
|
|
|
2017-03-15 12:44:01 +01:00
|
|
|
struct route_hop {
|
2017-04-29 10:52:40 +02:00
|
|
|
struct short_channel_id channel_id;
|
2019-01-15 11:04:07 +01:00
|
|
|
int direction;
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node_id nodeid;
|
2019-02-21 03:39:21 +01:00
|
|
|
struct amount_msat amount;
|
2017-03-15 12:44:01 +01:00
|
|
|
u32 delay;
|
|
|
|
};
|
|
|
|
|
2019-08-31 14:52:35 +02:00
|
|
|
enum exclude_entry_type {
|
|
|
|
EXCLUDE_CHANNEL = 1,
|
|
|
|
EXCLUDE_NODE = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
struct exclude_entry {
|
|
|
|
enum exclude_entry_type type;
|
|
|
|
union {
|
|
|
|
struct short_channel_id_dir chan_id;
|
|
|
|
struct node_id node_id;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2017-08-28 18:03:01 +02:00
|
|
|
struct routing_state *new_routing_state(const tal_t *ctx,
|
2018-11-21 04:10:03 +01:00
|
|
|
const struct chainparams *chainparams,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *local_id,
|
2019-04-11 07:16:57 +02:00
|
|
|
struct list_head *peers,
|
2019-09-27 02:04:34 +02:00
|
|
|
struct timers *timers,
|
2019-09-18 03:05:05 +02:00
|
|
|
const u32 *dev_gossip_time TAKES,
|
2019-09-26 04:00:20 +02:00
|
|
|
bool dev_fast_gossip,
|
|
|
|
bool dev_fast_gossip_prune);
|
2017-01-19 23:46:07 +01:00
|
|
|
|
2018-08-06 19:17:56 +02:00
|
|
|
/**
|
|
|
|
* Add a new bidirectional channel from id1 to id2 with the given
|
|
|
|
* short_channel_id and capacity to the local network view. The channel may not
|
|
|
|
* already exist, and might create the node entries for the two endpoints, if
|
|
|
|
* they do not exist yet.
|
|
|
|
*/
|
2018-03-04 03:26:59 +01:00
|
|
|
struct chan *new_chan(struct routing_state *rstate,
|
|
|
|
const struct short_channel_id *scid,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *id1,
|
|
|
|
const struct node_id *id2,
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat);
|
2017-12-20 07:22:03 +01:00
|
|
|
|
2017-02-01 15:09:26 +01:00
|
|
|
/* Handlers for incoming messages */
|
2017-11-24 15:47:14 +01:00
|
|
|
|
|
|
|
/**
|
2018-01-04 12:40:58 +01:00
|
|
|
* handle_channel_announcement -- Check channel announcement is valid
|
|
|
|
*
|
2018-03-08 05:10:31 +01:00
|
|
|
* Returns error message if we should fail channel. Make *scid non-NULL
|
|
|
|
* (for checking) if we extracted a short_channel_id, otherwise ignore.
|
2018-01-04 12:40:58 +01:00
|
|
|
*/
|
2018-03-08 05:10:31 +01:00
|
|
|
u8 *handle_channel_announcement(struct routing_state *rstate,
|
|
|
|
const u8 *announce TAKES,
|
2019-09-22 04:21:19 +02:00
|
|
|
u32 current_blockheight,
|
2019-10-08 03:13:24 +02:00
|
|
|
const struct short_channel_id **scid,
|
|
|
|
struct peer *peer);
|
2018-01-04 12:40:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* handle_pending_cannouncement -- handle channel_announce once we've
|
2019-06-12 01:27:07 +02:00
|
|
|
* completed short_channel_id lookup. Returns true if handling created
|
|
|
|
* a new channel.
|
2017-11-24 15:47:14 +01:00
|
|
|
*/
|
2019-10-08 03:13:24 +02:00
|
|
|
bool handle_pending_cannouncement(struct daemon *daemon,
|
|
|
|
struct routing_state *rstate,
|
2018-01-04 12:40:58 +01:00
|
|
|
const struct short_channel_id *scid,
|
2019-02-21 04:45:55 +01:00
|
|
|
const struct amount_sat sat,
|
2018-01-04 12:40:58 +01:00
|
|
|
const u8 *txscript);
|
2018-03-08 05:10:33 +01:00
|
|
|
|
2019-04-08 06:42:43 +02:00
|
|
|
/* Iterate through channels in a node */
|
|
|
|
struct chan *first_chan(const struct node *node, struct chan_map_iter *i);
|
|
|
|
struct chan *next_chan(const struct node *node, struct chan_map_iter *i);
|
|
|
|
|
2019-06-12 01:27:07 +02:00
|
|
|
/* Returns NULL if all OK, otherwise an error for the peer which sent.
|
|
|
|
* If the error is that the channel is unknown, fills in *unknown_scid
|
|
|
|
* (if not NULL). */
|
2018-09-25 07:43:56 +02:00
|
|
|
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update TAKES,
|
2019-10-08 03:13:24 +02:00
|
|
|
struct peer *peer,
|
2019-06-12 01:27:07 +02:00
|
|
|
struct short_channel_id *unknown_scid);
|
2018-03-08 05:10:26 +01:00
|
|
|
|
|
|
|
/* Returns NULL if all OK, otherwise an error for the peer which sent. */
|
2019-10-08 03:13:24 +02:00
|
|
|
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node,
|
|
|
|
struct peer *peer);
|
2017-02-01 15:09:26 +01:00
|
|
|
|
2018-02-27 21:16:43 +01:00
|
|
|
/* Get a node: use this instead of node_map_get() */
|
2019-04-08 11:58:32 +02:00
|
|
|
struct node *get_node(struct routing_state *rstate,
|
|
|
|
const struct node_id *id);
|
2018-02-27 21:16:43 +01:00
|
|
|
|
2017-03-15 12:44:01 +01:00
|
|
|
/* Compute a route to a destination, for a given amount and riskfactor. */
|
2018-03-15 07:10:20 +01:00
|
|
|
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *source,
|
|
|
|
const struct node_id *destination,
|
2019-02-21 04:45:55 +01:00
|
|
|
const struct amount_msat msat, double riskfactor,
|
2018-02-16 04:50:51 +01:00
|
|
|
u32 final_cltv,
|
2018-02-23 01:00:00 +01:00
|
|
|
double fuzz,
|
2019-02-01 03:36:18 +01:00
|
|
|
u64 seed,
|
2019-08-31 15:57:08 +02:00
|
|
|
struct exclude_entry **excluded,
|
2019-09-24 05:33:59 +02:00
|
|
|
u32 max_hops);
|
2018-01-18 00:32:36 +01:00
|
|
|
/* Disable channel(s) based on the given routing failure. */
|
|
|
|
void routing_failure(struct routing_state *rstate,
|
2019-04-08 11:58:32 +02:00
|
|
|
const struct node_id *erring_node,
|
2018-01-18 00:32:36 +01:00
|
|
|
const struct short_channel_id *erring_channel,
|
2019-01-17 16:24:32 +01:00
|
|
|
int erring_direction,
|
2018-01-21 01:36:41 +01:00
|
|
|
enum onion_type failcode,
|
|
|
|
const u8 *channel_update);
|
2017-03-15 12:44:01 +01:00
|
|
|
|
2018-03-02 09:59:17 +01:00
|
|
|
void route_prune(struct routing_state *rstate);
|
2018-03-02 09:59:16 +01:00
|
|
|
|
2018-03-22 15:11:24 +01:00
|
|
|
/**
|
|
|
|
* Add a channel_announcement to the network view without checking it
|
|
|
|
*
|
|
|
|
* Directly add the channel to the local network, without checking it first. Use
|
|
|
|
* this only for messages from trusted sources. Untrusted sources should use the
|
|
|
|
* @see{handle_channel_announcement} entrypoint to check before adding.
|
2019-04-10 09:31:29 +02:00
|
|
|
*
|
|
|
|
* index is usually 0, in which case it's set by insert_broadcast adding it
|
|
|
|
* to the store.
|
2019-10-08 03:13:24 +02:00
|
|
|
*
|
|
|
|
* peer is an optional peer responsible for this.
|
2018-03-22 15:11:24 +01:00
|
|
|
*/
|
2018-04-11 01:03:35 +02:00
|
|
|
bool routing_add_channel_announcement(struct routing_state *rstate,
|
2019-02-21 04:45:55 +01:00
|
|
|
const u8 *msg TAKES,
|
2019-04-10 09:31:29 +02:00
|
|
|
struct amount_sat sat,
|
2019-10-08 03:13:24 +02:00
|
|
|
u32 index,
|
|
|
|
struct peer *peer);
|
2018-03-22 15:11:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a channel_update without checking for errors
|
|
|
|
*
|
|
|
|
* Used to actually insert the information in the channel update into the local
|
|
|
|
* network view. Only use this for messages that are known to be good. For
|
|
|
|
* untrusted source, requiring verification please use
|
|
|
|
* @see{handle_channel_update}
|
|
|
|
*/
|
2018-04-11 01:03:35 +02:00
|
|
|
bool routing_add_channel_update(struct routing_state *rstate,
|
2019-04-10 09:31:29 +02:00
|
|
|
const u8 *update TAKES,
|
2019-10-08 03:13:24 +02:00
|
|
|
u32 index,
|
|
|
|
struct peer *peer);
|
2018-03-22 15:11:24 +01:00
|
|
|
/**
|
|
|
|
* Add a node_announcement to the network view without checking it
|
|
|
|
*
|
|
|
|
* Directly add the node being announced to the network view, without verifying
|
|
|
|
* it. This must be from a trusted source, e.g., gossip_store. For untrusted
|
|
|
|
* sources (peers) please use @see{handle_node_announcement}.
|
|
|
|
*/
|
2018-03-29 13:29:01 +02:00
|
|
|
bool routing_add_node_announcement(struct routing_state *rstate,
|
2019-04-10 09:31:29 +02:00
|
|
|
const u8 *msg TAKES,
|
2019-10-08 03:13:24 +02:00
|
|
|
u32 index,
|
|
|
|
struct peer *peer);
|
2018-03-22 15:11:24 +01:00
|
|
|
|
2018-04-21 12:13:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a local channel.
|
|
|
|
*
|
|
|
|
* Entrypoint to add a local channel that was not learned through gossip. This
|
|
|
|
* is the case for private channels or channels that have not yet reached
|
|
|
|
* `announce_depth`.
|
|
|
|
*/
|
2019-06-03 20:07:25 +02:00
|
|
|
bool handle_local_add_channel(struct routing_state *rstate, const u8 *msg,
|
|
|
|
u64 index);
|
2018-04-21 12:13:33 +02:00
|
|
|
|
2019-04-08 01:51:30 +02:00
|
|
|
/**
|
|
|
|
* Get the local time.
|
|
|
|
*
|
|
|
|
* This gets overridden in dev mode so we can use canned (stale) gossip.
|
|
|
|
*/
|
|
|
|
struct timeabs gossip_time_now(const struct routing_state *rstate);
|
|
|
|
|
2019-09-16 12:43:51 +02:00
|
|
|
static inline struct local_chan *is_local_chan(struct routing_state *rstate,
|
|
|
|
const struct chan *chan)
|
|
|
|
{
|
|
|
|
return local_chan_map_get(&rstate->local_chan_map, &chan->scid);
|
|
|
|
}
|
|
|
|
|
2019-10-08 03:28:24 +02:00
|
|
|
/* Would we ratelimit a channel_update with this timestamp? */
|
|
|
|
bool would_ratelimit_cupdate(struct routing_state *rstate,
|
|
|
|
const struct half_chan *hc,
|
|
|
|
u32 timestamp);
|
|
|
|
|
2019-04-11 07:15:22 +02:00
|
|
|
/* Because we can have millions of channels, and we only want a local_disable
|
|
|
|
* flag on ones connected to us, we keep a separate hashtable for that flag.
|
|
|
|
*/
|
|
|
|
static inline bool is_chan_local_disabled(struct routing_state *rstate,
|
|
|
|
const struct chan *chan)
|
|
|
|
{
|
2019-09-16 12:43:51 +02:00
|
|
|
struct local_chan *local_chan = is_local_chan(rstate, chan);
|
|
|
|
return local_chan && local_chan->local_disabled;
|
2019-04-11 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void local_disable_chan(struct routing_state *rstate,
|
|
|
|
const struct chan *chan)
|
|
|
|
{
|
2019-09-16 12:43:51 +02:00
|
|
|
struct local_chan *local_chan = is_local_chan(rstate, chan);
|
|
|
|
local_chan->local_disabled = true;
|
2019-04-11 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void local_enable_chan(struct routing_state *rstate,
|
|
|
|
const struct chan *chan)
|
|
|
|
{
|
2019-09-16 12:43:51 +02:00
|
|
|
struct local_chan *local_chan = is_local_chan(rstate, chan);
|
|
|
|
local_chan->local_disabled = false;
|
2019-04-11 07:15:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 07:15:21 +02:00
|
|
|
/* Helper to convert on-wire addresses format to wireaddrs array */
|
|
|
|
struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser);
|
2019-04-17 09:35:33 +02:00
|
|
|
|
2019-06-03 20:09:25 +02:00
|
|
|
/* Remove channel from store: announcement and any updates. */
|
|
|
|
void remove_channel_from_store(struct routing_state *rstate,
|
|
|
|
struct chan *chan);
|
2019-06-03 20:22:25 +02:00
|
|
|
|
2019-06-20 04:57:52 +02:00
|
|
|
/* Returns an error string if there are unfinalized entries after load */
|
|
|
|
const char *unfinalized_entries(const tal_t *ctx, struct routing_state *rstate);
|
2019-06-14 05:30:56 +02:00
|
|
|
|
2019-06-20 04:57:52 +02:00
|
|
|
void remove_all_gossip(struct routing_state *rstate);
|
2018-03-22 11:36:25 +01:00
|
|
|
#endif /* LIGHTNING_GOSSIPD_ROUTING_H */
|