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:
Rusty Russell
2021-12-29 13:56:43 +10:30
parent 70ed47d77a
commit 8e37eb0028
2 changed files with 18 additions and 10 deletions

View File

@@ -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)