Skip to content

Commit

Permalink
topology: don't call gossmap for locall added channels.
Browse files Browse the repository at this point in the history
This happens in deprecated mode, and we get bogus results.  Valgrind caught it!

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jan 31, 2024
1 parent 8281943 commit 8454e49
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
const size_t htlc_maximum_off = fee_prop_off + 4;

assert(gossmap_chan_set(chan, dir));
/* Not allowed on local updates! */
assert(chan->cann_off < map->map_size);

if (timestamp)
*timestamp = map_be32(map, timestamp_off);
Expand Down
2 changes: 1 addition & 1 deletion common/gossmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ u8 *gossmap_node_get_features(const tal_t *ctx,
const struct gossmap_node *n);

/* Returns details from channel_update (must be gossmap_chan_set, and
* does not work for local_updatechan! */
* does not work for local_updatechan)! */
void gossmap_chan_get_update_details(const struct gossmap *map,
const struct gossmap_chan *chan,
int dir,
Expand Down
29 changes: 21 additions & 8 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,27 @@ static void json_add_halfchan(struct json_stream *response,
json_add_num(response, "direction", dir);
json_add_bool(response, "public", !c->private);

gossmap_chan_get_update_details(gossmap, c, dir,
&timestamp,
&message_flags,
&channel_flags,
&fee_base_msat,
&fee_proportional_millionths,
&htlc_minimum_msat,
&htlc_maximum_msat);
if (c->private) {
/* Local additions don't have a channel_update
* in gossmap. This is deprecated anyway, but
* fill in values from entry we added. */
timestamp = time_now().ts.tv_sec;
message_flags = (ROUTING_OPT_HTLC_MAX_MSAT|ROUTING_OPT_DONT_FORWARD);
channel_flags = node_id_idx(&node_id[dir], &node_id[!dir]);
fee_base_msat = c->half[dir].base_fee;
fee_proportional_millionths = c->half[dir].proportional_fee;
htlc_minimum_msat = amount_msat(fp16_to_u64(c->half[dir].htlc_min));
htlc_maximum_msat = amount_msat(fp16_to_u64(c->half[dir].htlc_max));
} else {
gossmap_chan_get_update_details(gossmap, c, dir,
&timestamp,
&message_flags,
&channel_flags,
&fee_base_msat,
&fee_proportional_millionths,
&htlc_minimum_msat,
&htlc_maximum_msat);
}

json_add_amount_sat_msat(response, "amount_msat", capacity);
json_add_num(response, "message_flags", message_flags);
Expand Down

0 comments on commit 8454e49

Please sign in to comment.