Skip to content

Commit

Permalink
channeld: handle funding_locked message before reestablish.
Browse files Browse the repository at this point in the history
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 <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and cdecker committed Feb 20, 2019
1 parent 3b68e29 commit 5f0b065
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 16 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 5f0b065

Please sign in to comment.