Skip to content

Commit

Permalink
channeld: delay sending channel_announcement by 60 seconds.
Browse files Browse the repository at this point in the history
We currently send channel_announcement as soon as we and our
peer agree it's 6 blocks deep.  In theory, our other peers might
not have seen that block yet though, so delay a little.

This is mitigated by two factors:
1. lnd will stash any "not ready yet" channel_announcements anyway.
2. c-lightning doesn't enforce the 6 depth minimum at all.

We should not rely on other nodes' generosity or laxity, however!

Next release, we can start enforcing the depth limit, and maybe stashing
ones which don't quite make it (or simply enforce depth 5, not 6).

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Aug 2, 2019
1 parent 3e74ca4 commit 2b3003f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ msgdata,channel_init,upfront_shutdown_script_len,u16,
msgdata,channel_init,upfront_shutdown_script,u8,upfront_shutdown_script_len
msgdata,channel_init,remote_ann_node_sig,?secp256k1_ecdsa_signature,
msgdata,channel_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature,
msgdata,channel_init,announce_delay,u32,

# master->channeld funding hit new depth(funding locked if >= lock depth)
msgtype,channel_funding_depth,1002
Expand Down
11 changes: 9 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ struct peer {
u64 commit_timer_attempts;
u32 commit_msec;

/* How long to delay before broadcasting announcement? */
u32 announce_delay;

/* Are we expecting a pong? */
bool expecting_pong;

Expand Down Expand Up @@ -500,7 +503,10 @@ static void channel_announcement_negotiate(struct peer *peer)
&peer->announcement_node_sigs[REMOTE],
&peer->announcement_bitcoin_sigs[REMOTE])));

announce_channel(peer);
/* Give other nodes time to notice new block. */
notleak(new_reltimer(&peer->timers, peer,
time_from_sec(peer->announce_delay),
announce_channel, peer));
}
}

Expand Down Expand Up @@ -2904,7 +2910,8 @@ static void init_channel(struct peer *peer)
&peer->localfeatures,
&peer->remote_upfront_shutdown_script,
&remote_ann_node_sig,
&remote_ann_bitcoin_sig)) {
&remote_ann_bitcoin_sig,
&peer->announce_delay)) {
master_badmsg(WIRE_CHANNEL_INIT, msg);
}
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
Expand Down
5 changes: 4 additions & 1 deletion lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ void peer_start_channeld(struct channel *channel,
channel->peer->localfeatures,
channel->remote_upfront_shutdown_script,
remote_ann_node_sig,
remote_ann_bitcoin_sig);
remote_ann_bitcoin_sig,
/* Delay announce by 60 seconds after
* seeing block (adjustable if dev) */
ld->topology->poll_seconds * 2);

/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));
Expand Down

0 comments on commit 2b3003f

Please sign in to comment.