From f417dfa0e1f20de45421186dd5920c0ba3d2b16b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 8 Sep 2018 13:37:29 +0200 Subject: [PATCH] chainparams: Always retrieve chainparams by the chain_hash --- bitcoin/chainparams.c | 9 --------- bitcoin/chainparams.h | 8 -------- lightningd/opening_control.c | 3 ++- openingd/opening_wire.csv | 4 ++-- openingd/openingd.c | 6 +++--- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/bitcoin/chainparams.c b/bitcoin/chainparams.c index cb081718a..33a70340a 100644 --- a/bitcoin/chainparams.c +++ b/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++) { diff --git a/bitcoin/chainparams.h b/bitcoin/chainparams.h index 9070a1cd9..2e9071172 100644 --- a/bitcoin/chainparams.h +++ b/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 * diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 42f0b819a..8d4389084 100644 --- a/lightningd/opening_control.c +++ b/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, diff --git a/openingd/opening_wire.csv b/openingd/opening_wire.csv index 51ae36777..5a25577c5 100644 --- a/openingd/opening_wire.csv +++ b/openingd/opening_wire.csv @@ -3,8 +3,8 @@ #include 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 diff --git a/openingd/openingd.c b/openingd/openingd.c index 424f09cc5..b17e0eea3 100644 --- a/openingd/openingd.c +++ b/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));