build_utxos: fix weight calculation, and make more accurate.

Accuracy improvements:

1. We assumed the output was a p2wpkh, but it can be user-supplied now.
2. We assumed we always had change; remove this for wallet_select_all.

Calculation out-by-one fixes:

1. We need to add 1 byte (4 sipa) for the input count.
2. We need to add 1 byte (4 sipa) for the output count.
3. We need to add 1 byte (4 sipa) for the output script length for each output.
4. We need to add 1 byte (4 sipa) for the input script length for each input.
5. We need to add 1 byte (4 sipa) for the PUSH optcode for each P2SH input.

The results are now a slight overestimate (due to guessing 73 bytes
for signature, whereas they're 71 or 72 in practice).

Fixes: #458
Reported-by: Jonas Nick @jonasnick
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-12-20 16:35:01 +10:30
committed by Christian Decker
parent bbac67f108
commit 3543530172
6 changed files with 44 additions and 10 deletions

View File

@@ -2631,7 +2631,8 @@ static void json_fund_channel(struct command *cmd,
/* FIXME: dustlimit */
fc->utxomap = build_utxos(fc, cmd->ld, fc->funding_satoshi,
get_feerate(cmd->ld->topology, FEERATE_NORMAL),
600, &fc->change, &fc->change_keyindex);
600, BITCOIN_SCRIPTPUBKEY_P2WSH_LEN,
&fc->change, &fc->change_keyindex);
if (!fc->utxomap) {
command_fail(cmd, "Cannot afford funding transaction");
return;