diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index bcf2ef38d..d657c4e0a 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,16 @@ static inline u16 short_channel_id_outnum(const struct short_channel_id *scid) return scid->u64 & 0xFFFF; } +/* Subtly, at block N, depth is 1, hence the -1 here. eg. 103x1x0 is announceable + * when height is 108. */ +static inline bool +is_scid_depth_announceable(const struct short_channel_id *scid, + unsigned int height) +{ + return short_channel_id_blocknum(scid) + ANNOUNCE_MIN_DEPTH - 1 + <= height; +} + /* Returns false if blocknum, txnum or outnum require too many bits */ bool WARN_UNUSED_RESULT mk_short_channel_id(struct short_channel_id *scid, u64 blocknum, u64 txnum, u64 outnum); diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index ec16713cb..e3e42e19c 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -376,9 +376,9 @@ void peer_start_channeld(struct channel *channel, if (channel->scid) { scid = *channel->scid; - /* Subtle: depth=1 at funding height. */ - reached_announce_depth = get_block_height(ld->topology) + 1 >= - short_channel_id_blocknum(&scid) + ANNOUNCE_MIN_DEPTH; + reached_announce_depth + = is_scid_depth_announceable(&scid, + get_block_height(ld->topology)); log_debug(channel->log, "Already have funding locked in%s", reached_announce_depth ? " (and ready to announce)" : "");