Browse Source

tx: Add chainparams to struct bitcoin_tx as context

The way we build transactions, serialize them, and compute fees depends on the
chain we are working on, so let's add some context to the transactions.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
9288a7906b
  1. 8
      bitcoin/tx.c
  2. 8
      bitcoin/tx.h
  3. 14
      channeld/channeld.c
  4. 3
      channeld/commit_tx.c
  5. 2
      channeld/commit_tx.h
  6. 32
      channeld/full_channel.c
  7. 2
      channeld/full_channel.h
  8. 34
      channeld/test/run-commit_tx.c
  9. 48
      channeld/test/run-full_channel.c
  10. 20
      closingd/closingd.c
  11. 3
      common/close_tx.c
  12. 3
      common/close_tx.h
  13. 3
      common/funding_tx.c
  14. 3
      common/funding_tx.h
  15. 14
      common/htlc_tx.c
  16. 3
      common/htlc_tx.h
  17. 3
      common/initial_channel.c
  18. 3
      common/initial_commit_tx.c
  19. 3
      common/initial_commit_tx.h
  20. 5
      common/test/run-funding_tx.c
  21. 3
      common/utxo.c
  22. 2
      common/utxo.h
  23. 3
      common/withdraw_tx.c
  24. 3
      common/withdraw_tx.h
  25. 5
      devtools/mkcommit.c
  26. 3
      devtools/mkfunding.c
  27. 22
      hsmd/hsmd.c
  28. 4
      lightningd/opening_control.c
  29. 117
      onchaind/onchaind.c
  30. 3
      onchaind/test/run-grind_feerate.c
  31. 2
      openingd/openingd.c
  32. 3
      wallet/walletrpc.c

8
bitcoin/tx.c

@ -276,10 +276,12 @@ static void bitcoin_tx_destroy(struct bitcoin_tx *tx)
wally_tx_free(tx->wtx); wally_tx_free(tx->wtx);
} }
struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count, struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
varint_t output_count) const struct chainparams *chainparams,
varint_t input_count, varint_t output_count)
{ {
struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx); struct bitcoin_tx *tx = tal(ctx, struct bitcoin_tx);
wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count, wally_tx_init_alloc(WALLY_TX_VERSION_2, 0, input_count, output_count,
&tx->wtx); &tx->wtx);
tal_add_destructor(tx, bitcoin_tx_destroy); tal_add_destructor(tx, bitcoin_tx_destroy);
@ -287,6 +289,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
tx->input_amounts = tal_arrz(tx, struct amount_sat*, input_count); tx->input_amounts = tal_arrz(tx, struct amount_sat*, input_count);
tx->wtx->locktime = 0; tx->wtx->locktime = 0;
tx->wtx->version = 2; tx->wtx->version = 2;
tx->chainparams = chainparams;
return tx; return tx;
} }
@ -305,6 +308,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
/* We don't know the input amounts yet, so set them all to NULL */ /* We don't know the input amounts yet, so set them all to NULL */
tx->input_amounts = tx->input_amounts =
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len); tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);
tx->chainparams = NULL;
*cursor += wsize; *cursor += wsize;
*max -= wsize; *max -= wsize;

8
bitcoin/tx.h

@ -23,6 +23,9 @@ struct bitcoin_tx {
* unknown) */ * unknown) */
struct amount_sat **input_amounts; struct amount_sat **input_amounts;
struct wally_tx *wtx; struct wally_tx *wtx;
/* Keep a reference to the ruleset we have to abide by */
const struct chainparams *chainparams;
}; };
struct bitcoin_tx_output { struct bitcoin_tx_output {
@ -52,8 +55,9 @@ size_t measure_tx_weight(const struct bitcoin_tx *tx);
/* Allocate a tx: you just need to fill in inputs and outputs (they're /* Allocate a tx: you just need to fill in inputs and outputs (they're
* zeroed with inputs' sequence_number set to FFFFFFFF) */ * zeroed with inputs' sequence_number set to FFFFFFFF) */
struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count, struct bitcoin_tx *bitcoin_tx(const tal_t *ctx,
varint_t output_count); const struct chainparams *chainparams,
varint_t input_count, varint_t output_count);
/* This takes a raw bitcoin tx in hex. */ /* This takes a raw bitcoin tx in hex. */
struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex, struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex,

14
channeld/channeld.c

@ -979,10 +979,9 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx,
const u8 *msg; const u8 *msg;
secp256k1_ecdsa_signature *htlc_sigs; secp256k1_ecdsa_signature *htlc_sigs;
txs = channel_txs(tmpctx, &htlc_map, &wscripts, peer->channel, txs = channel_txs(tmpctx, peer->channel->chainparams, &htlc_map,
&peer->remote_per_commit, &wscripts, peer->channel, &peer->remote_per_commit,
commit_index, commit_index, REMOTE);
REMOTE);
msg = towire_hsm_sign_remote_commitment_tx(NULL, txs[0], msg = towire_hsm_sign_remote_commitment_tx(NULL, txs[0],
&peer->channel->funding_pubkey[REMOTE], &peer->channel->funding_pubkey[REMOTE],
@ -1398,9 +1397,10 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* SIGHASH_ALL is implied. */ /* SIGHASH_ALL is implied. */
commit_sig.sighash_type = SIGHASH_ALL; commit_sig.sighash_type = SIGHASH_ALL;
txs = channel_txs(tmpctx, &htlc_map, &wscripts, peer->channel, txs =
&peer->next_local_per_commit, channel_txs(tmpctx, peer->channel->chainparams, &htlc_map,
peer->next_index[LOCAL], LOCAL); &wscripts, peer->channel, &peer->next_local_per_commit,
peer->next_index[LOCAL], LOCAL);
if (!derive_simple_key(&peer->channel->basepoints[REMOTE].htlc, if (!derive_simple_key(&peer->channel->basepoints[REMOTE].htlc,
&peer->next_local_per_commit, &remote_htlckey)) &peer->next_local_per_commit, &remote_htlckey))

3
channeld/commit_tx.c

@ -76,6 +76,7 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n,
} }
struct bitcoin_tx *commit_tx(const tal_t *ctx, struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
@ -146,7 +147,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
#endif #endif
/* Worst-case sizing: both to-local and to-remote outputs. */ /* Worst-case sizing: both to-local and to-remote outputs. */
tx = bitcoin_tx(ctx, 1, untrimmed + 2); tx = bitcoin_tx(ctx, chainparams, 1, untrimmed + 2);
/* We keep track of which outputs have which HTLCs */ /* We keep track of which outputs have which HTLCs */
*htlcmap = tal_arr(tx, const struct htlc *, tx->wtx->outputs_allocation_len); *htlcmap = tal_arr(tx, const struct htlc *, tx->wtx->outputs_allocation_len);

2
channeld/commit_tx.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_CHANNELD_COMMIT_TX_H #ifndef LIGHTNING_CHANNELD_COMMIT_TX_H
#define LIGHTNING_CHANNELD_COMMIT_TX_H #define LIGHTNING_CHANNELD_COMMIT_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <channeld/channeld_htlc.h> #include <channeld/channeld_htlc.h>
#include <common/htlc.h> #include <common/htlc.h>
@ -43,6 +44,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
* transaction, so we carefully use the terms "self" and "other" here. * transaction, so we carefully use the terms "self" and "other" here.
*/ */
struct bitcoin_tx *commit_tx(const tal_t *ctx, struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,

32
channeld/full_channel.c

@ -187,7 +187,8 @@ static bool sum_offered_msatoshis(struct amount_msat *total,
return true; return true;
} }
static void add_htlcs(struct bitcoin_tx ***txs, static void add_htlcs(const struct chainparams *chainparams,
struct bitcoin_tx ***txs,
const u8 ***wscripts, const u8 ***wscripts,
const struct htlc **htlcmap, const struct htlc **htlcmap,
const struct channel *channel, const struct channel *channel,
@ -210,7 +211,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
continue; continue;
if (htlc_owner(htlc) == side) { if (htlc_owner(htlc) == side) {
tx = htlc_timeout_tx(*txs, &txid, i, tx = htlc_timeout_tx(*txs, chainparams, &txid, i,
htlc->amount, htlc->amount,
htlc->expiry.locktime, htlc->expiry.locktime,
channel->config[!side].to_self_delay, channel->config[!side].to_self_delay,
@ -222,7 +223,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
&htlc->rhash, &htlc->rhash,
&keyset->self_revocation_key); &keyset->self_revocation_key);
} else { } else {
tx = htlc_success_tx(*txs, &txid, i, tx = htlc_success_tx(*txs, chainparams, &txid, i,
htlc->amount, htlc->amount,
channel->config[!side].to_self_delay, channel->config[!side].to_self_delay,
feerate_per_kw, feerate_per_kw,
@ -245,6 +246,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
/* FIXME: We could cache these. */ /* FIXME: We could cache these. */
struct bitcoin_tx **channel_txs(const tal_t *ctx, struct bitcoin_tx **channel_txs(const tal_t *ctx,
const struct chainparams *chainparams,
const struct htlc ***htlcmap, const struct htlc ***htlcmap,
const u8 ***wscripts, const u8 ***wscripts,
const struct channel *channel, const struct channel *channel,
@ -266,27 +268,21 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
gather_htlcs(ctx, channel, side, &committed, NULL, NULL); gather_htlcs(ctx, channel, side, &committed, NULL, NULL);
txs = tal_arr(ctx, struct bitcoin_tx *, 1); txs = tal_arr(ctx, struct bitcoin_tx *, 1);
txs[0] = commit_tx(ctx, &channel->funding_txid, txs[0] = commit_tx(
channel->funding_txout, ctx, chainparams, &channel->funding_txid, channel->funding_txout,
channel->funding, channel->funding, channel->funder,
channel->funder, channel->config[!side].to_self_delay, &keyset,
channel->config[!side].to_self_delay, channel->view[side].feerate_per_kw,
&keyset, channel->config[side].dust_limit, channel->view[side].owed[side],
channel->view[side].feerate_per_kw, channel->view[side].owed[!side], committed, htlcmap,
channel->config[side].dust_limit, commitment_number ^ channel->commitment_number_obscurer, side);
channel->view[side].owed[side],
channel->view[side].owed[!side],
committed,
htlcmap,
commitment_number ^ channel->commitment_number_obscurer,
side);
*wscripts = tal_arr(ctx, const u8 *, 1); *wscripts = tal_arr(ctx, const u8 *, 1);
(*wscripts)[0] = bitcoin_redeem_2of2(*wscripts, (*wscripts)[0] = bitcoin_redeem_2of2(*wscripts,
&channel->funding_pubkey[side], &channel->funding_pubkey[side],
&channel->funding_pubkey[!side]); &channel->funding_pubkey[!side]);
add_htlcs(&txs, wscripts, *htlcmap, channel, &keyset, side); add_htlcs(chainparams, &txs, wscripts, *htlcmap, channel, &keyset, side);
tal_free(committed); tal_free(committed);
return txs; return txs;

2
channeld/full_channel.h

@ -47,6 +47,7 @@ struct channel *new_full_channel(const tal_t *ctx,
/** /**
* channel_txs: Get the current commitment and htlc txs for the channel. * channel_txs: Get the current commitment and htlc txs for the channel.
* @ctx: tal context to allocate return value from. * @ctx: tal context to allocate return value from.
* @chainparams: Parameters for the generated transactions.
* @channel: The channel to evaluate * @channel: The channel to evaluate
* @htlc_map: Pointer to htlcs for each tx output (allocated off @ctx). * @htlc_map: Pointer to htlcs for each tx output (allocated off @ctx).
* @wscripts: Pointer to array of wscript for each tx returned (alloced off @ctx) * @wscripts: Pointer to array of wscript for each tx returned (alloced off @ctx)
@ -59,6 +60,7 @@ struct channel *new_full_channel(const tal_t *ctx,
* fills in @htlc_map, or NULL on key derivation failure. * fills in @htlc_map, or NULL on key derivation failure.
*/ */
struct bitcoin_tx **channel_txs(const tal_t *ctx, struct bitcoin_tx **channel_txs(const tal_t *ctx,
const struct chainparams *chainparams,
const struct htlc ***htlcmap, const struct htlc ***htlcmap,
const u8 ***wscripts, const u8 ***wscripts,
const struct channel *channel, const struct channel *channel,

34
channeld/test/run-commit_tx.c

@ -222,7 +222,8 @@ static void report_htlcs(const struct bitcoin_tx *tx,
continue; continue;
if (htlc_owner(htlc) == LOCAL) { if (htlc_owner(htlc) == LOCAL) {
htlc_tx[i] = htlc_timeout_tx(htlc_tx, &txid, i, htlc_tx[i] = htlc_timeout_tx(htlc_tx, tx->chainparams,
&txid, i,
htlc->amount, htlc->amount,
htlc->expiry.locktime, htlc->expiry.locktime,
to_self_delay, to_self_delay,
@ -234,7 +235,8 @@ static void report_htlcs(const struct bitcoin_tx *tx,
&htlc->rhash, &htlc->rhash,
remote_revocation_key); remote_revocation_key);
} else { } else {
htlc_tx[i] = htlc_success_tx(htlc_tx, &txid, i, htlc_tx[i] = htlc_success_tx(htlc_tx, tx->chainparams,
&txid, i,
htlc->amount, htlc->amount,
to_self_delay, to_self_delay,
feerate_per_kw, feerate_per_kw,
@ -457,6 +459,7 @@ int main(void)
u64 commitment_number, cn_obscurer; u64 commitment_number, cn_obscurer;
struct amount_msat to_local, to_remote; struct amount_msat to_local, to_remote;
const struct htlc **htlcs, **htlc_map, **htlc_map2, **inv_htlcs; const struct htlc **htlcs, **htlc_map, **htlc_map2, **inv_htlcs;
const struct chainparams *chainparams = chainparams_for_network("bitcoin");
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN); | SECP256K1_CONTEXT_SIGN);
@ -712,7 +715,8 @@ int main(void)
keyset.other_htlc_key = remote_htlckey; keyset.other_htlc_key = remote_htlckey;
print_superverbose = true; print_superverbose = true;
tx = commit_tx(tmpctx, &funding_txid, funding_output_index, tx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,
@ -723,7 +727,8 @@ int main(void)
NULL, &htlc_map, commitment_number ^ cn_obscurer, NULL, &htlc_map, commitment_number ^ cn_obscurer,
LOCAL); LOCAL);
print_superverbose = false; print_superverbose = false;
tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, tx2 = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
REMOTE, to_self_delay, REMOTE, to_self_delay,
&keyset, &keyset,
@ -766,7 +771,8 @@ int main(void)
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
print_superverbose = true; print_superverbose = true;
tx = commit_tx(tmpctx, &funding_txid, funding_output_index, tx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,
@ -777,7 +783,8 @@ int main(void)
htlcs, &htlc_map, commitment_number ^ cn_obscurer, htlcs, &htlc_map, commitment_number ^ cn_obscurer,
LOCAL); LOCAL);
print_superverbose = false; print_superverbose = false;
tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, tx2 = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
REMOTE, to_self_delay, REMOTE, to_self_delay,
&keyset, &keyset,
@ -808,7 +815,8 @@ int main(void)
feerate_per_kw = increase(feerate_per_kw); feerate_per_kw = increase(feerate_per_kw);
print_superverbose = false; print_superverbose = false;
newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, newtx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,
@ -820,7 +828,8 @@ int main(void)
commitment_number ^ cn_obscurer, commitment_number ^ cn_obscurer,
LOCAL); LOCAL);
/* This is what it would look like for peer generating it! */ /* This is what it would look like for peer generating it! */
tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, tx2 = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
REMOTE, to_self_delay, REMOTE, to_self_delay,
&keyset, &keyset,
@ -851,7 +860,8 @@ int main(void)
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw-1); to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw-1);
/* Recalc with verbosity on */ /* Recalc with verbosity on */
print_superverbose = true; print_superverbose = true;
tx = commit_tx(tmpctx, &funding_txid, funding_output_index, tx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,
@ -887,7 +897,8 @@ int main(void)
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
/* Recalc with verbosity on */ /* Recalc with verbosity on */
print_superverbose = true; print_superverbose = true;
newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, newtx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,
@ -945,7 +956,8 @@ int main(void)
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %u\n", "local_feerate_per_kw: %u\n",
to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw);
tx = commit_tx(tmpctx, &funding_txid, funding_output_index, tx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, to_self_delay, LOCAL, to_self_delay,
&keyset, &keyset,

48
channeld/test/run-full_channel.c

@ -494,7 +494,8 @@ int main(void)
keyset.self_htlc_key = keyset.self_payment_key; keyset.self_htlc_key = keyset.self_payment_key;
keyset.other_htlc_key = keyset.other_payment_key; keyset.other_htlc_key = keyset.other_payment_key;
raw_tx = commit_tx(tmpctx, &funding_txid, funding_output_index, raw_tx = commit_tx(tmpctx, chainparams,
&funding_txid, funding_output_index,
funding_amount, funding_amount,
LOCAL, remote_config->to_self_delay, LOCAL, remote_config->to_self_delay,
&keyset, &keyset,
@ -504,7 +505,8 @@ int main(void)
to_remote, to_remote,
NULL, &htlc_map, 0x2bb038521914 ^ 42, LOCAL); NULL, &htlc_map, 0x2bb038521914 ^ 42, LOCAL);
txs = channel_txs(tmpctx, &htlc_map, &wscripts, txs = channel_txs(tmpctx, chainparams,
&htlc_map, &wscripts,
lchannel, &local_per_commitment_point, 42, LOCAL); lchannel, &local_per_commitment_point, 42, LOCAL);
assert(tal_count(txs) == 1); assert(tal_count(txs) == 1);
assert(tal_count(htlc_map) == 2); assert(tal_count(htlc_map) == 2);
@ -512,7 +514,8 @@ int main(void)
assert(scripteq(wscripts[0], funding_wscript)); assert(scripteq(wscripts[0], funding_wscript));
tx_must_be_eq(txs[0], raw_tx); tx_must_be_eq(txs[0], raw_tx);
txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, txs2 = channel_txs(tmpctx, chainparams,
&htlc_map, &wscripts,
rchannel, &local_per_commitment_point, 42, REMOTE); rchannel, &local_per_commitment_point, 42, REMOTE);
txs_must_be_eq(txs, txs2); txs_must_be_eq(txs, txs2);
@ -539,10 +542,10 @@ int main(void)
assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis
== rchannel->view[LOCAL].owed[LOCAL].millisatoshis); == rchannel->view[LOCAL].owed[LOCAL].millisatoshis);
txs = channel_txs(tmpctx, &htlc_map, &wscripts, txs = channel_txs(tmpctx, chainparams,&htlc_map, &wscripts,
lchannel, &local_per_commitment_point, 42, LOCAL); lchannel, &local_per_commitment_point, 42, LOCAL);
assert(tal_count(txs) == 1); assert(tal_count(txs) == 1);
txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts,
rchannel, &local_per_commitment_point, 42, REMOTE); rchannel, &local_per_commitment_point, 42, REMOTE);
txs_must_be_eq(txs, txs2); txs_must_be_eq(txs, txs2);
@ -557,10 +560,10 @@ int main(void)
assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis
== rchannel->view[LOCAL].owed[LOCAL].millisatoshis); == rchannel->view[LOCAL].owed[LOCAL].millisatoshis);
txs = channel_txs(tmpctx, &htlc_map, &wscripts, txs = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts,
lchannel, &local_per_commitment_point, 42, LOCAL); lchannel, &local_per_commitment_point, 42, LOCAL);
assert(tal_count(txs) == 6); assert(tal_count(txs) == 6);
txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts,
rchannel, &local_per_commitment_point, 42, REMOTE); rchannel, &local_per_commitment_point, 42, REMOTE);
txs_must_be_eq(txs, txs2); txs_must_be_eq(txs, txs2);
@ -570,6 +573,7 @@ int main(void)
* output htlc_success_tx 0: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000 * output htlc_success_tx 0: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000
*/ */
raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000"); raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000");
raw_tx->chainparams = chainparams_for_network("bitcoin");
bitcoin_tx_input_set_witness(raw_tx, 0, NULL); bitcoin_tx_input_set_witness(raw_tx, 0, NULL);
tx_must_be_eq(raw_tx, txs[1]); tx_must_be_eq(raw_tx, txs[1]);
@ -578,6 +582,7 @@ int main(void)
* output htlc_timeout_tx 2: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000 * output htlc_timeout_tx 2: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000
*/ */
raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000"); raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000");
raw_tx->chainparams = chainparams_for_network("bitcoin");
bitcoin_tx_input_set_witness(raw_tx, 0, NULL); bitcoin_tx_input_set_witness(raw_tx, 0, NULL);
tx_must_be_eq(raw_tx, txs[2]); tx_must_be_eq(raw_tx, txs[2]);
@ -586,6 +591,7 @@ int main(void)
* output htlc_success_tx 1: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000 * output htlc_success_tx 1: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000
*/ */
raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000"); raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000");
raw_tx->chainparams = chainparams_for_network("bitcoin");
bitcoin_tx_input_set_witness(raw_tx, 0, NULL); bitcoin_tx_input_set_witness(raw_tx, 0, NULL);
tx_must_be_eq(raw_tx, txs[3]); tx_must_be_eq(raw_tx, txs[3]);
@ -594,6 +600,7 @@ int main(void)
* output htlc_timeout_tx 3: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000 * output htlc_timeout_tx 3: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000
*/ */
raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000"); raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000");
raw_tx->chainparams = chainparams_for_network("bitcoin");
bitcoin_tx_input_set_witness(raw_tx, 0, NULL); bitcoin_tx_input_set_witness(raw_tx, 0, NULL);
tx_must_be_eq(raw_tx, txs[4]); tx_must_be_eq(raw_tx, txs[4]);
@ -602,6 +609,7 @@ int main(void)
* output htlc_success_tx 4: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000 * output htlc_success_tx 4: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000
*/ */
raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000"); raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000");
raw_tx->chainparams = chainparams_for_network("bitcoin");
bitcoin_tx_input_set_witness(raw_tx, 0, NULL); bitcoin_tx_input_set_witness(raw_tx, 0, NULL);
tx_must_be_eq(raw_tx, txs[5]); tx_must_be_eq(raw_tx, txs[5]);
@ -612,23 +620,19 @@ int main(void)
lchannel->view[LOCAL].feerate_per_kw = feerate_per_kw[LOCAL]; lchannel->view[LOCAL].feerate_per_kw = feerate_per_kw[LOCAL];
rchannel->view[REMOTE].feerate_per_kw = feerate_per_kw[REMOTE]; rchannel->view[REMOTE].feerate_per_kw = feerate_per_kw[REMOTE];
raw_tx = commit_tx(tmpctx, &funding_txid, funding_output_index, raw_tx = commit_tx(
funding_amount, tmpctx, chainparams, &funding_txid, funding_output_index,
LOCAL, remote_config->to_self_delay, funding_amount, LOCAL, remote_config->to_self_delay,
&keyset, &keyset, feerate_per_kw[LOCAL], local_config->dust_limit,
feerate_per_kw[LOCAL], to_local, to_remote, htlcs, &htlc_map, 0x2bb038521914 ^ 42,
local_config->dust_limit, LOCAL);
to_local,
to_remote, txs = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts,
htlcs, &htlc_map, lchannel, &local_per_commitment_point, 42,
0x2bb038521914 ^ 42, LOCAL); LOCAL);
txs = channel_txs(tmpctx, &htlc_map, &wscripts,
lchannel, &local_per_commitment_point,
42, LOCAL);
tx_must_be_eq(txs[0], raw_tx); tx_must_be_eq(txs[0], raw_tx);
txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts,
rchannel, &local_per_commitment_point, rchannel, &local_per_commitment_point,
42, REMOTE); 42, REMOTE);
txs_must_be_eq(txs, txs2); txs_must_be_eq(txs, txs2);

20
closingd/closingd.c

@ -31,6 +31,7 @@
#define HSM_FD 6 #define HSM_FD 6
static struct bitcoin_tx *close_tx(const tal_t *ctx, static struct bitcoin_tx *close_tx(const tal_t *ctx,
const struct chainparams *chainparams,
struct per_peer_state *pps, struct per_peer_state *pps,
const struct channel_id *channel_id, const struct channel_id *channel_id,
u8 *scriptpubkey[NUM_SIDES], u8 *scriptpubkey[NUM_SIDES],
@ -63,6 +64,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
/* FIXME: We need to allow this! */ /* FIXME: We need to allow this! */
tx = create_close_tx(ctx, tx = create_close_tx(ctx,
chainparams,
scriptpubkey[LOCAL], scriptpubkey[REMOTE], scriptpubkey[LOCAL], scriptpubkey[REMOTE],
funding_txid, funding_txid,
funding_txout, funding_txout,
@ -210,6 +212,7 @@ static void do_reconnect(struct per_peer_state *pps,
} }
static void send_offer(struct per_peer_state *pps, static void send_offer(struct per_peer_state *pps,
const struct chainparams *chainparams,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES], const struct pubkey funding_pubkey[NUM_SIDES],
u8 *scriptpubkey[NUM_SIDES], u8 *scriptpubkey[NUM_SIDES],
@ -231,7 +234,7 @@ static void send_offer(struct per_peer_state *pps,
* transaction, as specified in [BOLT * transaction, as specified in [BOLT
* #3](03-transactions.md#closing-transaction). * #3](03-transactions.md#closing-transaction).
*/ */
tx = close_tx(tmpctx, pps, channel_id, tx = close_tx(tmpctx, chainparams, pps, channel_id,
scriptpubkey, scriptpubkey,
funding_txid, funding_txid,
funding_txout, funding_txout,
@ -286,6 +289,7 @@ static void tell_master_their_offer(const struct bitcoin_signature *their_sig,
/* Returns fee they offered. */ /* Returns fee they offered. */
static struct amount_sat static struct amount_sat
receive_offer(struct per_peer_state *pps, receive_offer(struct per_peer_state *pps,
const struct chainparams *chainparams,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const struct pubkey funding_pubkey[NUM_SIDES], const struct pubkey funding_pubkey[NUM_SIDES],
const u8 *funding_wscript, const u8 *funding_wscript,
@ -340,7 +344,7 @@ receive_offer(struct per_peer_state *pps,
* specified in [BOLT #3](03-transactions.md#closing-transaction): * specified in [BOLT #3](03-transactions.md#closing-transaction):
* - MUST fail the connection. * - MUST fail the connection.
*/ */
tx = close_tx(tmpctx, pps, channel_id, tx = close_tx(tmpctx, chainparams, pps, channel_id,
scriptpubkey, scriptpubkey,
funding_txid, funding_txid,
funding_txout, funding_txout,
@ -369,7 +373,7 @@ receive_offer(struct per_peer_state *pps,
* `dust_limit_satoshis`. * `dust_limit_satoshis`.
* - MAY eliminate its own output. * - MAY eliminate its own output.
*/ */
trimmed = close_tx(tmpctx, pps, channel_id, trimmed = close_tx(tmpctx, chainparams, pps, channel_id,
scriptpubkey, scriptpubkey,
funding_txid, funding_txid,
funding_txout, funding_txout,
@ -551,6 +555,7 @@ int main(int argc, char *argv[])
u8 *channel_reestablish; u8 *channel_reestablish;
struct secret last_remote_per_commit_secret; struct secret last_remote_per_commit_secret;
struct bitcoin_blkid chain_hash; struct bitcoin_blkid chain_hash;
const struct chainparams *chainparams;
subdaemon_setup(argc, argv); subdaemon_setup(argc, argv);
@ -583,6 +588,7 @@ int main(int argc, char *argv[])
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */ /* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */
per_peer_state_set_fds(pps, 3, 4, 5); per_peer_state_set_fds(pps, 3, 4, 5);
chainparams = chainparams_by_chainhash(&chain_hash);
status_trace("out = %s/%s", status_trace("out = %s/%s",
type_to_string(tmpctx, struct amount_sat, &out[LOCAL]), type_to_string(tmpctx, struct amount_sat, &out[LOCAL]),
@ -624,7 +630,7 @@ int main(int argc, char *argv[])
whose_turn = funder; whose_turn = funder;
for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) { for (size_t i = 0; i < 2; i++, whose_turn = !whose_turn) {
if (whose_turn == LOCAL) { if (whose_turn == LOCAL) {
send_offer(pps, send_offer(pps, chainparams,
&channel_id, funding_pubkey, &channel_id, funding_pubkey,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding, out, funder, funding, out, funder,
@ -642,7 +648,7 @@ int main(int argc, char *argv[])
struct amount_sat, struct amount_sat,
&offer[LOCAL])); &offer[LOCAL]));
offer[REMOTE] offer[REMOTE]
= receive_offer(pps, = receive_offer(pps, chainparams,
&channel_id, funding_pubkey, &channel_id, funding_pubkey,
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, scriptpubkey, &funding_txid,
@ -671,7 +677,7 @@ int main(int argc, char *argv[])
&channel_id, &channel_id,
&feerange, offer[REMOTE], &feerange, offer[REMOTE],
min_fee_to_accept); min_fee_to_accept);
send_offer(pps, &channel_id, send_offer(pps, chainparams, &channel_id,
funding_pubkey, funding_pubkey,
scriptpubkey, &funding_txid, funding_txout, scriptpubkey, &funding_txid, funding_txout,
funding, out, funder, funding, out, funder,
@ -684,7 +690,7 @@ int main(int argc, char *argv[])
" theirs was %"PRIu64" satoshi,", " theirs was %"PRIu64" satoshi,",
offer[LOCAL], offer[REMOTE]); offer[LOCAL], offer[REMOTE]);
offer[REMOTE] offer[REMOTE]
= receive_offer(pps, &channel_id, = receive_offer(pps, chainparams, &channel_id,
funding_pubkey, funding_pubkey,
funding_wscript, funding_wscript,
scriptpubkey, &funding_txid, scriptpubkey, &funding_txid,

3
common/close_tx.c

@ -5,6 +5,7 @@
#include <assert.h> #include <assert.h>
struct bitcoin_tx *create_close_tx(const tal_t *ctx, struct bitcoin_tx *create_close_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const u8 *our_script, const u8 *our_script,
const u8 *their_script, const u8 *their_script,
const struct bitcoin_txid *anchor_txid, const struct bitcoin_txid *anchor_txid,
@ -33,7 +34,7 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx,
* * txin count: 1 * * txin count: 1
*/ */
/* Now create close tx: one input, two outputs. */ /* Now create close tx: one input, two outputs. */
tx = bitcoin_tx(ctx, 1, 2); tx = bitcoin_tx(ctx, chainparams, 1, 2);
/* Our input spends the anchor tx output. */ /* Our input spends the anchor tx output. */
bitcoin_tx_add_input(tx, anchor_txid, anchor_index, bitcoin_tx_add_input(tx, anchor_txid, anchor_index,

3
common/close_tx.h

@ -1,6 +1,8 @@
#ifndef LIGHTNING_COMMON_CLOSE_TX_H #ifndef LIGHTNING_COMMON_CLOSE_TX_H
#define LIGHTNING_COMMON_CLOSE_TX_H #define LIGHTNING_COMMON_CLOSE_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/tx.h>
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <common/amount.h> #include <common/amount.h>
@ -10,6 +12,7 @@ struct pubkey;
/* Create close tx to spend the anchor tx output; doesn't fill in /* Create close tx to spend the anchor tx output; doesn't fill in
* input scriptsig. */ * input scriptsig. */
struct bitcoin_tx *create_close_tx(const tal_t *ctx, struct bitcoin_tx *create_close_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const u8 *our_script, const u8 *our_script,
const u8 *their_script, const u8 *their_script,
const struct bitcoin_txid *anchor_txid, const struct bitcoin_txid *anchor_txid,

3
common/funding_tx.c

@ -12,6 +12,7 @@
#endif #endif
struct bitcoin_tx *funding_tx(const tal_t *ctx, struct bitcoin_tx *funding_tx(const tal_t *ctx,
const struct chainparams *chainparams,
u16 *outnum, u16 *outnum,
const struct utxo **utxomap, const struct utxo **utxomap,
struct amount_sat funding, struct amount_sat funding,
@ -25,7 +26,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
bool has_change = !amount_sat_eq(change, AMOUNT_SAT(0)); bool has_change = !amount_sat_eq(change, AMOUNT_SAT(0));
tx = tx_spending_utxos(ctx, utxomap, bip32_base, has_change); tx = tx_spending_utxos(ctx, chainparams, utxomap, bip32_base, has_change);
wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey); wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey);

3
common/funding_tx.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_COMMON_FUNDING_TX_H #ifndef LIGHTNING_COMMON_FUNDING_TX_H
#define LIGHTNING_COMMON_FUNDING_TX_H #define LIGHTNING_COMMON_FUNDING_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <common/amount.h> #include <common/amount.h>
@ -14,6 +15,7 @@ struct utxo;
/** /**
* funding_tx: create a P2WSH funding transaction for a channel. * funding_tx: create a P2WSH funding transaction for a channel.
* @ctx: context to tal from. * @ctx: context to tal from.
* @chainparams: (in) the params for the resulting transaction.
* @outnum: (out) txout (0 or 1) which is the funding output. * @outnum: (out) txout (0 or 1) which is the funding output.
* @utxomap: (in/out) tal_arr of UTXO pointers to spend (permuted to match) * @utxomap: (in/out) tal_arr of UTXO pointers to spend (permuted to match)
* @funding: (in) satoshis to output. * @funding: (in) satoshis to output.
@ -33,6 +35,7 @@ struct utxo;
* a special case because of the P2SH inputs. * a special case because of the P2SH inputs.
*/ */
struct bitcoin_tx *funding_tx(const tal_t *ctx, struct bitcoin_tx *funding_tx(const tal_t *ctx,
const struct chainparams *chainparams,
u16 *outnum, u16 *outnum,
const struct utxo **utxomap, const struct utxo **utxomap,
struct amount_sat funding, struct amount_sat funding,

14
common/htlc_tx.c

@ -5,6 +5,7 @@
#include <common/keyset.h> #include <common/keyset.h>
static struct bitcoin_tx *htlc_tx(const tal_t *ctx, static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *commit_txid, const struct bitcoin_txid *commit_txid,
unsigned int commit_output_number, unsigned int commit_output_number,
struct amount_msat msat, struct amount_msat msat,
@ -14,7 +15,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
struct amount_sat htlc_fee, struct amount_sat htlc_fee,
u32 locktime) u32 locktime)
{ {
struct bitcoin_tx *tx = bitcoin_tx(ctx, 1, 1); struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams, 1, 1);
u8 *wscript; u8 *wscript;
struct amount_sat amount; struct amount_sat amount;
@ -68,6 +69,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
} }
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx, struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *commit_txid, const struct bitcoin_txid *commit_txid,
unsigned int commit_output_number, unsigned int commit_output_number,
struct amount_msat htlc_msatoshi, struct amount_msat htlc_msatoshi,
@ -78,7 +80,7 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout * * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
*/ */
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi, return htlc_tx(ctx, chainparams, commit_txid, commit_output_number, htlc_msatoshi,
to_self_delay, to_self_delay,
&keyset->self_revocation_key, &keyset->self_revocation_key,
&keyset->self_delayed_payment_key, &keyset->self_delayed_payment_key,
@ -112,6 +114,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
} }
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *commit_txid, const struct bitcoin_txid *commit_txid,
unsigned int commit_output_number, unsigned int commit_output_number,
struct amount_msat htlc_msatoshi, struct amount_msat htlc_msatoshi,
@ -123,12 +126,11 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout * * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
*/ */
return htlc_tx(ctx, commit_txid, commit_output_number, htlc_msatoshi, return htlc_tx(ctx, chainparams, commit_txid, commit_output_number,
to_self_delay, htlc_msatoshi, to_self_delay,
&keyset->self_revocation_key, &keyset->self_revocation_key,
&keyset->self_delayed_payment_key, &keyset->self_delayed_payment_key,
htlc_timeout_fee(feerate_per_kw), htlc_timeout_fee(feerate_per_kw), cltv_expiry);
cltv_expiry);
} }
/* Fill in the witness for HTLC-timeout tx produced above. */ /* Fill in the witness for HTLC-timeout tx produced above. */

3
common/htlc_tx.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_COMMON_HTLC_TX_H #ifndef LIGHTNING_COMMON_HTLC_TX_H
#define LIGHTNING_COMMON_HTLC_TX_H #define LIGHTNING_COMMON_HTLC_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <common/amount.h> #include <common/amount.h>
#include <common/htlc.h> #include <common/htlc.h>
@ -38,6 +39,7 @@ static inline struct amount_sat htlc_success_fee(u32 feerate_per_kw)
/* Create HTLC-success tx to spend a received HTLC commitment tx /* Create HTLC-success tx to spend a received HTLC commitment tx
* output; doesn't fill in input witness. */ * output; doesn't fill in input witness. */
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx, struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *commit_txid, const struct bitcoin_txid *commit_txid,
unsigned int commit_output_number, unsigned int commit_output_number,
struct amount_msat htlc_msatoshi, struct amount_msat htlc_msatoshi,
@ -58,6 +60,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
/* Create HTLC-timeout tx to spend an offered HTLC commitment tx /* Create HTLC-timeout tx to spend an offered HTLC commitment tx
* output; doesn't fill in input witness. */ * output; doesn't fill in input witness. */
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *commit_txid, const struct bitcoin_txid *commit_txid,
unsigned int commit_output_number, unsigned int commit_output_number,
struct amount_msat htlc_msatoshi, struct amount_msat htlc_msatoshi,

3
common/initial_channel.c

@ -93,7 +93,8 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
&channel->funding_pubkey[side], &channel->funding_pubkey[side],
&channel->funding_pubkey[!side]); &channel->funding_pubkey[!side]);
return initial_commit_tx(ctx, &channel->funding_txid, return initial_commit_tx(ctx, channel->chainparams,
&channel->funding_txid,
channel->funding_txout, channel->funding_txout,
channel->funding, channel->funding,
channel->funder, channel->funder,

3
common/initial_commit_tx.c

@ -60,6 +60,7 @@ u8 *to_self_wscript(const tal_t *ctx,
} }
struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,
@ -146,7 +147,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
/* Worst-case sizing: both to-local and to-remote outputs. */ /* Worst-case sizing: both to-local and to-remote outputs. */
tx = bitcoin_tx(ctx, 1, untrimmed + 2); tx = bitcoin_tx(ctx, chainparams, 1, untrimmed + 2);
/* This could be done in a single loop, but we follow the BOLT /* This could be done in a single loop, but we follow the BOLT
* literally to make comments in test vectors clearer. */ * literally to make comments in test vectors clearer. */

3
common/initial_commit_tx.h

@ -2,6 +2,7 @@
#ifndef LIGHTNING_COMMON_INITIAL_COMMIT_TX_H #ifndef LIGHTNING_COMMON_INITIAL_COMMIT_TX_H
#define LIGHTNING_COMMON_INITIAL_COMMIT_TX_H #define LIGHTNING_COMMON_INITIAL_COMMIT_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <common/amount.h> #include <common/amount.h>
#include <common/htlc.h> #include <common/htlc.h>
@ -52,6 +53,7 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
/** /**
* initial_commit_tx: create (unsigned) commitment tx to spend the funding tx output * initial_commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from. * @ctx: context to allocate transaction and @htlc_map from.
* @chainparams: Params for the resulting transactions
* @funding_txid, @funding_out, @funding: funding outpoint. * @funding_txid, @funding_out, @funding: funding outpoint.
* @funder: is the LOCAL or REMOTE paying the fee? * @funder: is the LOCAL or REMOTE paying the fee?
* @keyset: keys derived for this commit tx. * @keyset: keys derived for this commit tx.
@ -69,6 +71,7 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
* transaction, so we carefully use the terms "self" and "other" here. * transaction, so we carefully use the terms "self" and "other" here.
*/ */
struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct bitcoin_txid *funding_txid, const struct bitcoin_txid *funding_txid,
unsigned int funding_txout, unsigned int funding_txout,
struct amount_sat funding, struct amount_sat funding,

5
common/test/run-funding_tx.c

@ -110,6 +110,7 @@ int main(void)
struct bitcoin_signature sig; struct bitcoin_signature sig;
struct bitcoin_address addr; struct bitcoin_address addr;
struct amount_sat tmpamt; struct amount_sat tmpamt;
const struct chainparams *chainparams = chainparams_for_network("bitcoin");
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN); | SECP256K1_CONTEXT_SIGN);
@ -122,6 +123,7 @@ int main(void)
input = bitcoin_tx_from_hex(tmpctx, input = bitcoin_tx_from_hex(tmpctx,
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000", "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000",
strlen("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000")); strlen("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000"));
input->chainparams = chainparams_for_network("bitcoin");
assert(input); assert(input);
/* BOLT #3: /* BOLT #3:
@ -172,7 +174,8 @@ int main(void)
if (!amount_sat_sub(&change, utxo.amount, funding_sat) if (!amount_sat_sub(&change, utxo.amount, funding_sat)
|| !amount_sat_sub(&change, change, fee)) || !amount_sat_sub(&change, change, fee))
abort(); abort();
funding = funding_tx(tmpctx, &funding_outnum, utxomap, funding = funding_tx(tmpctx, chainparams,
&funding_outnum, utxomap,
funding_sat, funding_sat,
&local_funding_pubkey, &local_funding_pubkey,
&remote_funding_pubkey, &remote_funding_pubkey,

3
common/utxo.c

@ -49,6 +49,7 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
} }
struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx, struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx,
const struct chainparams *chainparams,
const struct utxo **utxos, const struct utxo **utxos,
const struct ext_key *bip32_base, const struct ext_key *bip32_base,
bool add_change_output) bool add_change_output)
@ -56,7 +57,7 @@ struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx,
struct pubkey key; struct pubkey key;
u8 *script; u8 *script;
size_t outcount = add_change_output ? 2 : 1; size_t outcount = add_change_output ? 2 : 1;
struct bitcoin_tx *tx = bitcoin_tx(ctx, tal_count(utxos), outcount); struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams, tal_count(utxos), outcount);
for (size_t i = 0; i < tal_count(utxos); i++) { for (size_t i = 0; i < tal_count(utxos); i++) {
if (utxos[i]->is_p2sh && bip32_base) { if (utxos[i]->is_p2sh && bip32_base) {

2
common/utxo.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_COMMON_UTXO_H #ifndef LIGHTNING_COMMON_UTXO_H
#define LIGHTNING_COMMON_UTXO_H #define LIGHTNING_COMMON_UTXO_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/pubkey.h> #include <bitcoin/pubkey.h>
#include <bitcoin/shadouble.h> #include <bitcoin/shadouble.h>
#include <bitcoin/tx.h> #include <bitcoin/tx.h>
@ -46,6 +47,7 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max);
/* Create a tx, and populate inputs from utxos */ /* Create a tx, and populate inputs from utxos */
struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx, struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx,
const struct chainparams *chainparams,
const struct utxo **utxos, const struct utxo **utxos,
const struct ext_key *bip32_base, const struct ext_key *bip32_base,
bool add_change_output); bool add_change_output);

3
common/withdraw_tx.c

@ -9,6 +9,7 @@
#include <wally_bip32.h> #include <wally_bip32.h>
struct bitcoin_tx *withdraw_tx(const tal_t *ctx, struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct utxo **utxos, const struct utxo **utxos,
const u8 *destination, const u8 *destination,
struct amount_sat withdraw_amount, struct amount_sat withdraw_amount,
@ -19,7 +20,7 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
{ {
struct bitcoin_tx *tx; struct bitcoin_tx *tx;
tx = tx_spending_utxos(ctx, utxos, bip32_base, tx = tx_spending_utxos(ctx, chainparams, utxos, bip32_base,
!amount_sat_eq(change, AMOUNT_SAT(0))); !amount_sat_eq(change, AMOUNT_SAT(0)));
bitcoin_tx_add_output(tx, destination, &withdraw_amount); bitcoin_tx_add_output(tx, destination, &withdraw_amount);

3
common/withdraw_tx.h

@ -1,6 +1,7 @@
#ifndef LIGHTNING_COMMON_WITHDRAW_TX_H #ifndef LIGHTNING_COMMON_WITHDRAW_TX_H
#define LIGHTNING_COMMON_WITHDRAW_TX_H #define LIGHTNING_COMMON_WITHDRAW_TX_H
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>
#include <common/amount.h> #include <common/amount.h>
@ -16,6 +17,7 @@ struct utxo;
* withdraw_tx - Create a p2pkh withdrawal transaction * withdraw_tx - Create a p2pkh withdrawal transaction
* *
* @ctx: context to tal from. * @ctx: context to tal from.
* @chainparams: (in) the params for the created transaction.
* @utxos: (in/out) tal_arr of UTXO pointers to spend (permuted to match) * @utxos: (in/out) tal_arr of UTXO pointers to spend (permuted to match)
* @destination: (in) tal_arr of u8, scriptPubKey to send to. * @destination: (in) tal_arr of u8, scriptPubKey to send to.
* @amount: (in) satoshis to send to the destination * @amount: (in) satoshis to send to the destination
@ -25,6 +27,7 @@ struct utxo;
* @change_outnum: (out) set to output index of change output or -1 if none, unless NULL. * @change_outnum: (out) set to output index of change output or -1 if none, unless NULL.
*/ */
struct bitcoin_tx *withdraw_tx(const tal_t *ctx, struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct chainparams *chainparams,
const struct utxo **utxos, const struct utxo **utxos,
const u8 *destination, const u8 *destination,
struct amount_sat withdraw_amount, struct amount_sat withdraw_amount,

5
devtools/mkcommit.c

@ -247,6 +247,7 @@ int main(int argc, char *argv[])
const struct htlc **htlcmap; const struct htlc **htlcmap;
struct privkey local_htlc_privkey, remote_htlc_privkey; struct privkey local_htlc_privkey, remote_htlc_privkey;
struct pubkey local_htlc_pubkey, remote_htlc_pubkey; struct pubkey local_htlc_pubkey, remote_htlc_pubkey;
const struct chainparams *chainparams = chainparams_for_network("bitcoin");
setup_locale(); setup_locale();
@ -367,7 +368,7 @@ int main(int argc, char *argv[])
if (!per_commit_point(&localseed, &local_per_commit_point, commitnum)) if (!per_commit_point(&localseed, &local_per_commit_point, commitnum))
errx(1, "Bad deriving local per-commitment-point"); errx(1, "Bad deriving local per-commitment-point");
local_txs = channel_txs(NULL, &htlcmap, &wscripts, channel, local_txs = channel_txs(chainparams, NULL, &htlcmap, &wscripts, channel,
&local_per_commit_point, commitnum, LOCAL); &local_per_commit_point, commitnum, LOCAL);
printf("## local_commitment\n" printf("## local_commitment\n"
@ -468,7 +469,7 @@ int main(int argc, char *argv[])
/* Create the remote commitment tx */ /* Create the remote commitment tx */
if (!per_commit_point(&remoteseed, &remote_per_commit_point, commitnum)) if (!per_commit_point(&remoteseed, &remote_per_commit_point, commitnum))
errx(1, "Bad deriving remote per-commitment-point"); errx(1, "Bad deriving remote per-commitment-point");
remote_txs = channel_txs(NULL, &htlcmap, &wscripts, channel, remote_txs = channel_txs(chainparams, NULL, &htlcmap, &wscripts, channel,
&remote_per_commit_point, commitnum, REMOTE); &remote_per_commit_point, commitnum, REMOTE);
remote_txs[0]->input_amounts[0] remote_txs[0]->input_amounts[0]
= tal_dup(remote_txs[0], struct amount_sat, &funding_amount); = tal_dup(remote_txs[0], struct amount_sat, &funding_amount);

3
devtools/mkfunding.c

@ -46,6 +46,7 @@ int main(int argc, char *argv[])
const struct utxo **utxomap; const struct utxo **utxomap;
struct bitcoin_signature sig; struct bitcoin_signature sig;
struct bitcoin_txid txid; struct bitcoin_txid txid;
const struct chainparams *chainparams = chainparams_for_network("bitcoin");
setup_locale(); setup_locale();
@ -106,7 +107,7 @@ int main(int argc, char *argv[])
utxomap[0] = &input; utxomap[0] = &input;
/* No change output, so we don't need a bip32 base. */ /* No change output, so we don't need a bip32 base. */
tx = funding_tx(NULL, &outnum, utxomap, funding_amount, tx = funding_tx(NULL, chainparams, &outnum, utxomap, funding_amount,
&funding_localkey, &funding_remotekey, &funding_localkey, &funding_remotekey,
AMOUNT_SAT(0), NULL, NULL); AMOUNT_SAT(0), NULL, NULL);

22
hsmd/hsmd.c

@ -102,6 +102,9 @@ struct client {
/* What is this client allowed to ask for? */ /* What is this client allowed to ask for? */
u64 capabilities; u64 capabilities;
/* Params to apply to all transactions for this client */
const struct chainparams *chainparams;
}; };
/*~ We keep a map of nonzero dbid -> clients, mainly for leak detection. /*~ We keep a map of nonzero dbid -> clients, mainly for leak detection.
@ -206,6 +209,7 @@ static void destroy_client(struct client *c)
} }
static struct client *new_client(const tal_t *ctx, static struct client *new_client(const tal_t *ctx,
const struct chainparams *chainparams,
const struct node_id *id, const struct node_id *id,
u64 dbid, u64 dbid,
const u64 capabilities, const u64 capabilities,
@ -227,6 +231,8 @@ static struct client *new_client(const tal_t *ctx,
c->dbid = dbid; c->dbid = dbid;
c->capabilities = capabilities; c->capabilities = capabilities;
c->chainparams = chainparams;
/*~ This is the core of ccan/io: the connection creation calls a /*~ This is the core of ccan/io: the connection creation calls a
* callback which returns the initial plan to execute: in our case, * callback which returns the initial plan to execute: in our case,
* read a message.*/ * read a message.*/
@ -593,6 +599,10 @@ static struct io_plan *init_hsm(struct io_conn *conn,
dev_force_channel_secrets = secrets; dev_force_channel_secrets = secrets;
dev_force_channel_secrets_shaseed = shaseed; dev_force_channel_secrets_shaseed = shaseed;
#endif #endif
/* Once we have read the init message we know which params the master
* will use */
c->chainparams = chainparams_by_chainhash(&chain_hash);
maybe_create_new_hsm(); maybe_create_new_hsm();
load_hsm(); load_hsm();
@ -1339,7 +1349,7 @@ static struct io_plan *pass_client_hsmfd(struct io_conn *conn,
strerror(errno)); strerror(errno));
status_trace("new_client: %"PRIu64, dbid); status_trace("new_client: %"PRIu64, dbid);
new_client(c, &id, dbid, capabilities, fds[0]); new_client(c, c->chainparams, &id, dbid, capabilities, fds[0]);
/*~ We stash this in a global, because we need to get both the fd and /*~ We stash this in a global, because we need to get both the fd and
* the client pointer to the callback. The other way would be to * the client pointer to the callback. The other way would be to
@ -1471,7 +1481,7 @@ static struct io_plan *handle_sign_funding_tx(struct io_conn *conn,
} else } else
changekey = NULL; changekey = NULL;
tx = funding_tx(tmpctx, &outnum, tx = funding_tx(tmpctx, c->chainparams, &outnum,
/*~ For simplicity, our generated code is not const /*~ For simplicity, our generated code is not const
* correct. The C rules around const and * correct. The C rules around const and
* pointer-to-pointer are a bit weird, so we use * pointer-to-pointer are a bit weird, so we use
@ -1508,9 +1518,9 @@ static struct io_plan *handle_sign_withdrawal_tx(struct io_conn *conn,
return bad_req_fmt(conn, c, msg_in, return bad_req_fmt(conn, c, msg_in,
"Failed to get key %u", change_keyindex); "Failed to get key %u", change_keyindex);
tx = withdraw_tx(tmpctx, cast_const2(const struct utxo **, utxos), tx = withdraw_tx(tmpctx, c->chainparams,
scriptpubkey, satoshi_out, cast_const2(const struct utxo **, utxos), scriptpubkey,
&changekey, change_out, NULL, NULL); satoshi_out, &changekey, change_out, NULL, NULL);
sign_all_inputs(tx, utxos); sign_all_inputs(tx, utxos);
@ -1854,7 +1864,7 @@ int main(int argc, char *argv[])
status_setup_async(status_conn); status_setup_async(status_conn);
uintmap_init(&clients); uintmap_init(&clients);
master = new_client(NULL, NULL, 0, HSM_CAP_MASTER | HSM_CAP_SIGN_GOSSIP, master = new_client(NULL, NULL, NULL, 0, HSM_CAP_MASTER | HSM_CAP_SIGN_GOSSIP,
REQ_FD); REQ_FD);
/* First client == lightningd. */ /* First client == lightningd. */

4
lightningd/opening_control.c

@ -370,6 +370,7 @@ static bool compose_and_broadcast_tx(struct lightningd *ld,
struct bitcoin_tx *fundingtx; struct bitcoin_tx *fundingtx;
struct amount_sat change; struct amount_sat change;
struct bitcoin_txid funding_txid; struct bitcoin_txid funding_txid;
const struct chainparams *chainparams = get_chainparams(ld);
/* Generate the funding tx. */ /* Generate the funding tx. */
if (!amount_sat_eq(fc->wtx->change, AMOUNT_SAT(0)) if (!amount_sat_eq(fc->wtx->change, AMOUNT_SAT(0))
@ -377,7 +378,7 @@ static bool compose_and_broadcast_tx(struct lightningd *ld,
&changekey, fc->wtx->change_key_index)) &changekey, fc->wtx->change_key_index))
fatal("Error deriving change key %u", fc->wtx->change_key_index); fatal("Error deriving change key %u", fc->wtx->change_key_index);
fundingtx = funding_tx(tmpctx, &funding_outnum, fundingtx = funding_tx(tmpctx, chainparams, &funding_outnum,
fc->wtx->utxos, fc->wtx->amount, fc->wtx->utxos, fc->wtx->amount,
&fc->uc->local_funding_pubkey, &fc->uc->local_funding_pubkey,
&channel_info->remote_fundingkey, &channel_info->remote_fundingkey,
@ -453,6 +454,7 @@ static bool compose_and_broadcast_tx(struct lightningd *ld,
if (!fromwire_hsm_sign_funding_reply(tmpctx, msg, &fundingtx)) if (!fromwire_hsm_sign_funding_reply(tmpctx, msg, &fundingtx))
fatal("HSM gave bad sign_funding_reply %s", fatal("HSM gave bad sign_funding_reply %s",
tal_hex(msg, resp)); tal_hex(msg, resp));
fundingtx->chainparams = chainparams;
/* Extract the change output and add it to the DB */ /* Extract the change output and add it to the DB */
wallet_extract_owned_outputs(ld->wallet, fundingtx, NULL, &change); wallet_extract_owned_outputs(ld->wallet, fundingtx, NULL, &change);

117
onchaind/onchaind.c

@ -105,6 +105,8 @@ struct tracked_output {
/* If it is resolved. */ /* If it is resolved. */
struct resolution *resolved; struct resolution *resolved;
const struct chainparams *chainparams;
}; };
/* We vary feerate until signature they offered matches. */ /* We vary feerate until signature they offered matches. */
@ -305,7 +307,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
u8 *msg; u8 *msg;
u8 **witness; u8 **witness;
tx = bitcoin_tx(ctx, 1, 1); tx = bitcoin_tx(ctx, out->chainparams, 1, 1);
tx->wtx->locktime = locktime; tx->wtx->locktime = locktime;
bitcoin_tx_add_input(tx, &out->txid, out->outnum, to_self_delay, bitcoin_tx_add_input(tx, &out->txid, out->outnum, to_self_delay,
&out->sat, NULL); &out->sat, NULL);
@ -399,16 +401,17 @@ static void hsm_get_per_commitment_point(struct pubkey *per_commitment_point)
} }
static struct tracked_output * static struct tracked_output *
new_tracked_output(struct tracked_output ***outs, new_tracked_output(const struct chainparams *chainparams,
const struct bitcoin_txid *txid, struct tracked_output ***outs,
u32 tx_blockheight, const struct bitcoin_txid *txid,
enum tx_type tx_type, u32 tx_blockheight,
u32 outnum, enum tx_type tx_type,
struct amount_sat sat, u32 outnum,
enum output_type output_type, struct amount_sat sat,
const struct htlc_stub *htlc, enum output_type output_type,
const u8 *wscript, const struct htlc_stub *htlc,
const secp256k1_ecdsa_signature *remote_htlc_sig) const u8 *wscript,
const secp256k1_ecdsa_signature *remote_htlc_sig)
{ {
struct tracked_output *out = tal(*outs, struct tracked_output); struct tracked_output *out = tal(*outs, struct tracked_output);
@ -427,6 +430,7 @@ static struct tracked_output *
out->output_type = output_type; out->output_type = output_type;
out->proposal = NULL; out->proposal = NULL;
out->resolved = NULL; out->resolved = NULL;
out->chainparams = chainparams;
if (htlc) if (htlc)
out->htlc = *htlc; out->htlc = *htlc;
out->wscript = tal_steal(out, wscript); out->wscript = tal_steal(out, wscript);
@ -900,7 +904,8 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out,
&preimage))); &preimage)));
} }
static void resolve_htlc_tx(struct tracked_output ***outs, static void resolve_htlc_tx(const struct chainparams *chainparams,
struct tracked_output ***outs,
size_t out_index, size_t out_index,
const struct bitcoin_tx *htlc_tx, const struct bitcoin_tx *htlc_tx,
const struct bitcoin_txid *htlc_txid, const struct bitcoin_txid *htlc_txid,
@ -925,7 +930,7 @@ static void resolve_htlc_tx(struct tracked_output ***outs,
* output. * output.
*/ */
amt = bitcoin_tx_output_get_amount(htlc_tx, 0); amt = bitcoin_tx_output_get_amount(htlc_tx, 0);
out = new_tracked_output(outs, htlc_txid, tx_blockheight, out = new_tracked_output(chainparams, outs, htlc_txid, tx_blockheight,
(*outs)[out_index]->resolved->tx_type, (*outs)[out_index]->resolved->tx_type,
0, amt, 0, amt,
DELAYED_OUTPUT_TO_US, DELAYED_OUTPUT_TO_US,
@ -981,7 +986,8 @@ static void onchain_transaction_annotate(const struct bitcoin_txid *txid,
wire_sync_write(REQ_FD, take(msg)); wire_sync_write(REQ_FD, take(msg));
} }
/* An output has been spent: see if it resolves something we care about. */ /* An output has been spent: see if it resolves something we care about. */
static void output_spent(struct tracked_output ***outs, static void output_spent(const struct chainparams *chainparams,
struct tracked_output ***outs,
const struct bitcoin_tx *tx, const struct bitcoin_tx *tx,
u32 input_num, u32 input_num,
u32 tx_blockheight) u32 tx_blockheight)
@ -1008,7 +1014,7 @@ static void output_spent(struct tracked_output ***outs,
/* If it's our htlc tx, we need to resolve that, too. */ /* If it's our htlc tx, we need to resolve that, too. */
if (out->resolved->tx_type == OUR_HTLC_SUCCESS_TX if (out->resolved->tx_type == OUR_HTLC_SUCCESS_TX
|| out->resolved->tx_type == OUR_HTLC_TIMEOUT_TX) || out->resolved->tx_type == OUR_HTLC_TIMEOUT_TX)
resolve_htlc_tx(outs, i, tx, &txid, resolve_htlc_tx(chainparams, outs, i, tx, &txid,
tx_blockheight); tx_blockheight);
return; return;
} }
@ -1194,7 +1200,8 @@ static void tx_new_depth(struct tracked_output **outs,
* - MUST NOT *resolve* the output by spending it. * - MUST NOT *resolve* the output by spending it.
*/ */
/* Master makes sure we only get told preimages once other node is committed. */ /* Master makes sure we only get told preimages once other node is committed. */
static void handle_preimage(struct tracked_output **outs, static void handle_preimage(const struct chainparams *chainparams,
struct tracked_output **outs,
const struct preimage *preimage) const struct preimage *preimage)
{ {
size_t i; size_t i;
@ -1249,7 +1256,9 @@ static void handle_preimage(struct tracked_output **outs,
type_to_string(tmpctx, type_to_string(tmpctx,
struct amount_sat, struct amount_sat,
&outs[i]->sat)); &outs[i]->sat));
tx = htlc_success_tx(outs[i], &outs[i]->txid, tx = htlc_success_tx(outs[i],
chainparams,
&outs[i]->txid,
outs[i]->outnum, outs[i]->outnum,
htlc_amount, htlc_amount,
to_self_delay[LOCAL], to_self_delay[LOCAL],
@ -1347,7 +1356,8 @@ static bool handle_dev_memleak(struct tracked_output **outs, const u8 *msg)
* - MUST monitor the blockchain for transactions that spend any output that * - MUST monitor the blockchain for transactions that spend any output that
* is NOT *irrevocably resolved*. * is NOT *irrevocably resolved*.
*/ */
static void wait_for_resolved(struct tracked_output **outs) static void wait_for_resolved(const struct chainparams *chainparams,
struct tracked_output **outs)
{ {
billboard_update(outs); billboard_update(outs);
@ -1365,9 +1375,9 @@ static void wait_for_resolved(struct tracked_output **outs)
tx_new_depth(outs, &txid, depth); tx_new_depth(outs, &txid, depth);
else if (fromwire_onchain_spent(msg, msg, &tx, &input_num, else if (fromwire_onchain_spent(msg, msg, &tx, &input_num,
&tx_blockheight)) &tx_blockheight))
output_spent(&outs, tx, input_num, tx_blockheight); output_spent(chainparams, &outs, tx, input_num, tx_blockheight);
else if (fromwire_onchain_known_preimage(msg, &preimage)) else if (fromwire_onchain_known_preimage(msg, &preimage))
handle_preimage(outs, &preimage); handle_preimage(chainparams, outs, &preimage);
else if (!handle_dev_memleak(outs, msg)) else if (!handle_dev_memleak(outs, msg))
master_badmsg(-1, msg); master_badmsg(-1, msg);
@ -1387,7 +1397,8 @@ static void init_reply(const char *what)
peer_billboard(true, what); peer_billboard(true, what);
} }
static void handle_mutual_close(const struct bitcoin_txid *txid, static void handle_mutual_close(const struct chainparams *chainparams,
const struct bitcoin_txid *txid,
struct tracked_output **outs) struct tracked_output **outs)
{ {
init_reply("Tracking mutual close transaction"); init_reply("Tracking mutual close transaction");
@ -1402,7 +1413,7 @@ static void handle_mutual_close(const struct bitcoin_txid *txid,
*/ */
resolved_by_other(outs[0], txid, MUTUAL_CLOSE); resolved_by_other(outs[0], txid, MUTUAL_CLOSE);
wait_for_resolved(outs); wait_for_resolved(chainparams, outs);
} }
static u8 **derive_htlc_scripts(const struct htlc_stub *htlcs, enum side side) static u8 **derive_htlc_scripts(const struct htlc_stub *htlcs, enum side side)
@ -1432,7 +1443,8 @@ static u8 **derive_htlc_scripts(const struct htlc_stub *htlcs, enum side side)
return htlc_scripts; return htlc_scripts;
} }
static size_t resolve_our_htlc_ourcommit(struct tracked_output *out, static size_t resolve_our_htlc_ourcommit(const struct chainparams *chainparams,
struct tracked_output *out,
const size_t *matches, const size_t *matches,
const struct htlc_stub *htlcs, const struct htlc_stub *htlcs,
u8 **htlc_scripts) u8 **htlc_scripts)
@ -1463,7 +1475,8 @@ static size_t resolve_our_htlc_ourcommit(struct tracked_output *out,
* - MUST *resolve* the output by spending it using the * - MUST *resolve* the output by spending it using the
* HTLC-timeout transaction. * HTLC-timeout transaction.
*/ */
tx = htlc_timeout_tx(tmpctx, &out->txid, out->outnum, tx = htlc_timeout_tx(tmpctx, chainparams,
&out->txid, out->outnum,
htlc_amount, htlc_amount,
htlcs[matches[i]].cltv_expiry, htlcs[matches[i]].cltv_expiry,
to_self_delay[LOCAL], 0, keyset); to_self_delay[LOCAL], 0, keyset);
@ -1778,7 +1791,8 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
* node's `to_self_delay` field) before spending * node's `to_self_delay` field) before spending
* the output. * the output.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
OUR_UNILATERAL, i, OUR_UNILATERAL, i,
amt, amt,
DELAYED_OUTPUT_TO_US, DELAYED_OUTPUT_TO_US,
@ -1818,7 +1832,8 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
* node, as `to_remote` is considered *resolved* * node, as `to_remote` is considered *resolved*
* by the commitment transaction itself. * by the commitment transaction itself.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
OUR_UNILATERAL, i, OUR_UNILATERAL, i,
amt, amt,
OUTPUT_TO_THEM, OUTPUT_TO_THEM,
@ -1844,7 +1859,8 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
* in [HTLC Output Handling: Local Commitment, * in [HTLC Output Handling: Local Commitment,
* Local Offers] * Local Offers]
*/ */
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
OUR_UNILATERAL, i, OUR_UNILATERAL, i,
amt, amt,
@ -1852,11 +1868,13 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
NULL, NULL, NULL, NULL,
remote_htlc_sigs); remote_htlc_sigs);
/* Tells us which htlc to use */ /* Tells us which htlc to use */
which_htlc = resolve_our_htlc_ourcommit(out, matches, which_htlc = resolve_our_htlc_ourcommit(tx->chainparams,
out, matches,
htlcs, htlcs,
htlc_scripts); htlc_scripts);
} else { } else {
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
OUR_UNILATERAL, i, OUR_UNILATERAL, i,
amt, amt,
@ -1885,7 +1903,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs, note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately); tell_if_missing, tell_immediately);
wait_for_resolved(outs); wait_for_resolved(tx->chainparams, outs);
} }
/* We produce individual penalty txs. It's less efficient, but avoids them /* We produce individual penalty txs. It's less efficient, but avoids them
@ -2085,7 +2103,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
* - Note: this output is considered *resolved* by * - Note: this output is considered *resolved* by
* the commitment transaction itself. * the commitment transaction itself.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
THEIR_REVOKED_UNILATERAL, THEIR_REVOKED_UNILATERAL,
i, amt, i, amt,
OUTPUT_TO_US, NULL, NULL, NULL); OUTPUT_TO_US, NULL, NULL, NULL);
@ -2109,7 +2128,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
* - MUST *resolve* the _remote node's main output_ by * - MUST *resolve* the _remote node's main output_ by
* spending it using the revocation private key. * spending it using the revocation private key.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
THEIR_REVOKED_UNILATERAL, i, THEIR_REVOKED_UNILATERAL, i,
amt, amt,
DELAYED_OUTPUT_TO_THEM, DELAYED_OUTPUT_TO_THEM,
@ -2136,7 +2156,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
* * spend the *commitment tx* once the HTLC timeout has passed. * * spend the *commitment tx* once the HTLC timeout has passed.
* * spend the *HTLC-success tx*, if the remote node has published it. * * spend the *HTLC-success tx*, if the remote node has published it.
*/ */
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
THEIR_REVOKED_UNILATERAL, i, THEIR_REVOKED_UNILATERAL, i,
amt, amt,
@ -2146,7 +2167,8 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
NULL); NULL);
steal_htlc(out); steal_htlc(out);
} else { } else {
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
THEIR_REVOKED_UNILATERAL, i, THEIR_REVOKED_UNILATERAL, i,
amt, amt,
@ -2168,7 +2190,7 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs, note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately); tell_if_missing, tell_immediately);
wait_for_resolved(outs); wait_for_resolved(tx->chainparams, outs);
} }
static void handle_their_unilateral(const struct bitcoin_tx *tx, static void handle_their_unilateral(const struct bitcoin_tx *tx,
@ -2301,7 +2323,8 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
* - Note: `to_remote` is considered *resolved* by the * - Note: `to_remote` is considered *resolved* by the
* commitment transaction itself. * commitment transaction itself.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
THEIR_UNILATERAL, THEIR_UNILATERAL,
i, amt, i, amt,
OUTPUT_TO_US, NULL, NULL, NULL); OUTPUT_TO_US, NULL, NULL, NULL);
@ -2328,7 +2351,8 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
* - Note: `to_local` is considered *resolved* by the * - Note: `to_local` is considered *resolved* by the
* commitment transaction itself. * commitment transaction itself.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
THEIR_UNILATERAL, i, THEIR_UNILATERAL, i,
amt, amt,
DELAYED_OUTPUT_TO_THEM, DELAYED_OUTPUT_TO_THEM,
@ -2350,7 +2374,8 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
* [HTLC Output Handling: Remote Commitment, * [HTLC Output Handling: Remote Commitment,
* Local Offers] * Local Offers]
*/ */
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
THEIR_UNILATERAL, i, THEIR_UNILATERAL, i,
amt, amt,
@ -2362,7 +2387,8 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
htlcs, htlcs,
htlc_scripts); htlc_scripts);
} else { } else {
out = new_tracked_output(&outs, txid, out = new_tracked_output(tx->chainparams,
&outs, txid,
tx_blockheight, tx_blockheight,
THEIR_UNILATERAL, i, THEIR_UNILATERAL, i,
amt, amt,
@ -2385,7 +2411,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs, note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately); tell_if_missing, tell_immediately);
wait_for_resolved(outs); wait_for_resolved(tx->chainparams, outs);
} }
static void handle_unknown_commitment(const struct bitcoin_tx *tx, static void handle_unknown_commitment(const struct bitcoin_tx *tx,
@ -2435,7 +2461,8 @@ static void handle_unknown_commitment(const struct bitcoin_tx *tx,
* - Note: `to_remote` is considered *resolved* by the * - Note: `to_remote` is considered *resolved* by the
* commitment transaction itself. * commitment transaction itself.
*/ */
out = new_tracked_output(&outs, txid, tx_blockheight, out = new_tracked_output(tx->chainparams,
&outs, txid, tx_blockheight,
UNKNOWN_UNILATERAL, UNKNOWN_UNILATERAL,
i, amt, i, amt,
OUTPUT_TO_US, NULL, NULL, NULL); OUTPUT_TO_US, NULL, NULL, NULL);
@ -2477,7 +2504,7 @@ search_done:
wire_sync_write(REQ_FD, take(msg)); wire_sync_write(REQ_FD, take(msg));
} }
wait_for_resolved(outs); wait_for_resolved(tx->chainparams, outs);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -2538,6 +2565,8 @@ int main(int argc, char *argv[])
master_badmsg(WIRE_ONCHAIN_INIT, msg); master_badmsg(WIRE_ONCHAIN_INIT, msg);
} }
tx->chainparams = chainparams_by_chainhash(&chain_hash);
status_trace("feerate_per_kw = %u", feerate_per_kw); status_trace("feerate_per_kw = %u", feerate_per_kw);
bitcoin_txid(tx, &txid); bitcoin_txid(tx, &txid);
/* We need to keep tx around, but there's only one: not really a leak */ /* We need to keep tx around, but there's only one: not really a leak */
@ -2561,7 +2590,7 @@ int main(int argc, char *argv[])
outs = tal_arr(ctx, struct tracked_output *, 0); outs = tal_arr(ctx, struct tracked_output *, 0);
bitcoin_tx_input_get_txid(tx, 0, &tmptxid); bitcoin_tx_input_get_txid(tx, 0, &tmptxid);
new_tracked_output(&outs, &tmptxid, new_tracked_output(tx->chainparams, &outs, &tmptxid,
0, /* We don't care about funding blockheight */ 0, /* We don't care about funding blockheight */
FUNDING_TRANSACTION, FUNDING_TRANSACTION,
tx->wtx->inputs[0].index, tx->wtx->inputs[0].index,
@ -2586,7 +2615,7 @@ int main(int argc, char *argv[])
* [BOLT #2: Channel Close](02-peer-protocol.md#channel-close)). * [BOLT #2: Channel Close](02-peer-protocol.md#channel-close)).
*/ */
if (is_mutual_close(tx, scriptpubkey[LOCAL], scriptpubkey[REMOTE])) if (is_mutual_close(tx, scriptpubkey[LOCAL], scriptpubkey[REMOTE]))
handle_mutual_close(&txid, outs); handle_mutual_close(tx->chainparams, &txid, outs);
else { else {
/* BOLT #5: /* BOLT #5:
* *

3
onchaind/test/run-grind_feerate.c

@ -64,6 +64,7 @@ u8 *htlc_received_wscript(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "htlc_received_wscript called!\n"); abort(); } { fprintf(stderr, "htlc_received_wscript called!\n"); abort(); }
/* Generated stub for htlc_success_tx */ /* Generated stub for htlc_success_tx */
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx UNNEEDED, struct bitcoin_tx *htlc_success_tx(const tal_t *ctx UNNEEDED,
const struct chainparams *chainparams UNNEEDED,
const struct bitcoin_txid *commit_txid UNNEEDED, const struct bitcoin_txid *commit_txid UNNEEDED,
unsigned int commit_output_number UNNEEDED, unsigned int commit_output_number UNNEEDED,
struct amount_msat htlc_msatoshi UNNEEDED, struct amount_msat htlc_msatoshi UNNEEDED,
@ -73,6 +74,7 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "htlc_success_tx called!\n"); abort(); } { fprintf(stderr, "htlc_success_tx called!\n"); abort(); }
/* Generated stub for htlc_timeout_tx */ /* Generated stub for htlc_timeout_tx */
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx UNNEEDED, struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx UNNEEDED,
const struct chainparams *chainparams UNNEEDED,
const struct bitcoin_txid *commit_txid UNNEEDED, const struct bitcoin_txid *commit_txid UNNEEDED,
unsigned int commit_output_number UNNEEDED, unsigned int commit_output_number UNNEEDED,
struct amount_msat htlc_msatoshi UNNEEDED, struct amount_msat htlc_msatoshi UNNEEDED,
@ -205,6 +207,7 @@ int main(int argc, char *argv[])
strlen("0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000")); strlen("0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000"));
tx->input_amounts[0] = tal(tx, struct amount_sat); tx->input_amounts[0] = tal(tx, struct amount_sat);
*tx->input_amounts[0] = AMOUNT_SAT(700000); *tx->input_amounts[0] = AMOUNT_SAT(700000);
tx->chainparams = chainparams_for_network("bitcoin");
der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01", der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01",
strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01")); strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9" "01"));
if (!signature_from_der(der, tal_count(der), &sig)) if (!signature_from_der(der, tal_count(der), &sig))

2
openingd/openingd.c

@ -1069,7 +1069,7 @@ static u8 *funder_channel(struct state *state,
* it; lightningd will recreate it (and have the HSM sign it) when * it; lightningd will recreate it (and have the HSM sign it) when
* we've completed opening negotiation. * we've completed opening negotiation.
*/ */
funding = funding_tx(state, &state->funding_txout, funding = funding_tx(state, state->chainparams, &state->funding_txout,
cast_const2(const struct utxo **, utxos), cast_const2(const struct utxo **, utxos),
state->funding, state->funding,
&state->our_funding_pubkey, &state->our_funding_pubkey,

3
wallet/walletrpc.c

@ -128,6 +128,7 @@ static struct command_result *broadcast_and_wait(struct command *cmd,
if (!fromwire_hsm_sign_withdrawal_reply(utx, msg, &signed_tx)) if (!fromwire_hsm_sign_withdrawal_reply(utx, msg, &signed_tx))
fatal("HSM gave bad sign_withdrawal_reply %s", fatal("HSM gave bad sign_withdrawal_reply %s",
tal_hex(tmpctx, msg)); tal_hex(tmpctx, msg));
signed_tx->chainparams = utx->tx->chainparams;
/* Sanity check */ /* Sanity check */
bitcoin_txid(signed_tx, &signed_txid); bitcoin_txid(signed_tx, &signed_txid);
@ -199,7 +200,7 @@ static struct command_result *json_prepare_tx(struct command *cmd,
return command_fail(cmd, LIGHTNINGD, "Keys generation failure"); return command_fail(cmd, LIGHTNINGD, "Keys generation failure");
} }
(*utx)->tx = withdraw_tx(*utx, (*utx)->wtx->utxos, (*utx)->tx = withdraw_tx(*utx, get_chainparams(cmd->ld), (*utx)->wtx->utxos,
(*utx)->destination, (*utx)->wtx->amount, (*utx)->destination, (*utx)->wtx->amount,
changekey, (*utx)->wtx->change, changekey, (*utx)->wtx->change,
cmd->ld->wallet->bip32_base, cmd->ld->wallet->bip32_base,

Loading…
Cancel
Save