diff --git a/common/gossmap.c b/common/gossmap.c index 24d1e20a0..7b3ac6416 100644 --- a/common/gossmap.c +++ b/common/gossmap.c @@ -1140,6 +1140,22 @@ int gossmap_chan_get_feature(const struct gossmap *map, c->cann_off + feature_len_off + 2, feature_len); } +u8 *gossmap_chan_get_features(const tal_t *ctx, + const struct gossmap *map, + const struct gossmap_chan *c) +{ + u8 *ret; + /* Note that first two bytes are message type */ + const size_t feature_len_off = 2 + (64 + 64 + 64 + 64); + size_t feature_len; + + feature_len = map_be16(map, c->cann_off + feature_len_off); + ret = tal_arr(ctx, u8, feature_len); + + map_copy(map, c->cann_off + feature_len_off + 2, ret, feature_len); + return ret; +} + /* BOLT #7: * 1. type: 258 (`channel_update`) * 2. data: diff --git a/common/gossmap.h b/common/gossmap.h index 17500913b..a75e20a14 100644 --- a/common/gossmap.h +++ b/common/gossmap.h @@ -134,6 +134,11 @@ int gossmap_chan_get_feature(const struct gossmap *map, const struct gossmap_chan *c, int fbit); +/* Return the feature bitmap */ +u8 *gossmap_chan_get_features(const tal_t *ctx, + const struct gossmap *map, + const struct gossmap_chan *c); + /* Return the feature bit (odd or even), or -1 if neither (or no announcement) */ int gossmap_node_get_feature(const struct gossmap *map, const struct gossmap_node *n, diff --git a/common/test/run-gossmap_local.c b/common/test/run-gossmap_local.c index 8a4861b23..11499bbc7 100644 --- a/common/test/run-gossmap_local.c +++ b/common/test/run-gossmap_local.c @@ -402,6 +402,11 @@ int main(int argc, char *argv[]) assert(amount_msat_eq(htlc_minimum_msat, AMOUNT_MSAT(0))); assert(amount_msat_eq(htlc_maximum_msat, AMOUNT_MSAT(990000000))); + assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map, + gossmap_find_chan(map, &scid12))) == 0); + assert(tal_bytelen(gossmap_chan_get_features(tmpctx, map, + gossmap_find_chan(map, &scid23))) == 0); + /* Now, let's add a new channel l1 -> l4. */ mods = gossmap_localmods_new(tmpctx); assert(node_id_from_hexstr("0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199", 66, &l4));