Skip to content

Commit

Permalink
funding tx: include segwit marker + flag in fee calculation
Browse files Browse the repository at this point in the history
Noticed an off by one error when running tests for dual-funding;
we're not including the two 'header' segwit bytes in our weight
calculations.
  • Loading branch information
niftynei authored and rustyrussell committed Aug 3, 2019
1 parent b0b6ddb commit c7f3fa3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common/wallet_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ struct command_result *wtx_from_utxos(struct wallet_tx *tx,

/* The transaction has `tal_count(tx.utxos)` inputs and one output */
/* (version + in count + out count + locktime) (index + value + script length) */
weight = 4 * (4 + 1 + 1 + 4) + 4 * (8 + 1 + out_len);
/* + segwit marker + flag */
weight = 4 * (4 + 1 + 1 + 4) + 4 * (8 + 1 + out_len) + 1 + 1;
for (size_t i = 0; i < tal_count(utxos); i++) {
if (!*utxos[i]->blockheight || *utxos[i]->blockheight > maxheight) {
tal_arr_remove(&utxos, i);
Expand Down
2 changes: 2 additions & 0 deletions devtools/mkfunding.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ int main(int argc, char *argv[])

/* nVersion, input count, output count, nLocktime */
weight = 4 * (4 + 1 + 1 + 4);
/* Add segwit fields: marker + flag */
weight += 1 + 1;
/* Single output: Satoshis, script length, p2wsh. */
weight += 4 * (8 + 1 + BITCOIN_SCRIPTPUBKEY_P2WSH_LEN);
/* Single input: txid, index, scriptlen, nSequence */
Expand Down
3 changes: 3 additions & 0 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ static const struct utxo **wallet_select(const tal_t *ctx, struct wallet *w,
/* version, input count, output count, locktime */
weight = (4 + 1 + 1 + 4) * 4;

/* Add segwit fields: marker + flag */
weight += 1 + 1;

/* The main output: amount, len, scriptpubkey */
weight += (8 + 1 + outscriptlen) * 4;

Expand Down

0 comments on commit c7f3fa3

Please sign in to comment.