liquidity-ad: pipe request_amt all the way out to fundchannel

Changelog-Added: JSON-RPC: `fundchannel` now takes optional `request_amt` parameter
This commit is contained in:
niftynei 2021-06-08 16:55:06 -05:00 committed by neil saitug
parent e41d2dc0e6
commit 9ad40f2544
9 changed files with 41 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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
------------

View File

@ -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<ZmnSCPxj@protonmail.com\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:86b05635f6d0d55dc3771779237bf1046b52f8cd290f16cccc5656cb94f2863a
\" SHA256STAMP:fa55ac01a568d6b816641ddbfa3c9cccf437dea06df5ec84747f7ef02db6d47e

View File

@ -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.

View File

@ -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)

View File

@ -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) {

View File

@ -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;
};

View File

@ -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);
}