Browse Source

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>
ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
83c8c3fc52
  1. 7
      bitcoin/block.c
  2. 2
      bitcoin/block.h
  3. 11
      lightningd/opening/opening.c

7
bitcoin/block.c

@ -3,13 +3,6 @@
#include "bitcoin/tx.h"
#include <ccan/str/hex/hex.h>
const struct sha256_double genesis_blockhash
= { { .u.u8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xd6, 0x68,
0x9c, 0x08, 0x5a, 0xe1, 0x65, 0x83, 0x1e, 0x93,
0x4f, 0xf7, 0x63, 0xae, 0x46, 0xa2, 0xa6, 0xc1,
0x72, 0xb3, 0xf1, 0xb6, 0x0a, 0x8c, 0xe2, 0x6f
} } };
/* Encoding is <blockhdr> <varint-num-txs> <tx>... */
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
const char *hex, size_t hexlen)

2
bitcoin/block.h

@ -22,8 +22,6 @@ struct bitcoin_block {
struct bitcoin_tx **tx;
};
const struct sha256_double genesis_blockhash;
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
const char *hex, size_t hexlen);

11
lightningd/opening/opening.c

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

Loading…
Cancel
Save