From 5f0b065622a48d4cf6977a73c5f5d93648a04025 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 20 Feb 2019 21:46:59 +1030 Subject: [PATCH] channeld: handle funding_locked message before reestablish. LND seems to do this occasionally, though fixed in new versions. Workaround in the meantime. I tested this by hacking our code to send it prematurely, and this worked. Fixes: #2219 Signed-off-by: Rusty Russell --- CHANGELOG.md | 2 ++ channeld/channeld.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adbe72bf4..3d3402087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ changes. - You can no longer make giant unpayable "wumbo" invoices. - CLTV of total route now correctly evaluated when finding best route. - `riskfactor` arguments to `pay` and `getroute` now have an effect. +- Handle lnd sending premature 'funding_locked' message when we're expected 'reestablish'; + we used to close channel if this happened. ### Security diff --git a/channeld/channeld.c b/channeld/channeld.c index 69df8be3c..6aaf0cf68 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2087,6 +2087,7 @@ static void peer_reconnect(struct peer *peer, remote_current_per_commitment_point; struct secret last_local_per_commitment_secret; bool dataloss_protect; + const u8 *premature_funding_locked = NULL; dataloss_protect = local_feature_negotiated(peer->localfeatures, LOCAL_DATA_LOSS_PROTECT); @@ -2143,8 +2144,16 @@ static void peer_reconnect(struct peer *peer, do { clean_tmpctx(); msg = sync_crypto_read(tmpctx, &peer->cs, PEER_FD); - } while (handle_peer_gossip_or_error(PEER_FD, GOSSIP_FD, &peer->cs, - &peer->channel_id, msg)); + + /* Older LND sometimes sends funding_locked before reestablish! */ + if (fromwire_peektype(msg) == WIRE_FUNDING_LOCKED + && !premature_funding_locked) { + status_trace("Stashing early funding_locked msg!"); + premature_funding_locked = tal_steal(peer, msg); + msg = NULL; + } + } while (!msg || handle_peer_gossip_or_error(PEER_FD, GOSSIP_FD, &peer->cs, + &peer->channel_id, msg)); if (dataloss_protect) { if (!fromwire_channel_reestablish_option_data_loss_protect(msg, @@ -2342,6 +2351,11 @@ static void peer_reconnect(struct peer *peer, peer->channel->changes_pending[LOCAL] = true; peer_billboard(true, "Reconnected, and reestablished."); + + if (premature_funding_locked) { + handle_peer_funding_locked(peer, premature_funding_locked); + tal_free(premature_funding_locked); + } } /* Funding has locked in, and reached depth. */