Browse Source

elements: Fix transaction size estimate when selecting coins

In elements we add an explicit fee output, if we don't consider it when
selecting coins, we end up underpaying the fees.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
travis-debug
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
f197e3da83
  1. 12
      wallet/wallet.c

12
wallet/wallet.c

@ -378,9 +378,13 @@ static const struct utxo **wallet_select(const tal_t *ctx, struct wallet *w,
weight += 2 * 4; weight += 2 * 4;
/* Each output additionally has an asset_tag (1 + 32), value /* Each output additionally has an asset_tag (1 + 32), value
* is prefixed by a version (1 byte) and an empty nonce (1 * is prefixed by a version (1 byte), an empty nonce (1
* byte). */ * byte), two empty proofs (2 bytes). */
weight += (32 + 1 + 1 + 1) * 4 * num_outputs; weight += (32 + 1 + 1 + 1) * 4 * num_outputs;
/* An elements transaction has 1 additional output for fees */
weight += (8 + 1) * 4; /* Bitcoin style output */
weight += (32 + 1 + 1 + 1) * 4; /* Elements added fields */
} }
*fee_estimate = AMOUNT_SAT(0); *fee_estimate = AMOUNT_SAT(0);
@ -420,6 +424,10 @@ static const struct utxo **wallet_select(const tal_t *ctx, struct wallet *w,
/* Account for witness (1 byte count + sig + key) */ /* Account for witness (1 byte count + sig + key) */
input_weight += 1 + (1 + 73 + 1 + 33); input_weight += 1 + (1 + 73 + 1 + 33);
/* Elements inputs have 6 bytes of blank proofs attached. */
if (is_elements)
input_weight += 6;
weight += input_weight; weight += input_weight;
if (!amount_sat_add(satoshi_in, *satoshi_in, u->amount)) if (!amount_sat_add(satoshi_in, *satoshi_in, u->amount))

Loading…
Cancel
Save