mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
funder: subtract the fee of the utxo from the available amount
Adjust our total available funds downward, to account for the fees we'll be charged to spend them.
This commit is contained in:
parent
9a1041ee97
commit
f6186d5860
@ -350,7 +350,7 @@ listfunds_success(struct command *cmd,
|
||||
const jsmntok_t *result,
|
||||
struct open_info *info)
|
||||
{
|
||||
struct amount_sat available_funds;
|
||||
struct amount_sat available_funds, est_fee;
|
||||
const jsmntok_t *outputs_tok, *tok;
|
||||
struct out_req *req;
|
||||
size_t i;
|
||||
@ -365,7 +365,7 @@ listfunds_success(struct command *cmd,
|
||||
available_funds = AMOUNT_SAT(0);
|
||||
json_for_each_arr(i, tok, outputs_tok) {
|
||||
struct amount_sat val;
|
||||
bool is_reserved;
|
||||
bool is_reserved, is_p2sh;
|
||||
char *status;
|
||||
const char *err;
|
||||
|
||||
@ -382,6 +382,16 @@ listfunds_success(struct command *cmd,
|
||||
err, json_tok_full_len(result),
|
||||
json_tok_full(buf, result));
|
||||
|
||||
/* is it a p2sh output? */
|
||||
if (json_get_member(buf, tok, "redeemscript"))
|
||||
is_p2sh = true;
|
||||
else
|
||||
is_p2sh = false;
|
||||
|
||||
/* The estimated fee per utxo. */
|
||||
est_fee = amount_tx_fee(info->funding_feerate_perkw,
|
||||
bitcoin_tx_input_weight(is_p2sh, 110));
|
||||
|
||||
/* we skip reserved funds */
|
||||
if (is_reserved)
|
||||
continue;
|
||||
@ -390,11 +400,14 @@ listfunds_success(struct command *cmd,
|
||||
if (!streq(status, "confirmed"))
|
||||
continue;
|
||||
|
||||
/* Don't include outputs that can't cover their weight;
|
||||
* subtract the fee for this utxo out of the utxo */
|
||||
if (!amount_sat_sub(&val, val, est_fee))
|
||||
continue;
|
||||
|
||||
if (!amount_sat_add(&available_funds, available_funds, val))
|
||||
plugin_err(cmd->plugin,
|
||||
"`listfunds` overflowed output values");
|
||||
|
||||
/* FIXME: count of utxos? */
|
||||
}
|
||||
|
||||
info->our_funding = calculate_our_funding(current_policy,
|
||||
|
@ -213,9 +213,6 @@ calculate_our_funding(struct funder_policy policy,
|
||||
if (amount_sat_greater(our_funding, policy.per_channel_max))
|
||||
our_funding = policy.per_channel_max;
|
||||
|
||||
/* FIXME: net_available_funds needs to know feerate, and make
|
||||
* worst-case UTXO assumptions? */
|
||||
|
||||
/* Is our_funding more than we have available? if so
|
||||
* set to max available */
|
||||
if (amount_sat_greater(our_funding, net_available_funds))
|
||||
|
Loading…
Reference in New Issue
Block a user