From 1e1948bfd21a59e55d82147666516180340d470e Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Tue, 21 Dec 2021 20:07:24 -0800 Subject: [PATCH] hsmd: Add redeemscripts to anchor outputs --- channeld/commit_tx.c | 17 ++++++++++------- common/initial_commit_tx.c | 7 ++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 1e87ae6ee..2fdf0df1a 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -285,6 +285,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * `dust_limit_satoshis`, add a [`to_remote` * output](#to_remote-output). */ + u8 *redeem; if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { struct amount_sat amount = amount_msat_to_sat_round_down(other_pay); u8 *scriptpubkey; @@ -303,11 +304,10 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * Otherwise, this output is a simple P2WPKH to `remotepubkey`. */ if (option_anchor_outputs) { - const u8 *redeem - = anchor_to_remote_redeem(tmpctx, - &keyset->other_payment_key, - (!side) == lessor ? - csv_lock : 1); + redeem = anchor_to_remote_redeem(tmpctx, + &keyset->other_payment_key, + (!side) == lessor ? + csv_lock : 1); /* BOLT- #3: * ##### Leased channel (`option_will_fund`) * @@ -322,10 +322,11 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, */ scriptpubkey = scriptpubkey_p2wsh(tmpctx, redeem); } else { + redeem = NULL; scriptpubkey = scriptpubkey_p2wpkh(tmpctx, &keyset->other_payment_key); } - pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount); + pos = bitcoin_tx_add_output(tx, scriptpubkey, redeem, amount); assert(pos == n); (*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL; /* We don't assign cltvs[n]: if we use it, order doesn't matter. @@ -337,8 +338,10 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, n++; to_remote = true; - } else + } else { to_remote = false; + redeem = NULL; + } /* BOLT #3: * diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 6da3fa3a0..44203f7f4 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -243,19 +243,20 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, */ u8 *scriptpubkey; int pos; + u8 *redeem; amount = amount_msat_to_sat_round_down(other_pay); if (option_anchor_outputs) { - const u8 *redeem - = anchor_to_remote_redeem(tmpctx, + redeem = anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, (!side) == lessor ? csv_lock : 1); scriptpubkey = scriptpubkey_p2wsh(tmpctx, redeem); } else { + redeem = NULL; scriptpubkey = scriptpubkey_p2wpkh(tmpctx, &keyset->other_payment_key); } - pos = bitcoin_tx_add_output(tx, scriptpubkey, NULL, amount); + pos = bitcoin_tx_add_output(tx, scriptpubkey, redeem, amount); assert(pos == n); output_order[n] = dummy_remote; n++;