Browse Source

channeld: Keep track of the chainparams for the chain we are using

json-streaming
Christian Decker 6 years ago
parent
commit
2402c524cc
  1. 4
      channeld/channeld.c
  2. 6
      channeld/full_channel.c
  3. 1
      channeld/full_channel.h
  4. 9
      channeld/test/run-full_channel.c
  5. 4
      common/initial_channel.c
  6. 5
      common/initial_channel.h
  7. 2
      openingd/openingd.c

4
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,

6
channeld/full_channel.c

@ -1,4 +1,5 @@
#include <assert.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/preimage.h>
#include <bitcoin/script.h>
#include <bitcoin/tx.h>
@ -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,

1
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,

9
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,

4
common/initial_channel.c

@ -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>
@ -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,
@ -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;
}

5
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,

2
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,

Loading…
Cancel
Save