From 6077eca660132b8747c229c705ffa0e7ce5ff0f7 Mon Sep 17 00:00:00 2001 From: niftynei Date: Mon, 26 Oct 2020 14:40:00 -0500 Subject: [PATCH] df: pass back 'close_to' for completed/commitment secured channels When commitments are secured, also return the 'close_to' script if we've got a local_upfront_shutdown_script set. --- doc/lightning-openchannel_update.7 | 16 +++++++++++++++- doc/lightning-openchannel_update.7.md | 8 ++++++++ lightningd/dual_open_control.c | 3 +++ plugins/spender/openchannel.c | 10 +++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/doc/lightning-openchannel_update.7 b/doc/lightning-openchannel_update.7 index 42677e026..39f22ed25 100644 --- a/doc/lightning-openchannel_update.7 +++ b/doc/lightning-openchannel_update.7 @@ -35,6 +35,20 @@ complete \fIpsbt\fR for this channel's funding transaction; and the flag If \fIcommitments_secured\fR is true, caller should proceed with signing the returned PSBT and calling \fBopenchannel_signed\fR to complete the channel open\. + +If \fIcommitments_secured\fR is true, will also return: + +.RS +.IP \[bu] +The derived \fIchannel_id\fR\. +.IP \[bu] +A \fIclose_to\fR script, iff a \fBclose_to\fR address was provided to +\fBopenchannel_init\fR and the peer supports \fBoption_upfront_shutdownscript\fR\. +.IP \[bu] +The \fIfunding_outnum\fR, the index of the funding output for this channel +in the funding transaction\. + +.RE .RS .IP \[bu] -32602: If the given parameters are wrong\. @@ -63,4 +77,4 @@ lightning-fundchannel_\fBstart\fR(7), lightning-fundchannel_\fBcomplete\fR(7), Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:ab3d19be91c8b2e651a6f4a23552f21323c4f0096ceda8026bb2450c2f9c616c +\" SHA256STAMP:de370bb6e61a0390a50a85e97f533238f379c908cddd822436d0ac4c72b43d6e diff --git a/doc/lightning-openchannel_update.7.md b/doc/lightning-openchannel_update.7.md index 9a8e8475e..2977943e1 100644 --- a/doc/lightning-openchannel_update.7.md +++ b/doc/lightning-openchannel_update.7.md @@ -34,6 +34,14 @@ complete *psbt* for this channel's funding transaction; and the flag If *commitments_secured* is true, caller should proceed with signing the returned PSBT and calling `openchannel_signed` to complete the channel open. +If *commitments_secured* is true, will also return: +- The derived *channel_id*. +- A *close_to* script, iff a `close_to` address was provided to + `openchannel_init` and the peer supports `option_upfront_shutdownscript`. +- The *funding_outnum*, the index of the funding output for this channel + in the funding transaction. + + - -32602: If the given parameters are wrong. - -1: Catchall nonspecific error. - 305: Peer is not connected. diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index f304f0257..a584196b7 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -933,6 +933,9 @@ static void opener_commit_received(struct subd *dualopend, json_add_bool(response, "commitments_secured", true); /* For convenience sake, we include the funding outnum */ json_add_num(response, "funding_outnum", funding_outnum); + if (local_upfront_shutdown_script) + json_add_hex_talarr(response, "close_to", + local_upfront_shutdown_script); /* Now that we've got the final PSBT, save it */ channel->psbt = tal_steal(channel, psbt); wallet_channel_save(uc->fc->cmd->ld->wallet, channel); diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 1cebc0d35..84b5334f3 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -715,7 +715,7 @@ openchannel_update_ok(struct command *cmd, json_tok_full(buf, result)); if (done) { - const jsmntok_t *outnum_tok; + const jsmntok_t *outnum_tok, *close_to_tok; outnum_tok = json_get_member(buf, result, "funding_outnum"); if (!outnum_tok) @@ -732,6 +732,14 @@ openchannel_update_ok(struct command *cmd, json_tok_full_len(result), json_tok_full(buf, result)); + close_to_tok = json_get_member(buf, result, "close_to"); + if (close_to_tok) + dest->close_to_script = + json_tok_bin_from_hex(dest->mfc, buf, + close_to_tok); + else + dest->close_to_script = NULL; + /* It's possible they beat us to the SIGNED flag, * in which case we just let that be the more senior * state position */