Skip to content

Commit

Permalink
channeld: Keep track of the chainparams for the chain we are using
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Sep 14, 2018
1 parent 8d95917 commit 2402c52
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion channeld/full_channel.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/preimage.h>
#include <bitcoin/script.h>
#include <bitcoin/tx.h>
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions common/initial_channel.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/script.h>
#include <ccan/tal/str/str.h>
#include <common/initial_channel.h>
Expand All @@ -8,6 +9,7 @@
#include <inttypes.h>

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,
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions common/initial_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2402c52

Please sign in to comment.