common/gossmap: remove now-unused private flag.

The only way you'll see private channel_updates is if you put them
there yourself with localmods.

I also renamed the confusing gossmap_chan_capacity to gossmap_chan_has_capacity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-01-31 14:48:33 +10:30
parent 5544911387
commit 37ccca5d69
6 changed files with 34 additions and 48 deletions

View file

@ -318,14 +318,9 @@ static u32 init_chan_arr(struct gossmap_chan *chan_arr, size_t start)
for (i = start; i < tal_count(chan_arr) - 1; i++) {
chan_arr[i].cann_off = i + 1;
chan_arr[i].plus_scid_off = 0;
/* We don't need to initialize this, *but* on some platforms
* (ppc, arm64) valgrind complains: this is a bitfield shared
* with plus_scid_off */
chan_arr[i].private = false;
}
chan_arr[i].cann_off = UINT_MAX;
chan_arr[i].plus_scid_off = 0;
chan_arr[i].private = false;
return start;
}
@ -350,13 +345,11 @@ static struct gossmap_chan *next_free_chan(struct gossmap *map)
static struct gossmap_chan *new_channel(struct gossmap *map,
u32 cannounce_off,
u32 plus_scid_off,
bool private,
u32 n1idx, u32 n2idx)
{
struct gossmap_chan *chan = next_free_chan(map);
chan->cann_off = cannounce_off;
chan->private = private;
chan->plus_scid_off = plus_scid_off;
chan->cupdate_off[0] = chan->cupdate_off[1] = 0;
memset(chan->half, 0, sizeof(chan->half));
@ -421,8 +414,7 @@ void gossmap_remove_node(struct gossmap *map, struct gossmap_node *node)
* * [`point`:`node_id_2`]
*/
static struct gossmap_chan *add_channel(struct gossmap *map,
size_t cannounce_off,
bool private)
size_t cannounce_off)
{
/* Note that first two bytes are message type */
const size_t feature_len_off = 2 + (64 + 64 + 64 + 64);
@ -440,12 +432,9 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
map_nodeid(map, cannounce_off + plus_scid_off + 8, &node_id[0]);
map_nodeid(map, cannounce_off + plus_scid_off + 8 + PUBKEY_CMPR_LEN, &node_id[1]);
/* We can have a channel upgrade from private->public, but
* that's the only time we get duplicates */
/* We 1should not get duplicates. */
scid.u64 = map_be64(map, cannounce_off + plus_scid_off);
chan = gossmap_find_chan(map, &scid);
if (chan)
gossmap_remove_chan(map, chan);
assert(!gossmap_find_chan(map, &scid));
/* We carefully map pointers to indexes, since new_node can move them! */
n[0] = gossmap_find_node(map, &node_id[0]);
@ -460,7 +449,7 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
else
nidx[1] = new_node(map);
chan = new_channel(map, cannounce_off, plus_scid_off, private,
chan = new_channel(map, cannounce_off, plus_scid_off,
nidx[0], nidx[1]);
/* Now we have a channel, we can add nodes to htable */
@ -635,7 +624,7 @@ static bool map_catchup(struct gossmap *map, size_t *num_rejected)
off = map->map_end + sizeof(ghdr);
type = map_be16(map, off);
if (type == WIRE_CHANNEL_ANNOUNCEMENT)
add_channel(map, off, false);
add_channel(map, off);
else if (type == WIRE_CHANNEL_UPDATE)
num_bad += !update_channel(map, off);
else if (type == WIRE_GOSSIP_STORE_DELETE_CHAN)
@ -902,8 +891,7 @@ void gossmap_apply_localmods(struct gossmap *map,
continue;
/* Create new channel, pointing into local. */
chan = add_channel(map, map->map_size + mod->local_off,
true);
chan = add_channel(map, map->map_size + mod->local_off);
}
/* Save old, overwrite (keep nodeidx) */
@ -995,6 +983,12 @@ void gossmap_node_get_id(const struct gossmap *map,
+ 8 + PUBKEY_CMPR_LEN*dir, id);
}
bool gossmap_chan_is_localmod(const struct gossmap *map,
const struct gossmap_chan *c)
{
return c->cann_off >= map->map_size;
}
bool gossmap_chan_get_capacity(const struct gossmap *map,
const struct gossmap_chan *c,
struct amount_sat *amount)
@ -1004,16 +998,9 @@ bool gossmap_chan_get_capacity(const struct gossmap *map,
u16 type;
/* Fail for local channels */
if (c->cann_off >= map->map_size)
if (gossmap_chan_is_localmod(map, c))
return false;
/* For private, we need to go back WIRE_GOSSIP_STORE_PRIVATE_CHANNEL,
* which is 8 (satoshis) + 2 (len) */
if (c->private) {
*amount = amount_sat(map_be64(map, c->cann_off - 8 - 2));
return true;
}
/* Skip over this record to next; expect a gossip_store_channel_amount */
off = c->cann_off - sizeof(ghdr);
map_copy(map, off, &ghdr, sizeof(ghdr));
@ -1113,9 +1100,9 @@ struct gossmap_chan *gossmap_next_chan(const struct gossmap *map,
return chan_iter(map, prev - map->chan_arr + 1);
}
bool gossmap_chan_capacity(const struct gossmap_chan *chan,
int direction,
struct amount_msat amount)
bool gossmap_chan_has_capacity(const struct gossmap_chan *chan,
int direction,
struct amount_msat amount)
{
if (amount_msat_less_fp16(amount, chan->half[direction].htlc_min))
return false;
@ -1133,14 +1120,10 @@ u8 *gossmap_chan_get_announce(const tal_t *ctx,
{
u16 len;
u8 *msg;
u32 pre_off;
/* We need to go back to struct gossip_hdr to get len */
if (c->private)
pre_off = 2 + 8 + 2 + sizeof(struct gossip_hdr);
else
pre_off = sizeof(struct gossip_hdr);
len = map_be16(map, c->cann_off - pre_off
if (gossmap_chan_is_localmod(map, c))
return NULL;
len = map_be16(map, c->cann_off - sizeof(struct gossip_hdr)
+ offsetof(struct gossip_hdr, len));
msg = tal_arr(ctx, u8, len);

View file

@ -18,9 +18,8 @@ struct gossmap_node {
struct gossmap_chan {
u32 cann_off;
u32 private: 1;
/* Technically redundant, but we have a hole anyway: from cann_off */
u32 plus_scid_off: 31;
u32 plus_scid_off;
/* Offsets of cupdates (0 if missing). Logically inside half_chan,
* but that would add padding. */
u32 cupdate_off[2];
@ -85,6 +84,10 @@ void gossmap_apply_localmods(struct gossmap *map,
void gossmap_remove_localmods(struct gossmap *map,
const struct gossmap_localmods *localmods);
/* Is this channel a localmod? */
bool gossmap_chan_is_localmod(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);
@ -124,7 +127,7 @@ bool gossmap_chan_get_capacity(const struct gossmap *map,
const struct gossmap_chan *c,
struct amount_sat *amount);
/* Get the announcement msg which created this chan */
/* Get the announcement msg which created this chan (NULL for localmods) */
u8 *gossmap_chan_get_announce(const tal_t *ctx,
const struct gossmap *map,
const struct gossmap_chan *c);
@ -180,9 +183,9 @@ struct gossmap_node *gossmap_nth_node(const struct gossmap *map,
int n);
/* Can this channel send this amount? */
bool gossmap_chan_capacity(const struct gossmap_chan *chan,
int direction,
struct amount_msat amount);
bool gossmap_chan_has_capacity(const struct gossmap_chan *chan,
int direction,
struct amount_msat amount);
/* Remove a channel from the map (warning! realloc can move gossmap_chan
* and gossmap_node ptrs!) */

View file

@ -15,7 +15,7 @@ bool route_can_carry_even_disabled(const struct gossmap *map,
return false;
/* Amount 0 is a special "ignore min" probe case */
if (!amount_msat_eq(amount, AMOUNT_MSAT(0))
&& !gossmap_chan_capacity(c, dir, amount))
&& !gossmap_chan_has_capacity(c, dir, amount))
return false;
return true;
}

View file

@ -332,7 +332,7 @@ int main(int argc, char *argv[])
assert(short_channel_id_from_str("110x1x0", 7, &scid12));
assert(gossmap_find_chan(map, &scid12));
assert(!gossmap_find_chan(map, &scid12)->private);
assert(!gossmap_chan_is_localmod(map, gossmap_find_chan(map, &scid12)));
assert(gossmap_chan_get_capacity(map, gossmap_find_chan(map, &scid12),
&capacity));
assert(amount_sat_eq(capacity, AMOUNT_SAT(1000000)));

View file

@ -358,9 +358,9 @@ int main(int argc, char *argv[])
assert(short_channel_id_from_str("103x1x0", 7, &scid23));
assert(short_channel_id_from_str("110x1x0", 7, &scid12));
assert(gossmap_find_chan(map, &scid23));
assert(!gossmap_find_chan(map, &scid23)->private);
assert(!gossmap_chan_is_localmod(map, gossmap_find_chan(map, &scid23)));
assert(gossmap_find_chan(map, &scid12));
assert(!gossmap_find_chan(map, &scid12)->private);
assert(!gossmap_chan_is_localmod(map, gossmap_find_chan(map, &scid12)));
assert(gossmap_chan_get_capacity(map, gossmap_find_chan(map, &scid23),
&capacity));
assert(amount_sat_eq(capacity, AMOUNT_SAT(1000000)));

View file

@ -264,7 +264,7 @@ static void json_add_halfchan(struct json_stream *response,
json_add_node_id(response, "destination", &node_id[!dir]);
json_add_short_channel_id(response, "short_channel_id", &scid);
json_add_num(response, "direction", dir);
json_add_bool(response, "public", !c->private);
json_add_bool(response, "public", !gossmap_chan_is_localmod(gossmap, c));
if (c->private) {
/* Local additions don't have a channel_update
@ -666,7 +666,7 @@ listpeerchannels_listincoming_done(struct command *cmd,
json_add_u32(js, "cltv_expiry_delta", ourchan->half[!dir].delay);
json_add_amount_msat(js, "incoming_capacity_msat",
peer_capacity(gossmap, me, peer, ourchan));
json_add_bool(js, "public", !ourchan->private);
json_add_bool(js, "public", !gossmap_chan_is_localmod(gossmap, ourchan));
peer_features = gossmap_node_get_features(tmpctx, gossmap, peer);
if (peer_features)
json_add_hex_talarr(js, "peer_features", peer_features);