Browse Source

chainparams: Always retrieve chainparams by the chain_hash

json-streaming
Christian Decker 6 years ago
parent
commit
f417dfa0e1
  1. 9
      bitcoin/chainparams.c
  2. 8
      bitcoin/chainparams.h
  3. 3
      lightningd/opening_control.c
  4. 4
      openingd/opening_wire.csv
  5. 6
      openingd/openingd.c

9
bitcoin/chainparams.c

@ -82,15 +82,6 @@ const struct chainparams *chainparams_for_network(const char *network_name)
return NULL;
}
const struct chainparams *chainparams_by_index(const int index)
{
if (index >= ARRAY_SIZE(networks) || index < 0) {
return NULL;
} else {
return &networks[index];
}
}
const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash)
{
for (size_t i = 0; i < ARRAY_SIZE(networks); i++) {

8
bitcoin/chainparams.h

@ -28,14 +28,6 @@ struct chainparams {
*/
const struct chainparams *chainparams_for_network(const char *network_name);
/**
* chainparams_by_index - Helper to get a network by its numeric index
*
* We may not want to pass the network name through to subdaemons, so
* we allows lookup by index.
*/
const struct chainparams *chainparams_by_index(const int index);
/**
* chainparams_by_bip173 - Helper to get a network by its bip173 name
*

3
lightningd/opening_control.c

@ -730,7 +730,8 @@ void peer_start_openingd(struct peer *peer,
*/
uc->minimum_depth = peer->ld->config.anchor_confirms;
msg = towire_opening_init(NULL, get_chainparams(peer->ld)->index,
msg = towire_opening_init(NULL,
&get_chainparams(peer->ld)->genesis_blockhash,
&uc->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,

4
openingd/opening_wire.csv

@ -3,8 +3,8 @@
#include <common/derive_basepoints.h>
opening_init,6000
# Which network are we configured for (as index into the chainparams)?
opening_init,,network_index,u32
# Which network are we configured for?
opening_init,,chain_hash,struct bitcoin_blkid
# Base configuration we'll offer (channel reserve will vary with amount)
opening_init,,our_config,struct channel_config
# Minimum/maximum configuration values we'll accept

Can't render this file because it has a wrong number of fields in line 5.

6
openingd/openingd.c

@ -1095,7 +1095,7 @@ int main(int argc, char *argv[])
u8 *msg, *inner;
struct pollfd pollfd[3];
struct state *state = tal(NULL, struct state);
u32 network_index;
struct bitcoin_blkid chain_hash;
struct secret *none;
subdaemon_setup(argc, argv);
@ -1104,7 +1104,7 @@ int main(int argc, char *argv[])
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_opening_init(tmpctx, msg,
&network_index,
&chain_hash,
&state->localconf,
&state->max_to_self_delay,
&state->min_effective_htlc_capacity_msat,
@ -1125,7 +1125,7 @@ int main(int argc, char *argv[])
fail_if_all_error(inner);
}
state->chainparams = chainparams_by_index(network_index);
state->chainparams = chainparams_by_chainhash(&chain_hash);
/* Initially we're not associated with a channel, but
* handle_peer_gossip_or_error wants this. */
memset(&state->channel_id, 0, sizeof(state->channel_id));

Loading…
Cancel
Save