From ec1b86d9d5d30178a37ff8ccdfa158541f363fff Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Thu, 30 Jan 2020 15:01:27 -0800 Subject: [PATCH] channel: make error 'hard' if awaiting lockin if the channel hasn't been locked in yet, allow for a 'hard' error to kill the channel --- channeld/channeld.c | 11 +++++++++-- tests/test_connection.py | 3 --- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 31037d798..efe9f7319 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1846,6 +1846,11 @@ static void peer_in(struct peer *peer, const u8 *msg) { enum wire_type type = fromwire_peektype(msg); + /* Only count soft errors if the channel has locked-in already; + * otherwise we can't cancel a channel before it has opened. + */ + bool soft_error = peer->funding_locked[REMOTE] || peer->funding_locked[LOCAL]; + peer->last_recv = time_now(); /* Catch our own ping replies. */ @@ -1859,7 +1864,7 @@ static void peer_in(struct peer *peer, const u8 *msg) /* Since LND seems to send errors which aren't actually fatal events, * we treat errors here as soft. */ - if (handle_peer_gossip_or_error(peer->pps, &peer->channel_id, true, msg)) + if (handle_peer_gossip_or_error(peer->pps, &peer->channel_id, soft_error, msg)) return; /* Must get funding_locked before almost anything. */ @@ -2350,6 +2355,8 @@ static void peer_reconnect(struct peer *peer, sync_crypto_write(peer->pps, take(msg)); peer_billboard(false, "Sent reestablish, waiting for theirs"); + bool soft_error = peer->funding_locked[REMOTE] + || peer->funding_locked[LOCAL]; /* Read until they say something interesting (don't forward * gossip *to* them yet: we might try sending channel_update @@ -2358,7 +2365,7 @@ static void peer_reconnect(struct peer *peer, clean_tmpctx(); msg = sync_crypto_read(tmpctx, peer->pps); } while (channeld_handle_custommsg(msg) || - handle_peer_gossip_or_error(peer->pps, &peer->channel_id, true, + handle_peer_gossip_or_error(peer->pps, &peer->channel_id, soft_error, msg) || capture_premature_msg(&premature_msgs, msg)); diff --git a/tests/test_connection.py b/tests/test_connection.py index 02bdbcbfc..5f886c58c 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1038,9 +1038,6 @@ def test_funding_external_wallet_corners(node_factory, bitcoind): # We can cancel channel after fundchannel_complete assert l1.rpc.fundchannel_cancel(l2.info['id'])['cancelled'] - # l2 won't give up, since it considers error "soft". - l2.rpc.dev_forget_channel(l1.info['id']) - l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.rpc.fundchannel_start(l2.info['id'], amount)['funding_address'] assert l1.rpc.fundchannel_complete(l2.info['id'], prep['txid'], txout)['commitments_secured']