opening: Use the correct chainparams to open a channel

We were using the bitcoin genesis blockhash for all networks, which is
not correct, and would result in the open being aborted when talking
to other implementations.

Reported-by: @sstone and @pm47
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2017-07-11 15:50:10 +02:00
committed by Rusty Russell
parent fbc2b65a3d
commit 83c8c3fc52
3 changed files with 9 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
#include <bitcoin/block.h>
#include <bitcoin/chainparams.h>
#include <bitcoin/privkey.h>
#include <bitcoin/script.h>
#include <ccan/breakpoint/breakpoint.h>
@@ -55,6 +56,8 @@ struct state {
u64 min_effective_htlc_capacity_msat;
struct channel *channel;
const struct chainparams *chainparams;
};
static void check_config_bounds(struct state *state,
@@ -246,7 +249,9 @@ static u8 *funder_channel(struct state *state,
"push-msat must be < %"PRIu64,
1000 * state->funding_satoshis);
msg = towire_open_channel(tmpctx, &genesis_blockhash.sha, &channel_id,
msg = towire_open_channel(tmpctx,
&state->chainparams->genesis_blockhash.sha,
&channel_id,
state->funding_satoshis, state->push_msat,
state->localconf.dust_limit_satoshis,
state->localconf.max_htlc_value_in_flight_msat,
@@ -507,7 +512,7 @@ static u8 *fundee_channel(struct state *state,
* within the `open_channel` message is set to a hash of a chain
* unknown to the receiver.
*/
if (!structeq(&chain_hash, &genesis_blockhash)) {
if (!structeq(&chain_hash, &state->chainparams->genesis_blockhash)) {
peer_failed(PEER_FD, &state->cs, NULL,
WIRE_OPENING_PEER_BAD_INITIAL_MESSAGE,
"Unknown chain-hash %s",
@@ -720,6 +725,8 @@ int main(int argc, char *argv[])
status_failed(WIRE_OPENING_BAD_COMMAND, "%s", strerror(errno));
tal_free(msg);
state->chainparams = chainparams_by_index(network_index);
/* We derive everything from the one secret seed. */
if (!derive_basepoints(&seed, &our_funding_pubkey,
&our_points, &state->our_secrets,