mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
fundpsbt: dont add utxos that are a net-loss
if the utxo can't pay for its own fees, dont put it in the tx Changelog-Changed: JSONRPC: fundpsbt will not include UTXOs that aren't economic (can't pay for their own fees), unless 'all'
This commit is contained in:
parent
5e7695f6a0
commit
9a1041ee97
@ -460,6 +460,8 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
|||||||
while (!inputs_sufficient(input, *amount, *feerate_per_kw, *weight,
|
while (!inputs_sufficient(input, *amount, *feerate_per_kw, *weight,
|
||||||
&diff)) {
|
&diff)) {
|
||||||
struct utxo *utxo;
|
struct utxo *utxo;
|
||||||
|
struct amount_sat fee;
|
||||||
|
u32 utxo_weight;
|
||||||
|
|
||||||
utxo = wallet_find_utxo(utxos, cmd->ld->wallet,
|
utxo = wallet_find_utxo(utxos, cmd->ld->wallet,
|
||||||
cmd->ld->topology->tip->height,
|
cmd->ld->topology->tip->height,
|
||||||
@ -468,6 +470,14 @@ static struct command_result *json_fundpsbt(struct command *cmd,
|
|||||||
maxheight,
|
maxheight,
|
||||||
cast_const2(const struct utxo **, utxos));
|
cast_const2(const struct utxo **, utxos));
|
||||||
if (utxo) {
|
if (utxo) {
|
||||||
|
utxo_weight = utxo_spend_weight(utxo,
|
||||||
|
*min_witness_weight);
|
||||||
|
fee = amount_tx_fee(*feerate_per_kw, utxo_weight);
|
||||||
|
|
||||||
|
/* Uneconomic to add this utxo, skip it */
|
||||||
|
if (!all && amount_sat_greater_eq(fee, utxo->amount))
|
||||||
|
continue;
|
||||||
|
|
||||||
tal_arr_expand(&utxos, utxo);
|
tal_arr_expand(&utxos, utxo);
|
||||||
|
|
||||||
/* It supplies more input. */
|
/* It supplies more input. */
|
||||||
@ -476,7 +486,7 @@ 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, *min_witness_weight);
|
*weight += utxo_weight;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user