From 2b3003f25bcd97365f3e543177877a8cdb3360c6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 2 Aug 2019 13:01:00 +0930 Subject: [PATCH] channeld: delay sending channel_announcement by 60 seconds. 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 --- channeld/channel_wire.csv | 1 + channeld/channeld.c | 11 +++++++++-- lightningd/channel_control.c | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index b1f14b9a8..373f8434e 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -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 diff --git a/channeld/channeld.c b/channeld/channeld.c index e7df12412..a500aeb89 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -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; @@ -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)); } } @@ -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 */ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index f98cd3c06..aa9337ee2 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -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));