mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
bitcoin: implement is_scid_depth_announceable helper.
The math is a bit tricky, so encapsulate it. Includes the extra 'e' in 'announcable' as noted by @cdecker :) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2a74d53841
commit
45381bba33
@ -4,6 +4,7 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <common/gossip_constants.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@ -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);
|
||||
|
@ -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)" : "");
|
||||
|
Loading…
Reference in New Issue
Block a user