Skip to content

Commit

Permalink
channeld: add a message to read if we only want to reestablish.
Browse files Browse the repository at this point in the history
This supports reestablish on a closed channel: we tell channeld to
respond to the reestablish message appropriately, then close the
channel.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 25, 2021
1 parent 6afb9f8 commit 9929d63
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 25 deletions.
26 changes: 23 additions & 3 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,8 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
}

static void peer_reconnect(struct peer *peer,
const struct secret *last_remote_per_commit_secret)
const struct secret *last_remote_per_commit_secret,
u8 *reestablish_only)
{
struct channel_id channel_id;
/* Note: BOLT #2 uses these names! */
Expand Down Expand Up @@ -2636,6 +2637,13 @@ static void peer_reconnect(struct peer *peer,
bool soft_error = peer->funding_locked[REMOTE]
|| peer->funding_locked[LOCAL];

/* If they sent reestablish, we analyze it for courtesy, but also
* in case *they* are ahead of us! */
if (reestablish_only) {
msg = reestablish_only;
goto got_reestablish;
}

/* Read until they say something interesting (don't forward
* gossip *to* them yet: we might try sending channel_update
* before we've reestablished channel). */
Expand All @@ -2647,6 +2655,7 @@ static void peer_reconnect(struct peer *peer,
msg) ||
capture_premature_msg(&premature_msgs, msg));

got_reestablish:
#if EXPERIMENTAL_FEATURES
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif
Expand Down Expand Up @@ -2919,6 +2928,12 @@ static void peer_reconnect(struct peer *peer,

#endif /* EXPERIMENTAL_FEATURES */

/* Now stop, we've been polite long enough. */
if (reestablish_only)
peer_failed_err(peer->pps,
&peer->channel_id,
"Channel is already closed");

/* Corner case: we didn't send shutdown before because update_add_htlc
* pending, but now they're cleared by restart, and we're actually
* complete. In that case, their `shutdown` will trigger us. */
Expand Down Expand Up @@ -3409,6 +3424,7 @@ static void init_channel(struct peer *peer)
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig;
bool option_static_remotekey, option_anchor_outputs;
struct penalty_base *pbases;
u8 *reestablish_only;
#if !DEVELOPER
bool dev_fail_process_onionpacket; /* Ignored */
#endif
Expand Down Expand Up @@ -3470,7 +3486,8 @@ static void init_channel(struct peer *peer)
&option_anchor_outputs,
&dev_fast_gossip,
&dev_fail_process_onionpacket,
&pbases)) {
&pbases,
&reestablish_only)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

Expand Down Expand Up @@ -3562,7 +3579,10 @@ static void init_channel(struct peer *peer)

/* OK, now we can process peer messages. */
if (reconnected)
peer_reconnect(peer, &last_remote_per_commit_secret);
peer_reconnect(peer, &last_remote_per_commit_secret,
reestablish_only);
else
assert(!reestablish_only);

/* If we have a messages to send, send them immediately */
if (fwd_msg)
Expand Down
2 changes: 2 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ msgdata,channeld_init,dev_fast_gossip,bool,
msgdata,channeld_init,dev_fail_process_onionpacket,bool,
msgdata,channeld_init,num_penalty_bases,u32,
msgdata,channeld_init,pbases,penalty_base,num_penalty_bases
msgdata,channeld_init,reestablish_only_len,u16,
msgdata,channeld_init,reestablish_only,u8,reestablish_only_len

# master->channeld funding hit new depth(funding locked if >= lock depth)
msgtype,channeld_funding_depth,1002
Expand Down
14 changes: 11 additions & 3 deletions channeld/channeld_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions channeld/channeld_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9929d63

Please sign in to comment.