diff --git a/channeld/channeld.c b/channeld/channeld.c index 7441c06cc..028228ac4 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2614,7 +2614,9 @@ static void init_channel(struct peer *peer) /* channel_id is set from funding txout */ derive_channel_id(&peer->channel_id, &funding_txid, funding_txout); - peer->channel = new_full_channel(peer, &funding_txid, funding_txout, + peer->channel = new_full_channel(peer, + &peer->chain_hash, + &funding_txid, funding_txout, funding_satoshi, local_msatoshi, feerate_per_kw, diff --git a/channeld/full_channel.c b/channeld/full_channel.c index e8b395a41..d5d930c07 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "gen_full_channel_error_names.h" 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, u64 funding_satoshis, @@ -35,7 +37,9 @@ struct channel *new_full_channel(const tal_t *ctx, const struct pubkey *remote_funding_pubkey, enum side funder) { - struct channel *channel = new_initial_channel(ctx, funding_txid, + struct channel *channel = new_initial_channel(ctx, + chain_hash, + funding_txid, funding_txout, funding_satoshis, local_msatoshi, diff --git a/channeld/full_channel.h b/channeld/full_channel.h index b8ef156c8..103de0a8f 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -27,6 +27,7 @@ * 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, u64 funding_satoshis, diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index 58e8bb391..f8098acf1 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -336,6 +336,7 @@ int main(void) const struct htlc **htlc_map, **htlcs; const u8 *funding_wscript, **wscripts; size_t i; + const struct chainparams *chainparams = chainparams_for_network("bitcoin"); secp256k1_ctx = wally_get_secp_context(); setup_tmpctx(); @@ -443,7 +444,9 @@ int main(void) to_local_msat = 7000000000; to_remote_msat = 3000000000; feerate_per_kw[LOCAL] = feerate_per_kw[REMOTE] = 15000; - lchannel = new_full_channel(tmpctx, &funding_txid, funding_output_index, + lchannel = new_full_channel(tmpctx, + &chainparams->genesis_blockhash, + &funding_txid, funding_output_index, funding_amount_satoshi, to_local_msat, feerate_per_kw, local_config, @@ -452,7 +455,9 @@ int main(void) &local_funding_pubkey, &remote_funding_pubkey, LOCAL); - rchannel = new_full_channel(tmpctx, &funding_txid, funding_output_index, + rchannel = new_full_channel(tmpctx, + &chainparams->genesis_blockhash, + &funding_txid, funding_output_index, funding_amount_satoshi, to_remote_msat, feerate_per_kw, remote_config, diff --git a/common/initial_channel.c b/common/initial_channel.c index f2ad81c18..94a93e977 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,6 +9,7 @@ #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, u64 funding_satoshis, @@ -58,6 +60,8 @@ 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); + assert(channel->chainparams != NULL); return channel; } diff --git a/common/initial_channel.h b/common/initial_channel.h index 9ea5df573..a3ad47454 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -57,6 +57,9 @@ struct channel { /* What it looks like to each side. */ struct channel_view view[NUM_SIDES]; + + /* Chain params to check against */ + const struct chainparams *chainparams; }; /* Some requirements are self-specified (eg. my dust limit), others @@ -125,6 +128,7 @@ static inline u16 to_self_delay(const struct channel *channel, enum side side) /** * 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. * @funding_satoshis: The commitment transaction amount. @@ -142,6 +146,7 @@ static inline u16 to_self_delay(const struct channel *channel, enum side side) * 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, u64 funding_satoshis, diff --git a/openingd/openingd.c b/openingd/openingd.c index 0aab661fb..4d0b2c3c1 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -503,6 +503,7 @@ static u8 *funder_channel(struct state *state, bitcoin_txid(funding, &state->funding_txid); state->channel = new_initial_channel(state, + &state->chainparams->genesis_blockhash, &state->funding_txid, state->funding_txout, state->funding_satoshis, @@ -842,6 +843,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) type_to_string(msg, struct channel_id, &id_in)); state->channel = new_initial_channel(state, + &chain_hash, &state->funding_txid, state->funding_txout, state->funding_satoshis,