diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index e407e107c..74bf55938 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -693,7 +693,7 @@ class LightningRpc(UnixDomainSocketRpc): } return self.call("feerates", payload) - def fundchannel(self, node_id, amount, feerate=None, announce=True, minconf=None, utxos=None, push_msat=None, close_to=None): + def fundchannel(self, node_id, amount, feerate=None, announce=True, minconf=None, utxos=None, push_msat=None, close_to=None, request_amt=None): """ Fund channel with {id} using {amount} satoshis with feerate of {feerate} (uses default feerate if unset). @@ -702,6 +702,10 @@ class LightningRpc(UnixDomainSocketRpc): If {utxos} is specified (as a list of 'txid:vout' strings), fund a channel from these specifics utxos. {close_to} is a valid Bitcoin address. + + {request_amt} is the lease amount to request from the peer. Only + valid if peer is advertising a liquidity ad + supports v2 channel opens + (dual-funding) """ payload = { "id": node_id, @@ -712,6 +716,7 @@ class LightningRpc(UnixDomainSocketRpc): "utxos": utxos, "push_msat": push_msat, "close_to": close_to, + "request_amt": request_amt, } return self.call("fundchannel", payload) diff --git a/doc/lightning-fundchannel.7 b/doc/lightning-fundchannel.7 index 51dc7de65..3180e88b8 100644 --- a/doc/lightning-fundchannel.7 +++ b/doc/lightning-fundchannel.7 @@ -72,6 +72,11 @@ on close\. Only valid if both peers have negotiated \fBoption_upfront_shutdown_s Returns \fBclose_to\fR set to closing script iff is negotiated\. +\fIrequest_amt\fR is an amount of liquidity you'd like to lease from the peer\. +If peer supports \fBoption_will_fund\fR, indicates to them to include this +much liquidity into the channel\. + + This example shows how to use lightning-cli to open new channel with peer 03f\.\.\.fc1 from one whole utxo bcc1\.\.\.39c:0 (you can use \fBlistfunds\fR command to get txid and vout): @@ -80,7 +85,6 @@ This example shows how to use lightning-cli to open new channel with peer 03f\.\ lightning-cli -k fundchannel id=03f...fc1 amount=all feerate=normal utxos='["bcc1...39c:0"]' - .RE .fi @@ -130,4 +134,4 @@ channel parameters (funding limits, channel reserves, fees, etc\.)\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:d25fc36b745b6f58556f7f4b06f23ff83b466d4a00911f7ffdc9d86572902954 +\" SHA256STAMP:c7cd9291a08e66e41b24d0045c313ac1e3dabcb4579ab5fe132aad8d1ecbb640 diff --git a/doc/lightning-fundchannel.7.md b/doc/lightning-fundchannel.7.md index 770efa4ea..125fc9204 100644 --- a/doc/lightning-fundchannel.7.md +++ b/doc/lightning-fundchannel.7.md @@ -64,12 +64,16 @@ unrecoverable once pushed. on close. Only valid if both peers have negotiated `option_upfront_shutdown_script`. Returns `close_to` set to closing script iff is negotiated. +*request_amt* is an amount of liquidity you'd like to lease from the peer. +If peer supports `option_will_fund`, indicates to them to include this +much liquidity into the channel. + + This example shows how to use lightning-cli to open new channel with peer 03f...fc1 from one whole utxo bcc1...39c:0 (you can use **listfunds** command to get txid and vout): lightning-cli -k fundchannel id=03f...fc1 amount=all feerate=normal utxos='["bcc1...39c:0"]' - RETURN VALUE ------------ diff --git a/doc/lightning-multifundchannel.7 b/doc/lightning-multifundchannel.7 index 7c1e7e23f..c86e9ea55 100644 --- a/doc/lightning-multifundchannel.7 +++ b/doc/lightning-multifundchannel.7 @@ -58,6 +58,10 @@ out of this\. on close\. Only valid if both peers have negotiated \fBoption_upfront_shutdown_script\fR\. Returns \fBclose_to\fR set to closing script iff is negotiated\. +.IP \[bu] +\fIrequest_amt\fR is the amount of liquidity you'd like to lease from peer\. +If peer supports \fBoption_will_fund\fR, indicates to them to include this +much liquidity into the channel\. .RE @@ -204,4 +208,4 @@ ZmnSCPxj \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:86b05635f6d0d55dc3771779237bf1046b52f8cd290f16cccc5656cb94f2863a +\" SHA256STAMP:fa55ac01a568d6b816641ddbfa3c9cccf437dea06df5ec84747f7ef02db6d47e diff --git a/doc/lightning-multifundchannel.7.md b/doc/lightning-multifundchannel.7.md index 4f6c43b1e..a0472f9d4 100644 --- a/doc/lightning-multifundchannel.7.md +++ b/doc/lightning-multifundchannel.7.md @@ -51,6 +51,9 @@ Readiness is indicated by **listpeers** reporting a *state* of on close. Only valid if both peers have negotiated `option_upfront_shutdown_script`. Returns `close_to` set to closing script iff is negotiated. +* *request_amt* is the amount of liquidity you'd like to lease from peer. +If peer supports `option_will_fund`, indicates to them to include this +much liquidity into the channel. There must be at least one entry in *destinations*; it cannot be an empty array. diff --git a/plugins/spender/fundchannel.c b/plugins/spender/fundchannel.c index 39cdae088..e4b75756d 100644 --- a/plugins/spender/fundchannel.c +++ b/plugins/spender/fundchannel.c @@ -42,6 +42,7 @@ json_fundchannel(struct command *cmd, const jsmntok_t *utxos; const jsmntok_t *push_msat; const jsmntok_t *close_to; + const jsmntok_t *request_amt; struct out_req *req; @@ -54,6 +55,7 @@ json_fundchannel(struct command *cmd, p_opt("utxos", param_tok, &utxos), p_opt("push_msat", param_tok, &push_msat), p_opt("close_to", param_tok, &close_to), + p_opt("request_amt", param_tok, &request_amt), NULL)) return command_param_failed(); @@ -71,6 +73,8 @@ json_fundchannel(struct command *cmd, json_add_tok(req->js, "push_msat", push_msat, buf); if (close_to) json_add_tok(req->js, "close_to", close_to, buf); + if (request_amt) + json_add_tok(req->js, "request_amt", request_amt, buf); json_object_end(req->js); json_array_end(req->js); if (feerate) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 72fbe4e8c..6df6931b6 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -1813,7 +1813,7 @@ param_destinations_array(struct command *cmd, const char *name, struct multifundchannel_destination *dest; const char *id; char *addrhint; - struct amount_sat *amount; + struct amount_sat *amount, *request_amt; bool *announce; struct amount_msat *push_msat; @@ -1830,6 +1830,8 @@ param_destinations_array(struct command *cmd, const char *name, * passed in to fundchannel_start) if invalid*/ p_opt("close_to", param_string, &dest->close_to_str), + p_opt_def("request_amt", param_sat, &request_amt, + AMOUNT_SAT(0)), NULL)) return command_param_failed(); @@ -1864,6 +1866,7 @@ param_destinations_array(struct command *cmd, const char *name, dest->psbt = NULL; dest->updated_psbt = NULL; dest->protocol = FUND_CHANNEL; + dest->request_amt = *request_amt; /* Only one destination can have "all" indicator. */ if (dest->all) { diff --git a/plugins/spender/multifundchannel.h b/plugins/spender/multifundchannel.h index 1519ccfa1..0a1614ce4 100644 --- a/plugins/spender/multifundchannel.h +++ b/plugins/spender/multifundchannel.h @@ -143,6 +143,9 @@ struct multifundchannel_destination { /* serial of the funding output for this channel (OPEN_CHANNEL) */ u64 funding_serial; + + /* amount to request peer to lease (OPEN_CHANNEL) */ + struct amount_sat request_amt; }; diff --git a/plugins/spender/openchannel.c b/plugins/spender/openchannel.c index 43deb9bee..9f274aad7 100644 --- a/plugins/spender/openchannel.c +++ b/plugins/spender/openchannel.c @@ -1025,6 +1025,11 @@ openchannel_init_dest(struct multifundchannel_destination *dest) type_to_string(tmpctx, struct amount_msat, &dest->push_msat)); + /* Request some sats from the peer! */ + if (amount_sat_greater(dest->request_amt, AMOUNT_SAT(0))) + json_add_string(req->js, "request_amt", + fmt_amount_sat(tmpctx, dest->request_amt)); + return send_outreq(cmd->plugin, req); }