From b356dda0ba7e8cc347184f70da44f065f7838247 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 9 May 2019 13:04:24 +0200 Subject: [PATCH] elements: Add explicit fee outputs to various transactions we create Elements requires us to have an explicit fee output instead of bitcoin's implied fee. We add the fee output mostly after sorting the other outputs since that matches the behavior in elements itself. Signed-off-by: Christian Decker --- channeld/commit_tx.c | 2 ++ common/close_tx.c | 2 ++ common/funding_tx.c | 2 ++ common/htlc_tx.c | 2 ++ common/initial_commit_tx.c | 1 + common/withdraw_tx.c | 1 + 6 files changed, 10 insertions(+) diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index ff3abb0d5..42f664557 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -289,5 +289,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, u32 sequence = (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF)); bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL); + bitcoin_tx_add_fee_output(tx); + return tx; } diff --git a/common/close_tx.c b/common/close_tx.c index 81949597c..b727c952f 100644 --- a/common/close_tx.c +++ b/common/close_tx.c @@ -61,6 +61,8 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, return tal_free(tx); permute_outputs(tx, NULL, NULL); + bitcoin_tx_add_fee_output(tx); + assert(bitcoin_tx_check(tx)); return tx; } diff --git a/common/funding_tx.c b/common/funding_tx.c index 5f7426e96..4e4261c7e 100644 --- a/common/funding_tx.c +++ b/common/funding_tx.c @@ -48,6 +48,8 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, } permute_inputs(tx, (const void **)utxomap); + + bitcoin_tx_add_fee_output(tx); assert(bitcoin_tx_check(tx)); return tx; } diff --git a/common/htlc_tx.c b/common/htlc_tx.c index b3f2db006..56eb58f3c 100644 --- a/common/htlc_tx.c +++ b/common/htlc_tx.c @@ -63,6 +63,8 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, wscript = bitcoin_wscript_htlc_tx(tx, to_self_delay, revocation_pubkey, local_delayedkey); bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), amount); + bitcoin_tx_add_fee_output(tx); + tal_free(wscript); return tx; diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index ee928a3ca..361575ee0 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -238,6 +238,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, sequence = (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF)); bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL); + bitcoin_tx_add_fee_output(tx); assert(bitcoin_tx_check(tx)); return tx; diff --git a/common/withdraw_tx.c b/common/withdraw_tx.c index 20a6c9336..d20639d05 100644 --- a/common/withdraw_tx.c +++ b/common/withdraw_tx.c @@ -38,6 +38,7 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx, } else if (change_outnum) *change_outnum = -1; permute_inputs(tx, (const void **)utxos); + bitcoin_tx_add_fee_output(tx); assert(bitcoin_tx_check(tx)); return tx; }