mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
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
This commit is contained in:
@@ -64,7 +64,14 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
|||||||
return utxo;
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max);
|
||||||
|
|
||||||
/* Estimate of (signed) UTXO weight in transaction */
|
/* 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 */
|
#endif /* LIGHTNING_COMMON_UTXO_H */
|
||||||
|
|||||||
9
doc/lightning-fundpsbt.7
generated
9
doc/lightning-fundpsbt.7
generated
@@ -3,7 +3,7 @@
|
|||||||
lightning-fundpsbt - Command to populate PSBT inputs from the wallet
|
lightning-fundpsbt - Command to populate PSBT inputs from the wallet
|
||||||
.SH SYNOPSIS
|
.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
|
.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
|
\fIlocktime\fR is an optional locktime: if not set, it is set to a recent
|
||||||
block height\.
|
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
|
.SH EXAMPLE USAGE
|
||||||
|
|
||||||
Let's assume the caller is trying to produce a 100,000 satoshi output\.
|
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
|
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
|
||||||
|
|
||||||
\" SHA256STAMP:8eb6970e2d625198db9b8e5ab7f90f9fb141744a837f58ee68ef54d28c7066b0
|
\" SHA256STAMP:a8b9705274638127c2f5ec4e97ed94e6d7f6b6b10a76c2248e8bc8b36dd804ff
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ lightning-fundpsbt -- Command to populate PSBT inputs from the wallet
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
|
|
||||||
**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] \[*locktime*\]
|
**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] \[*locktime*\] \[*min_witness_weight*\]
|
||||||
|
|
||||||
DESCRIPTION
|
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
|
*locktime* is an optional locktime: if not set, it is set to a recent
|
||||||
block height.
|
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
|
EXAMPLE USAGE
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|||||||
9
doc/lightning-utxopsbt.7
generated
9
doc/lightning-utxopsbt.7
generated
@@ -3,7 +3,7 @@
|
|||||||
lightning-utxopsbt - Command to populate PSBT inputs from given UTXOs
|
lightning-utxopsbt - Command to populate PSBT inputs from given UTXOs
|
||||||
.SH SYNOPSIS
|
.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
|
.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
|
\fIlocktime\fR is an optional locktime: if not set, it is set to a recent
|
||||||
block height\.
|
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
|
.SH RETURN VALUE
|
||||||
|
|
||||||
On success, returns the \fIpsbt\fR containing the inputs, \fIfeerate_per_kw\fR
|
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
|
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
|
||||||
|
|
||||||
\" SHA256STAMP:e47331be08a0911c74e142f2255bf62a83b70b818c1cf39a9314aab8c17a6e47
|
\" SHA256STAMP:777710bb963f435193e92a55344c740c123d7aa4d54bf573c99a616f59eeee54
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ lightning-utxopsbt -- Command to populate PSBT inputs from given UTXOs
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
|
|
||||||
**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] \[*reservedok*\] \[*locktime*\]
|
**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] \[*reservedok*\] \[*locktime*\] \[*min_witness_weight*\]
|
||||||
|
|
||||||
DESCRIPTION
|
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
|
*locktime* is an optional locktime: if not set, it is set to a recent
|
||||||
block height.
|
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
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
|||||||
{
|
{
|
||||||
struct utxo **utxos;
|
struct utxo **utxos;
|
||||||
u32 *feerate_per_kw;
|
u32 *feerate_per_kw;
|
||||||
u32 *minconf, *weight;
|
u32 *minconf, *weight, *min_witness_weight;
|
||||||
struct amount_sat *amount, input, diff;
|
struct amount_sat *amount, input, diff;
|
||||||
bool all, *reserve;
|
bool all, *reserve;
|
||||||
u32 *locktime, maxheight;
|
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("minconf", param_number, &minconf, 1),
|
||||||
p_opt_def("reserve", param_bool, &reserve, true),
|
p_opt_def("reserve", param_bool, &reserve, true),
|
||||||
p_opt("locktime", param_number, &locktime),
|
p_opt("locktime", param_number, &locktime),
|
||||||
|
p_opt_def("min_witness_weight", param_number,
|
||||||
|
&min_witness_weight, 0),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
@@ -427,7 +429,9 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
|||||||
"impossible UTXO value");
|
"impossible UTXO value");
|
||||||
|
|
||||||
/* But also adds weight */
|
/* 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +559,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
|
|||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
struct utxo **utxos;
|
struct utxo **utxos;
|
||||||
u32 *feerate_per_kw, *weight;
|
u32 *feerate_per_kw, *weight, *min_witness_weight;
|
||||||
bool all, *reserve, *reserved_ok;
|
bool all, *reserve, *reserved_ok;
|
||||||
struct amount_sat *amount, input, excess;
|
struct amount_sat *amount, input, excess;
|
||||||
u32 current_height, *locktime;
|
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("reserve", param_bool, &reserve, true),
|
||||||
p_opt_def("reservedok", param_bool, &reserved_ok, false),
|
p_opt_def("reservedok", param_bool, &reserved_ok, false),
|
||||||
p_opt("locktime", param_number, &locktime),
|
p_opt("locktime", param_number, &locktime),
|
||||||
|
p_opt_def("min_witness_weight", param_number,
|
||||||
|
&min_witness_weight, 0),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
@@ -592,7 +598,7 @@ static struct command_result *json_utxopsbt(struct command *cmd,
|
|||||||
"impossible UTXO value");
|
"impossible UTXO value");
|
||||||
|
|
||||||
/* But also adds weight */
|
/* But also adds weight */
|
||||||
*weight += utxo_spend_weight(utxo);
|
*weight += utxo_spend_weight(utxo, *min_witness_weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For all, anything above 0 is "excess" */
|
/* For all, anything above 0 is "excess" */
|
||||||
|
|||||||
Reference in New Issue
Block a user