gossmap: function to get channel features bitmap.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-05-22 14:30:22 +09:30
parent 770a328d56
commit d54abd0e36
3 changed files with 26 additions and 0 deletions

View File

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

View File

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

View File

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