gossmap: fail to get capacity of locally-added chans (don't crash!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-09-18 09:51:50 +09:30
parent 2da5244e83
commit 6a48ed9e82
2 changed files with 5 additions and 1 deletions

View file

@ -967,6 +967,10 @@ bool gossmap_chan_get_capacity(const struct gossmap *map,
size_t off;
u16 type;
/* Fail for local channels */
if (c->cann_off >= map->map_size)
return false;
/* For private, we need to go back WIRE_GOSSIP_STORE_PRIVATE_CHANNEL,
* which is 8 (satoshis) + 2 (len) */
if (c->private) {

View file

@ -117,7 +117,7 @@ static inline bool gossmap_chan_set(const struct gossmap_chan *chan, int dir)
return chan->cupdate_off[dir] != 0;
}
/* Return capacity if it's known (fails only on race condition) */
/* Return capacity if it's known (fails only on race condition, or a local mod) */
bool gossmap_chan_get_capacity(const struct gossmap *map,
const struct gossmap_chan *c,
struct amount_sat *amount);