mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
gossipd: local_direction helper to generalize is_local_channel.
Increasingly we want to know is it local, and get the direction: it's more efficient to do both at once. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
70ed47d77a
commit
8e37eb0028
2 changed files with 18 additions and 10 deletions
|
@ -795,13 +795,6 @@ static void destroy_pending_cannouncement(struct pending_cannouncement *pending,
|
|||
pending_cannouncement_map_del(&rstate->pending_cannouncements, pending);
|
||||
}
|
||||
|
||||
static bool is_local_channel(const struct routing_state *rstate,
|
||||
const struct chan *chan)
|
||||
{
|
||||
return node_id_eq(&chan->nodes[0]->id, &rstate->local_id)
|
||||
|| node_id_eq(&chan->nodes[1]->id, &rstate->local_id);
|
||||
}
|
||||
|
||||
static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
||||
struct chan *chan,
|
||||
const u8 *channel_announce,
|
||||
|
@ -809,7 +802,7 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
|||
u32 index)
|
||||
{
|
||||
u8 *addendum = towire_gossip_store_channel_amount(tmpctx, chan->sat);
|
||||
bool is_local = is_local_channel(rstate, chan);
|
||||
bool is_local = local_direction(rstate, chan, NULL);
|
||||
|
||||
chan->bcast.timestamp = timestamp;
|
||||
/* 0, unless we're loading from store */
|
||||
|
@ -1381,7 +1374,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
|||
} else if (!is_chan_public(chan)) {
|
||||
/* For private channels, we get updates without an announce: don't
|
||||
* broadcast them! But save local ones to store anyway. */
|
||||
assert(is_local_channel(rstate, chan));
|
||||
assert(local_direction(rstate, chan, NULL));
|
||||
/* Don't save if we're loading from store */
|
||||
if (!index) {
|
||||
hc->bcast.index
|
||||
|
@ -1399,7 +1392,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
|||
hc->bcast.index
|
||||
= gossip_store_add(rstate->gs, update,
|
||||
hc->bcast.timestamp,
|
||||
is_local_channel(rstate, chan),
|
||||
local_direction(rstate, chan, NULL),
|
||||
NULL);
|
||||
if (hc->bcast.timestamp > rstate->last_timestamp
|
||||
&& hc->bcast.timestamp < time_now().ts.tv_sec)
|
||||
|
|
|
@ -273,6 +273,21 @@ struct routing_state {
|
|||
#endif
|
||||
};
|
||||
|
||||
/* Which direction are we? False if neither. */
|
||||
static inline bool local_direction(struct routing_state *rstate,
|
||||
const struct chan *chan,
|
||||
int *direction)
|
||||
{
|
||||
for (int dir = 0; dir <= 1; (dir)++) {
|
||||
if (node_id_eq(&chan->nodes[dir]->id, &rstate->local_id)) {
|
||||
if (direction)
|
||||
*direction = dir;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline struct chan *
|
||||
get_channel(const struct routing_state *rstate,
|
||||
const struct short_channel_id *scid)
|
||||
|
|
Loading…
Add table
Reference in a new issue