From 7e4b204c1edc41f35aefab6f98a7995afc7efdd9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 18 Aug 2020 12:00:03 +0930 Subject: [PATCH] fundpsbt: let caller specify locktime. Required for dual funding where the opener sets it. Changelog-Added: JSON-RPC: fundpsbt takes a new `locktime` parameter Signed-off-by: Rusty Russell --- contrib/pyln-client/pyln/client/lightning.py | 3 ++- doc/lightning-fundpsbt.7 | 6 +++++- doc/lightning-fundpsbt.7.md | 5 ++++- wallet/reservation.c | 16 ++++++++++------ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py index 23c7583c457e..208a0fb2770b 100644 --- a/contrib/pyln-client/pyln/client/lightning.py +++ b/contrib/pyln-client/pyln/client/lightning.py @@ -1126,7 +1126,7 @@ def unreserveinputs(self, psbt): } return self.call("unreserveinputs", payload) - def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True): + def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True, locktime=None): """ Create a PSBT with inputs sufficient to give an output of satoshi. """ @@ -1136,6 +1136,7 @@ def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True): "startweight": startweight, "minconf": minconf, "reserve": reserve, + "locktime": locktime, } return self.call("fundpsbt", payload) diff --git a/doc/lightning-fundpsbt.7 b/doc/lightning-fundpsbt.7 index 140925c9c2dd..2665a8a46b1d 100644 --- a/doc/lightning-fundpsbt.7 +++ b/doc/lightning-fundpsbt.7 @@ -3,7 +3,7 @@ lightning-fundpsbt - Command to populate PSBT inputs from the wallet .SH SYNOPSIS -\fBfundpsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR [\fIminconf\fR] [\fIreserve\fR] +\fBfundpsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR [\fIminconf\fR] [\fIreserve\fR] [\fIlocktime\fR] .SH DESCRIPTION @@ -39,6 +39,10 @@ outputs should have\. Default is 1\. \fIreserve\fR is a boolean: if true (the default), then \fIreserveinputs\fR is called (successfully, with \fIexclusive\fR true) on the returned PSBT\. + +\fIlocktime\fR is an optional locktime: if not set, it is set to a recent +block height\. + .SH EXAMPLE USAGE Let's assume the caller is trying to produce a 100,000 satoshi output\. diff --git a/doc/lightning-fundpsbt.7.md b/doc/lightning-fundpsbt.7.md index 3332dcd68cb1..b1f0edab14cf 100644 --- a/doc/lightning-fundpsbt.7.md +++ b/doc/lightning-fundpsbt.7.md @@ -4,7 +4,7 @@ lightning-fundpsbt -- Command to populate PSBT inputs from the wallet SYNOPSIS -------- -**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] +**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] \[*locktime*\] DESCRIPTION ----------- @@ -36,6 +36,9 @@ outputs should have. Default is 1. *reserve* is a boolean: if true (the default), then *reserveinputs* is called (successfully, with *exclusive* true) on the returned PSBT. +*locktime* is an optional locktime: if not set, it is set to a recent +block height. + EXAMPLE USAGE ------------- diff --git a/wallet/reservation.c b/wallet/reservation.c index 2bcef05c0550..2988eaf6ed0c 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -219,7 +219,7 @@ static struct command_result *json_fundpsbt(struct command *cmd, u32 *minconf, *weight; struct amount_sat *amount, input, diff; bool all, *reserve; - u32 locktime, maxheight, current_height; + u32 *locktime, maxheight, current_height; struct bitcoin_tx *tx; if (!param(cmd, buffer, params, @@ -228,6 +228,7 @@ static struct command_result *json_fundpsbt(struct command *cmd, p_req("startweight", param_number, &weight), p_opt_def("minconf", param_number, &minconf, 1), p_opt_def("reserve", param_bool, &reserve, true), + p_opt("locktime", param_u32, &locktime), NULL)) return command_param_failed(); @@ -303,18 +304,21 @@ static struct command_result *json_fundpsbt(struct command *cmd, * 0xFFFFFFFD by default. Other wallets are likely to implement * this too). */ - locktime = current_height; + if (!locktime) { + locktime = tal(cmd, u32); + *locktime = current_height; - /* Eventually fuzz it too. */ - if (locktime > 100 && pseudorand(10) == 0) - locktime -= pseudorand(100); + /* Eventually fuzz it too. */ + if (*locktime > 100 && pseudorand(10) == 0) + *locktime -= pseudorand(100); + } /* FIXME: tx_spending_utxos does more than we need, but there * are other users right now. */ tx = tx_spending_utxos(cmd, chainparams, cast_const2(const struct utxo **, utxos), cmd->ld->wallet->bip32_base, - false, 0, locktime, + false, 0, *locktime, BITCOIN_TX_RBF_SEQUENCE); response = json_stream_success(cmd);