common: add gossmap_chan_is_dying() helper to check flags.

And fix up gossip_store backwards comment!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-02-11 21:00:41 +10:30 committed by Christian Decker
parent 27ef4b98c1
commit 5135658805
3 changed files with 19 additions and 2 deletions

View File

@ -44,8 +44,8 @@ struct gossip_rcvd_filter;
* gossip_hdr -- On-disk format header.
*/
struct gossip_hdr {
beint16_t flags; /* Length of message after header. */
beint16_t len; /* GOSSIP_STORE_xxx_BIT flags. */
beint16_t flags; /* GOSSIP_STORE_xxx_BIT flags. */
beint16_t len; /* Length of message after header. */
beint32_t crc; /* crc of message of timestamp, after header. */
beint32_t timestamp; /* timestamp of msg. */
};

View File

@ -1093,6 +1093,19 @@ bool gossmap_chan_is_localmod(const struct gossmap *map,
return c->cann_off >= map->map_size;
}
bool gossmap_chan_is_dying(const struct gossmap *map,
const struct gossmap_chan *c)
{
struct gossip_hdr ghdr;
size_t off;
/* FIXME: put this flag in plus_scid_off instead? */
off = c->cann_off - sizeof(ghdr);
map_copy(map, off, &ghdr, sizeof(ghdr));
return ghdr.flags & CPU_TO_BE16(GOSSIP_STORE_DYING_BIT);
}
bool gossmap_chan_get_capacity(const struct gossmap *map,
const struct gossmap_chan *c,
struct amount_sat *amount)

View File

@ -122,6 +122,10 @@ void gossmap_remove_localmods(struct gossmap *map,
bool gossmap_chan_is_localmod(const struct gossmap *map,
const struct gossmap_chan *c);
/* Is this channel dying? */
bool gossmap_chan_is_dying(const struct gossmap *map,
const struct gossmap_chan *c);
/* Each channel has a unique (low) index. */
u32 gossmap_node_idx(const struct gossmap *map, const struct gossmap_node *node);
u32 gossmap_chan_idx(const struct gossmap *map, const struct gossmap_chan *chan);