From f9300e8480682cf2ae613047b8d2525254ba5b2d Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 21 May 2020 22:16:11 -0500 Subject: [PATCH] tx: add setter for tx locktime We need to update the psbt's global transaction simultaneously, so we wrap access to the locktime in a method which will handle both --- bitcoin/tx.c | 6 ++++++ bitcoin/tx.h | 3 +++ channeld/commit_tx.c | 4 ++-- common/initial_commit_tx.c | 4 ++-- onchaind/test/run-grind_feerate-bug.c | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 5024845d4..9ffe7376a 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -151,6 +151,12 @@ static int elements_tx_add_fee_output(struct bitcoin_tx *tx) } } +void bitcoin_tx_set_locktime(struct bitcoin_tx *tx, u32 locktime) +{ + tx->wtx->locktime = locktime; + tx->psbt->tx->locktime = locktime; +} + int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, u32 outnum, u32 sequence, const u8 *scriptSig, struct amount_sat amount, const u8 *scriptPubkey, diff --git a/bitcoin/tx.h b/bitcoin/tx.h index fdbd8f8da..b9c69048d 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -77,6 +77,9 @@ int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, int bitcoin_tx_add_multi_outputs(struct bitcoin_tx *tx, struct bitcoin_tx_output **outputs); +/* Set the locktime for a transaction */ +void bitcoin_tx_set_locktime(struct bitcoin_tx *tx, u32 locktime); + /* Add a new input to a bitcoin tx. * * For P2WSH inputs, we'll also store the wscript and/or scriptPubkey diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 75030de84..3819708c2 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -276,8 +276,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * * * locktime: upper 8 bits are 0x20, lower 24 bits are the lower 24 bits of the obscured commitment number */ - tx->wtx->locktime - = (0x20000000 | (obscured_commitment_number & 0xFFFFFF)); + bitcoin_tx_set_locktime(tx, + (0x20000000 | (obscured_commitment_number & 0xFFFFFF))); /* BOLT #3: * diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index bedb87d86..8d10bcda6 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -228,8 +228,8 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, * * locktime: upper 8 bits are 0x20, lower 24 bits are the * lower 24 bits of the obscured commitment number */ - tx->wtx->locktime = - (0x20000000 | (obscured_commitment_number & 0xFFFFFF)); + bitcoin_tx_set_locktime(tx, + (0x20000000 | (obscured_commitment_number & 0xFFFFFF))); /* BOLT #3: * diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index 25eac3c53..633a15a62 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -357,7 +357,7 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, psbt_input_set_prev_utxo_wscript(tx->psbt, 0, commit_wscript, in_amount); tx->chainparams = chainparams; - tx->wtx->locktime = cltv_expiry; + bitcoin_tx_set_locktime(tx, cltv_expiry); return tx; }