mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
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:
committed by
Rusty Russell
parent
fbc2b65a3d
commit
83c8c3fc52
@@ -3,13 +3,6 @@
|
|||||||
#include "bitcoin/tx.h"
|
#include "bitcoin/tx.h"
|
||||||
#include <ccan/str/hex/hex.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>... */
|
/* Encoding is <blockhdr> <varint-num-txs> <tx>... */
|
||||||
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
|
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
|
||||||
const char *hex, size_t hexlen)
|
const char *hex, size_t hexlen)
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ struct bitcoin_block {
|
|||||||
struct bitcoin_tx **tx;
|
struct bitcoin_tx **tx;
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct sha256_double genesis_blockhash;
|
|
||||||
|
|
||||||
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
|
struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
|
||||||
const char *hex, size_t hexlen);
|
const char *hex, size_t hexlen);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <bitcoin/block.h>
|
#include <bitcoin/block.h>
|
||||||
|
#include <bitcoin/chainparams.h>
|
||||||
#include <bitcoin/privkey.h>
|
#include <bitcoin/privkey.h>
|
||||||
#include <bitcoin/script.h>
|
#include <bitcoin/script.h>
|
||||||
#include <ccan/breakpoint/breakpoint.h>
|
#include <ccan/breakpoint/breakpoint.h>
|
||||||
@@ -55,6 +56,8 @@ struct state {
|
|||||||
u64 min_effective_htlc_capacity_msat;
|
u64 min_effective_htlc_capacity_msat;
|
||||||
|
|
||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
|
const struct chainparams *chainparams;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void check_config_bounds(struct state *state,
|
static void check_config_bounds(struct state *state,
|
||||||
@@ -246,7 +249,9 @@ static u8 *funder_channel(struct state *state,
|
|||||||
"push-msat must be < %"PRIu64,
|
"push-msat must be < %"PRIu64,
|
||||||
1000 * state->funding_satoshis);
|
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->funding_satoshis, state->push_msat,
|
||||||
state->localconf.dust_limit_satoshis,
|
state->localconf.dust_limit_satoshis,
|
||||||
state->localconf.max_htlc_value_in_flight_msat,
|
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
|
* within the `open_channel` message is set to a hash of a chain
|
||||||
* unknown to the receiver.
|
* 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,
|
peer_failed(PEER_FD, &state->cs, NULL,
|
||||||
WIRE_OPENING_PEER_BAD_INITIAL_MESSAGE,
|
WIRE_OPENING_PEER_BAD_INITIAL_MESSAGE,
|
||||||
"Unknown chain-hash %s",
|
"Unknown chain-hash %s",
|
||||||
@@ -720,6 +725,8 @@ int main(int argc, char *argv[])
|
|||||||
status_failed(WIRE_OPENING_BAD_COMMAND, "%s", strerror(errno));
|
status_failed(WIRE_OPENING_BAD_COMMAND, "%s", strerror(errno));
|
||||||
tal_free(msg);
|
tal_free(msg);
|
||||||
|
|
||||||
|
state->chainparams = chainparams_by_index(network_index);
|
||||||
|
|
||||||
/* We derive everything from the one secret seed. */
|
/* We derive everything from the one secret seed. */
|
||||||
if (!derive_basepoints(&seed, &our_funding_pubkey,
|
if (!derive_basepoints(&seed, &our_funding_pubkey,
|
||||||
&our_points, &state->our_secrets,
|
&our_points, &state->our_secrets,
|
||||||
|
|||||||
Reference in New Issue
Block a user