Browse Source

fundpsbt/utxopsbt: new `min_witness_weight` param

Needed for v2 of channel opens, where the minimum weight is 110; a
'simple utxo' (sig + key) weighs in at 107, so we a need a way to
establish a floor for this case.

Changelog-Added: JSON-RPC: fundpsbt/utxopsbt have new param, `min_witness_utxo`, which sets a floor for the weight calculation of an added input
fix-mocks
niftynei 4 years ago
committed by Rusty Russell
parent
commit
e81d78ec4c
  1. 11
      common/utxo.c
  2. 2
      common/utxo.h
  3. 9
      doc/lightning-fundpsbt.7
  4. 6
      doc/lightning-fundpsbt.7.md
  5. 9
      doc/lightning-utxopsbt.7
  6. 6
      doc/lightning-utxopsbt.7.md
  7. 14
      wallet/reservation.c

11
common/utxo.c

@ -64,7 +64,14 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
return utxo;
}
size_t utxo_spend_weight(const struct utxo *utxo)
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
{
return bitcoin_tx_simple_input_weight(utxo->is_p2sh);
size_t wit_weight = bitcoin_tx_simple_input_witness_weight();
/* If the min is less than what we'd use for a 'normal' tx,
* we return the value with the greater added/calculated */
if (wit_weight < min_witness_weight)
return bitcoin_tx_input_weight(utxo->is_p2sh,
min_witness_weight);
return bitcoin_tx_input_weight(utxo->is_p2sh, wit_weight);
}

2
common/utxo.h

@ -74,5 +74,5 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo);
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max);
/* Estimate of (signed) UTXO weight in transaction */
size_t utxo_spend_weight(const struct utxo *utxo);
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight);
#endif /* LIGHTNING_COMMON_UTXO_H */

9
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] [\fIlocktime\fR]
\fBfundpsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR [\fIminconf\fR] [\fIreserve\fR] [\fIlocktime\fR] [\fImin_witness_weight\fR]
.SH DESCRIPTION
@ -43,6 +43,11 @@ 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\.
\fImin_witness_weight\fR is an optional minimum weight to use for a UTXO's
witness\. If the actual witness weight is greater than the provided minimum,
the actual witness weight will be used\.
.SH EXAMPLE USAGE
Let's assume the caller is trying to produce a 100,000 satoshi output\.
@ -104,4 +109,4 @@ Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:8eb6970e2d625198db9b8e5ab7f90f9fb141744a837f58ee68ef54d28c7066b0
\" SHA256STAMP:a8b9705274638127c2f5ec4e97ed94e6d7f6b6b10a76c2248e8bc8b36dd804ff

6
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*\] \[*locktime*\]
**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] \[*locktime*\] \[*min_witness_weight*\]
DESCRIPTION
-----------
@ -39,6 +39,10 @@ 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.
*min_witness_weight* is an optional minimum weight to use for a UTXO's
witness. If the actual witness weight is greater than the provided minimum,
the actual witness weight will be used.
EXAMPLE USAGE
-------------

9
doc/lightning-utxopsbt.7

@ -3,7 +3,7 @@
lightning-utxopsbt - Command to populate PSBT inputs from given UTXOs
.SH SYNOPSIS
\fButxopsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR \fIutxos\fR [\fIreserve\fR] [\fIreservedok\fR] [\fIlocktime\fR]
\fButxopsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR \fIutxos\fR [\fIreserve\fR] [\fIreservedok\fR] [\fIlocktime\fR] [\fImin_witness_weight\fR]
.SH DESCRIPTION
@ -31,6 +31,11 @@ if any of the \fIutxos\fR are already reserved\.
\fIlocktime\fR is an optional locktime: if not set, it is set to a recent
block height\.
\fImin_witness_weight\fR is an optional minimum weight to use for a UTXO's
witness\. If the actual witness weight is greater than the provided minimum,
the actual witness weight will be used\.
.SH RETURN VALUE
On success, returns the \fIpsbt\fR containing the inputs, \fIfeerate_per_kw\fR
@ -70,4 +75,4 @@ Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:e47331be08a0911c74e142f2255bf62a83b70b818c1cf39a9314aab8c17a6e47
\" SHA256STAMP:777710bb963f435193e92a55344c740c123d7aa4d54bf573c99a616f59eeee54

6
doc/lightning-utxopsbt.7.md

@ -4,7 +4,7 @@ lightning-utxopsbt -- Command to populate PSBT inputs from given UTXOs
SYNOPSIS
--------
**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] \[*reservedok*\] \[*locktime*\]
**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] \[*reservedok*\] \[*locktime*\] \[*min_witness_weight*\]
DESCRIPTION
-----------
@ -29,6 +29,10 @@ if any of the *utxos* are already reserved.
*locktime* is an optional locktime: if not set, it is set to a recent
block height.
*min_witness_weight* is an optional minimum weight to use for a UTXO's
witness. If the actual witness weight is greater than the provided minimum,
the actual witness weight will be used.
RETURN VALUE
------------

14
wallet/reservation.c

@ -386,7 +386,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
{
struct utxo **utxos;
u32 *feerate_per_kw;
u32 *minconf, *weight;
u32 *minconf, *weight, *min_witness_weight;
struct amount_sat *amount, input, diff;
bool all, *reserve;
u32 *locktime, maxheight;
@ -398,6 +398,8 @@ static struct command_result *json_fundpsbt(struct command *cmd,
p_opt_def("minconf", param_number, &minconf, 1),
p_opt_def("reserve", param_bool, &reserve, true),
p_opt("locktime", param_number, &locktime),
p_opt_def("min_witness_weight", param_number,
&min_witness_weight, 0),
NULL))
return command_param_failed();
@ -427,7 +429,9 @@ static struct command_result *json_fundpsbt(struct command *cmd,
"impossible UTXO value");
/* But also adds weight */
*weight += utxo_spend_weight(utxo);
fprintf(stderr, "min_witness_weight is %u\n",
*min_witness_weight);
*weight += utxo_spend_weight(utxo, *min_witness_weight);
continue;
}
@ -555,7 +559,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
const jsmntok_t *params)
{
struct utxo **utxos;
u32 *feerate_per_kw, *weight;
u32 *feerate_per_kw, *weight, *min_witness_weight;
bool all, *reserve, *reserved_ok;
struct amount_sat *amount, input, excess;
u32 current_height, *locktime;
@ -568,6 +572,8 @@ static struct command_result *json_utxopsbt(struct command *cmd,
p_opt_def("reserve", param_bool, &reserve, true),
p_opt_def("reservedok", param_bool, &reserved_ok, false),
p_opt("locktime", param_number, &locktime),
p_opt_def("min_witness_weight", param_number,
&min_witness_weight, 0),
NULL))
return command_param_failed();
@ -592,7 +598,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
"impossible UTXO value");
/* But also adds weight */
*weight += utxo_spend_weight(utxo);
*weight += utxo_spend_weight(utxo, *min_witness_weight);
}
/* For all, anything above 0 is "excess" */

Loading…
Cancel
Save