diff --git a/channeld/channeld.c b/channeld/channeld.c index e4ab88fa0..54058b74b 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -97,7 +97,6 @@ struct peer { */ u64 htlc_id; - struct bitcoin_blkid chain_hash; struct channel_id channel_id; struct channel *channel; @@ -266,8 +265,7 @@ static struct amount_msat advertized_htlc_max(const struct channel *channel) &lower_bound)); } - if (amount_msat_greater(lower_bound_msat, - channel->chainparams->max_payment)) + if (amount_msat_greater(lower_bound_msat, chainparams->max_payment)) /* BOLT #7: * * The origin node: @@ -277,7 +275,7 @@ static struct amount_msat advertized_htlc_max(const struct channel *channel) * - for channels with `chain_hash` identifying the Bitcoin blockchain: * - MUST set this to less than 2^32. */ - lower_bound_msat = channel->chainparams->max_payment; + lower_bound_msat = chainparams->max_payment; return lower_bound_msat; } @@ -407,7 +405,7 @@ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer) &peer->announcement_bitcoin_sigs[first], &peer->announcement_bitcoin_sigs[second], features, - &peer->chain_hash, + &chainparams->genesis_blockhash, &peer->short_channel_ids[LOCAL], &peer->node_ids[first], &peer->node_ids[second], @@ -987,7 +985,7 @@ static secp256k1_ecdsa_signature *calc_commitsigs(const tal_t *ctx, const u8 *msg; secp256k1_ecdsa_signature *htlc_sigs; - txs = channel_txs(tmpctx, peer->channel->chainparams, &htlc_map, + txs = channel_txs(tmpctx, &htlc_map, &wscripts, peer->channel, &peer->remote_per_commit, commit_index, REMOTE); @@ -1406,7 +1404,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg) commit_sig.sighash_type = SIGHASH_ALL; txs = - channel_txs(tmpctx, peer->channel->chainparams, &htlc_map, + channel_txs(tmpctx, &htlc_map, &wscripts, peer->channel, &peer->next_local_per_commit, peer->next_index[LOCAL], LOCAL); @@ -3008,7 +3006,6 @@ static void init_channel(struct peer *peer) } /* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */ per_peer_state_set_fds(peer->pps, 3, 4, 5); - peer->chain_hash = chainparams->genesis_blockhash; status_debug("init %s: remote_per_commit = %s, old_remote_per_commit = %s" " next_idx_local = %"PRIu64 @@ -3051,7 +3048,6 @@ static void init_channel(struct peer *peer) derive_channel_id(&peer->channel_id, &funding_txid, funding_txout); peer->channel = new_full_channel(peer, - &peer->chain_hash, &funding_txid, funding_txout, minimum_depth, diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 2973cc16e..d8a3ba0ba 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -76,7 +76,6 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n, } struct bitcoin_tx *commit_tx(const tal_t *ctx, - const struct chainparams *chainparams, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, diff --git a/channeld/commit_tx.h b/channeld/commit_tx.h index 2ad7c72fa..6b01208c5 100644 --- a/channeld/commit_tx.h +++ b/channeld/commit_tx.h @@ -44,7 +44,6 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs, * transaction, so we carefully use the terms "self" and "other" here. */ struct bitcoin_tx *commit_tx(const tal_t *ctx, - const struct chainparams *chainparams, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 36661b36e..4db50c406 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -33,7 +33,6 @@ static void memleak_help_htlcmap(struct htable *memtable, #endif /* DEVELOPER */ struct channel *new_full_channel(const tal_t *ctx, - const struct bitcoin_blkid *chain_hash, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, @@ -50,7 +49,6 @@ struct channel *new_full_channel(const tal_t *ctx, enum side funder) { struct channel *channel = new_initial_channel(ctx, - chain_hash, funding_txid, funding_txout, minimum_depth, @@ -199,8 +197,7 @@ static bool sum_offered_msatoshis(struct amount_msat *total, return true; } -static void add_htlcs(const struct chainparams *chainparams, - struct bitcoin_tx ***txs, +static void add_htlcs(struct bitcoin_tx ***txs, const u8 ***wscripts, const struct htlc **htlcmap, const struct channel *channel, @@ -258,7 +255,6 @@ static void add_htlcs(const struct chainparams *chainparams, /* FIXME: We could cache these. */ struct bitcoin_tx **channel_txs(const tal_t *ctx, - const struct chainparams *chainparams, const struct htlc ***htlcmap, const u8 ***wscripts, const struct channel *channel, @@ -282,7 +278,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, txs = tal_arr(ctx, struct bitcoin_tx *, 1); txs[0] = commit_tx( - ctx, chainparams, &channel->funding_txid, channel->funding_txout, + ctx, &channel->funding_txid, channel->funding_txout, channel->funding, channel->funder, channel->config[!side].to_self_delay, &keyset, channel->view[side].feerate_per_kw, @@ -295,7 +291,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, &channel->funding_pubkey[side], &channel->funding_pubkey[!side]); - add_htlcs(chainparams, &txs, wscripts, *htlcmap, channel, &keyset, side); + add_htlcs(&txs, wscripts, *htlcmap, channel, &keyset, side); tal_free(committed); return txs; @@ -446,7 +442,7 @@ static enum channel_add_err add_htlc(struct channel *channel, * - MUST set the four most significant bytes of `amount_msat` to 0. */ if (sender == LOCAL - && amount_msat_greater(htlc->amount, channel->chainparams->max_payment)) { + && amount_msat_greater(htlc->amount, chainparams->max_payment)) { return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED; } diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 01d4ce160..8fde9087f 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -10,7 +10,6 @@ /** * new_full_channel: Given initial fees and funding, what is initial state? * @ctx: tal context to allocate return value from. - * @chain_hash: Which blockchain are we talking about? * @funding_txid: The commitment transaction id. * @funding_txout: The commitment transaction output number. * @minimum_depth: The minimum confirmations needed for funding transaction. @@ -30,7 +29,6 @@ * Returns state, or NULL if malformed. */ struct channel *new_full_channel(const tal_t *ctx, - const struct bitcoin_blkid *chain_hash, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, @@ -49,7 +47,6 @@ struct channel *new_full_channel(const tal_t *ctx, /** * channel_txs: Get the current commitment and htlc txs for the channel. * @ctx: tal context to allocate return value from. - * @chainparams: Parameters for the generated transactions. * @channel: The channel to evaluate * @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) @@ -62,7 +59,6 @@ struct channel *new_full_channel(const tal_t *ctx, * fills in @htlc_map, or NULL on key derivation failure. */ struct bitcoin_tx **channel_txs(const tal_t *ctx, - const struct chainparams *chainparams, const struct htlc ***htlcmap, const u8 ***wscripts, const struct channel *channel, diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index a5164dad6..df054f090 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -723,7 +723,7 @@ int main(void) keyset.other_htlc_key = remote_htlckey; print_superverbose = true; - tx = commit_tx(tmpctx, chainparams, + tx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, @@ -735,7 +735,7 @@ int main(void) NULL, &htlc_map, commitment_number ^ cn_obscurer, LOCAL); print_superverbose = false; - tx2 = commit_tx(tmpctx, chainparams, + tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, REMOTE, to_self_delay, @@ -779,7 +779,7 @@ int main(void) to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); print_superverbose = true; - tx = commit_tx(tmpctx, chainparams, + tx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, @@ -791,7 +791,7 @@ int main(void) htlcs, &htlc_map, commitment_number ^ cn_obscurer, LOCAL); print_superverbose = false; - tx2 = commit_tx(tmpctx, chainparams, + tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, REMOTE, to_self_delay, @@ -823,7 +823,7 @@ int main(void) feerate_per_kw = increase(feerate_per_kw); print_superverbose = false; - newtx = commit_tx(tmpctx, chainparams, + newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, @@ -836,7 +836,7 @@ int main(void) commitment_number ^ cn_obscurer, LOCAL); /* This is what it would look like for peer generating it! */ - tx2 = commit_tx(tmpctx, chainparams, + tx2 = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, REMOTE, to_self_delay, @@ -868,7 +868,7 @@ int main(void) to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw-1); /* Recalc with verbosity on */ print_superverbose = true; - tx = commit_tx(tmpctx, chainparams, + tx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, @@ -905,7 +905,7 @@ int main(void) to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); /* Recalc with verbosity on */ print_superverbose = true; - newtx = commit_tx(tmpctx, chainparams, + newtx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, @@ -964,7 +964,7 @@ int main(void) "to_remote_msat: %"PRIu64"\n" "local_feerate_per_kw: %u\n", to_local.millisatoshis, to_remote.millisatoshis, feerate_per_kw); - tx = commit_tx(tmpctx, chainparams, + tx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, to_self_delay, diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index d3ddae31b..6e9ba032c 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -466,7 +466,6 @@ int main(void) to_remote = AMOUNT_MSAT(3000000000); feerate_per_kw[LOCAL] = feerate_per_kw[REMOTE] = 15000; lchannel = new_full_channel(tmpctx, - &chainparams->genesis_blockhash, &funding_txid, funding_output_index, 0, funding_amount, to_local, feerate_per_kw, @@ -477,7 +476,6 @@ int main(void) &remote_funding_pubkey, false, LOCAL); rchannel = new_full_channel(tmpctx, - &chainparams->genesis_blockhash, &funding_txid, funding_output_index, 0, funding_amount, to_remote, feerate_per_kw, @@ -508,7 +506,7 @@ int main(void) keyset.self_htlc_key = keyset.self_payment_key; keyset.other_htlc_key = keyset.other_payment_key; - raw_tx = commit_tx(tmpctx, chainparams, + raw_tx = commit_tx(tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, remote_config->to_self_delay, @@ -519,7 +517,7 @@ int main(void) to_remote, NULL, &htlc_map, 0x2bb038521914 ^ 42, LOCAL); - txs = channel_txs(tmpctx, chainparams, + txs = channel_txs(tmpctx, &htlc_map, &wscripts, lchannel, &local_per_commitment_point, 42, LOCAL); assert(tal_count(txs) == 1); @@ -528,7 +526,7 @@ int main(void) assert(scripteq(wscripts[0], funding_wscript)); tx_must_be_eq(txs[0], raw_tx); - txs2 = channel_txs(tmpctx, chainparams, + txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, rchannel, &local_per_commitment_point, 42, REMOTE); txs_must_be_eq(txs, txs2); @@ -556,10 +554,10 @@ int main(void) assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis == rchannel->view[LOCAL].owed[LOCAL].millisatoshis); - txs = channel_txs(tmpctx, chainparams,&htlc_map, &wscripts, + txs = channel_txs(tmpctx, &htlc_map, &wscripts, lchannel, &local_per_commitment_point, 42, LOCAL); assert(tal_count(txs) == 1); - txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts, + txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, rchannel, &local_per_commitment_point, 42, REMOTE); txs_must_be_eq(txs, txs2); @@ -574,10 +572,10 @@ int main(void) assert(lchannel->view[REMOTE].owed[REMOTE].millisatoshis == rchannel->view[LOCAL].owed[LOCAL].millisatoshis); - txs = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts, + txs = channel_txs(tmpctx, &htlc_map, &wscripts, lchannel, &local_per_commitment_point, 42, LOCAL); assert(tal_count(txs) == 6); - txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts, + txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, rchannel, &local_per_commitment_point, 42, REMOTE); txs_must_be_eq(txs, txs2); @@ -587,7 +585,7 @@ int main(void) * output htlc_success_tx 0: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000 */ raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219700000000000000000001e8030000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402206a6e59f18764a5bf8d4fa45eebc591566689441229c918b480fb2af8cc6a4aeb02205248f273be447684b33e3c8d1d85a8e0ca9fa0bae9ae33f0527ada9c162919a60147304402207cb324fa0de88f452ffa9389678127ebcf4cabe1dd848b8e076c1a1962bf34720220116ed922b12311bd602d67e60d2529917f21c5b82f25ff6506c0f87886b4dfd5012000000000000000000000000000000000000000000000000000000000000000008a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac686800000000"); - raw_tx->chainparams = chainparams_for_network("bitcoin"); + raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[1]); @@ -596,7 +594,7 @@ int main(void) * output htlc_timeout_tx 2: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000 */ raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219701000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100d5275b3619953cb0c3b5aa577f04bc512380e60fa551762ce3d7a1bb7401cff9022037237ab0dac3fe100cde094e82e2bed9ba0ed1bb40154b48e56aa70f259e608b01483045022100c89172099507ff50f4c925e6c5150e871fb6e83dd73ff9fbb72f6ce829a9633f02203a63821d9162e99f9be712a68f9e589483994feae2661e4546cd5b6cec007be501008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868f6010000"); - raw_tx->chainparams = chainparams_for_network("bitcoin"); + raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[2]); @@ -605,7 +603,7 @@ int main(void) * output htlc_success_tx 1: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000 */ raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219702000000000000000001d0070000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402201b63ec807771baf4fdff523c644080de17f1da478989308ad13a58b51db91d360220568939d38c9ce295adba15665fa68f51d967e8ed14a007b751540a80b325f20201483045022100def389deab09cee69eaa1ec14d9428770e45bcbe9feb46468ecf481371165c2f022015d2e3c46600b2ebba8dcc899768874cc6851fd1ecb3fffd15db1cc3de7e10da012001010101010101010101010101010101010101010101010101010101010101018a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a9144b6b2e5444c2639cc0fb7bcea5afba3f3cdce23988527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f501b175ac686800000000"); - raw_tx->chainparams = chainparams_for_network("bitcoin"); + raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[3]); @@ -614,7 +612,7 @@ int main(void) * output htlc_timeout_tx 3: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000 */ raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219703000000000000000001b80b0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0500483045022100daee1808f9861b6c3ecd14f7b707eca02dd6bdfc714ba2f33bc8cdba507bb182022026654bf8863af77d74f51f4e0b62d461a019561bb12acb120d3f7195d148a554014730440220643aacb19bbb72bd2b635bc3f7375481f5981bace78cdd8319b2988ffcc6704202203d27784ec8ad51ed3bd517a05525a5139bb0b755dd719e0054332d186ac0872701008576a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9148a486ff2e31d6158bf39e2608864d63fefd09d5b88ac6868f7010000"); - raw_tx->chainparams = chainparams_for_network("bitcoin"); + raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[4]); @@ -623,7 +621,7 @@ int main(void) * output htlc_success_tx 4: 020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000 */ raw_tx = tx_from_hex(tmpctx, "020000000001018154ecccf11a5fb56c39654c4deb4d2296f83c69268280b94d021370c94e219704000000000000000001a00f0000000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e050047304402207e0410e45454b0978a623f36a10626ef17b27d9ad44e2760f98cfa3efb37924f0220220bd8acd43ecaa916a80bd4f919c495a2c58982ce7c8625153f8596692a801d014730440220549e80b4496803cbc4a1d09d46df50109f546d43fbbf86cd90b174b1484acd5402205f12a4f995cb9bded597eabfee195a285986aa6d93ae5bb72507ebc6a4e2349e012004040404040404040404040404040404040404040404040404040404040404048a76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a91418bc1a114ccf9c052d3d23e28d3b0a9d1227434288527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f801b175ac686800000000"); - raw_tx->chainparams = chainparams_for_network("bitcoin"); + raw_tx->chainparams = chainparams; bitcoin_tx_input_set_witness(raw_tx, 0, NULL); tx_must_be_eq(raw_tx, txs[5]); @@ -635,18 +633,18 @@ int main(void) rchannel->view[REMOTE].feerate_per_kw = feerate_per_kw[REMOTE]; raw_tx = commit_tx( - tmpctx, chainparams, &funding_txid, funding_output_index, + tmpctx, &funding_txid, funding_output_index, funding_amount, LOCAL, remote_config->to_self_delay, &keyset, feerate_per_kw[LOCAL], local_config->dust_limit, to_local, to_remote, htlcs, &htlc_map, 0x2bb038521914 ^ 42, LOCAL); - txs = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts, + txs = channel_txs(tmpctx, &htlc_map, &wscripts, lchannel, &local_per_commitment_point, 42, LOCAL); tx_must_be_eq(txs[0], raw_tx); - txs2 = channel_txs(tmpctx, chainparams, &htlc_map, &wscripts, + txs2 = channel_txs(tmpctx, &htlc_map, &wscripts, rchannel, &local_per_commitment_point, 42, REMOTE); txs_must_be_eq(txs, txs2); diff --git a/common/initial_channel.c b/common/initial_channel.c index 16547da58..a68ad9bcd 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -9,7 +9,6 @@ #include struct channel *new_initial_channel(const tal_t *ctx, - const struct bitcoin_blkid *chain_hash, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, @@ -62,9 +61,6 @@ struct channel *new_initial_channel(const tal_t *ctx, channel->commitment_number_obscurer = commit_number_obscurer(&channel->basepoints[funder].payment, &channel->basepoints[!funder].payment); - channel->chainparams = chainparams_by_chainhash(chain_hash); - if (channel->chainparams == NULL) - return tal_free(channel); channel->option_static_remotekey = option_static_remotekey; return channel; @@ -96,7 +92,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, &channel->funding_pubkey[side], &channel->funding_pubkey[!side]); - return initial_commit_tx(ctx, channel->chainparams, + return initial_commit_tx(ctx, &channel->funding_txid, channel->funding_txout, channel->funding, diff --git a/common/initial_channel.h b/common/initial_channel.h index 4db6d72a6..f5486a794 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -62,9 +62,6 @@ struct channel { /* What it looks like to each side. */ struct channel_view view[NUM_SIDES]; - /* Chain params to check against */ - const struct chainparams *chainparams; - /* Is this using option_static_remotekey? */ bool option_static_remotekey; }; @@ -72,7 +69,6 @@ struct channel { /** * new_initial_channel: Given initial fees and funding, what is initial state? * @ctx: tal context to allocate return value from. - * @chain_hash: Which blockchain are we talking about? * @funding_txid: The commitment transaction id. * @funding_txout: The commitment transaction output number. * @minimum_depth: The minimum confirmations needed for funding transaction. @@ -91,7 +87,6 @@ struct channel { * Returns channel, or NULL if malformed. */ struct channel *new_initial_channel(const tal_t *ctx, - const struct bitcoin_blkid *chain_hash, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, u32 minimum_depth, diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 0141f6a3e..9f80f500e 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -59,7 +59,6 @@ u8 *to_self_wscript(const tal_t *ctx, } struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, - const struct chainparams *chainparams, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index 81f05c803..9e5e3dd3b 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -75,7 +75,6 @@ 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 * @ctx: context to allocate transaction and @htlc_map from. - * @chainparams: Params for the resulting transactions * @funding_txid, @funding_out, @funding: funding outpoint. * @funder: is the LOCAL or REMOTE paying the fee? * @keyset: keys derived for this commit tx. @@ -93,7 +92,6 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw, * transaction, so we carefully use the terms "self" and "other" here. */ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, - const struct chainparams *chainparams, const struct bitcoin_txid *funding_txid, unsigned int funding_txout, struct amount_sat funding, diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index 4923398c5..bc138c728 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -360,8 +360,6 @@ int main(int argc, char *argv[]) &remotebase, &funding_remotekey, commitnum); channel = new_full_channel(NULL, - &chainparams_for_network("regtest") - ->genesis_blockhash, &funding_txid, funding_outnum, 1, funding_amount, local_msat, @@ -384,7 +382,7 @@ int main(int argc, char *argv[]) if (!per_commit_point(&localseed, &local_per_commit_point, commitnum)) errx(1, "Bad deriving local per-commitment-point"); - local_txs = channel_txs(NULL, chainparams, &htlcmap, &wscripts, channel, + local_txs = channel_txs(NULL, &htlcmap, &wscripts, channel, &local_per_commit_point, commitnum, LOCAL); printf("## local_commitment\n" @@ -485,7 +483,7 @@ int main(int argc, char *argv[]) /* Create the remote commitment tx */ if (!per_commit_point(&remoteseed, &remote_per_commit_point, commitnum)) errx(1, "Bad deriving remote per-commitment-point"); - remote_txs = channel_txs(NULL, chainparams, &htlcmap, &wscripts, channel, + remote_txs = channel_txs(NULL, &htlcmap, &wscripts, channel, &remote_per_commit_point, commitnum, REMOTE); remote_txs[0]->input_amounts[0] = tal_dup(remote_txs[0], struct amount_sat, &funding_amount); diff --git a/openingd/openingd.c b/openingd/openingd.c index 79a859f5c..6fd425b50 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -109,8 +109,6 @@ struct state { * as initial channels never have HTLCs. */ struct channel *channel; - /* Which chain we're on, so we can check/set `chain_hash` fields */ - const struct chainparams *chainparams; bool option_static_remotekey; }; @@ -480,11 +478,11 @@ static bool setup_channel_funder(struct state *state) *... * - MUST set `funding_satoshis` to less than 2^24 satoshi. */ - if (amount_sat_greater(state->funding, state->chainparams->max_funding)) { + if (amount_sat_greater(state->funding, chainparams->max_funding)) { status_failed(STATUS_FAIL_MASTER_IO, "funding_satoshis must be < %s, not %s", type_to_string(tmpctx, struct amount_sat, - &state->chainparams->max_funding), + &chainparams->max_funding), type_to_string(tmpctx, struct amount_sat, &state->funding)); return false; @@ -520,7 +518,7 @@ static u8 *funder_channel_start(struct state *state, our_upfront_shutdown_script = dev_upfront_shutdown_script(tmpctx); msg = towire_open_channel_option_upfront_shutdown_script(NULL, - &state->chainparams->genesis_blockhash, + &chainparams->genesis_blockhash, &state->channel_id, state->funding, state->push_msat, @@ -666,7 +664,6 @@ static bool funder_finalize_channel_setup(struct state *state, * enough for us here, and the complete channel support required by * `channeld` which lives in channeld/full_channel. */ state->channel = new_initial_channel(state, - &state->chainparams->genesis_blockhash, &state->funding_txid, state->funding_txout, state->minimum_depth, @@ -951,8 +948,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) * - the `chain_hash` value is set to a hash of a chain * that is unknown to the receiver. */ - if (!bitcoin_blkid_eq(&chain_hash, - &state->chainparams->genesis_blockhash)) { + if (!bitcoin_blkid_eq(&chain_hash, &chainparams->genesis_blockhash)) { negotiation_failed(state, false, "Unknown chain-hash %s", type_to_string(tmpctx, @@ -965,7 +961,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) * * The receiving node ... MUST fail the channel if `funding-satoshis` * is greater than or equal to 2^24 */ - if (amount_sat_greater(state->funding, state->chainparams->max_funding)) { + if (amount_sat_greater(state->funding, chainparams->max_funding)) { negotiation_failed(state, false, "funding_satoshis %s too large", type_to_string(tmpctx, struct amount_sat, @@ -1131,7 +1127,6 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) /* Now we can create the channel structure. */ state->channel = new_initial_channel(state, - &chain_hash, &state->funding_txid, state->funding_txout, state->minimum_depth, @@ -1473,11 +1468,6 @@ int main(int argc, char *argv[]) tal_free(inner); } - /*~ Even though I only care about bitcoin, there's still testnet and - * regtest modes, so we have a general "parameters for this chain" - * function. */ - state->chainparams = chainparams; - /*~ Initially we're not associated with a channel, but * handle_peer_gossip_or_error compares this. */ memset(&state->channel_id, 0, sizeof(state->channel_id));