mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
Update wire from spec 9e0a0e893db389bfe392b2f4db8097949395fe28
Now we send genesis block in handshake. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e45bc0ce47
commit
8cc7f31d44
@ -3,6 +3,13 @@
|
||||
#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)
|
||||
|
@ -22,6 +22,8 @@ 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);
|
||||
|
||||
|
@ -322,7 +322,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
|
||||
*
|
||||
* A receiving node SHOULD fail the channel if a sending node ... or
|
||||
* adds more than its `max-htlc-value-in-flight-msat` worth of offered
|
||||
* HTLCs to its local commitment transaction. */
|
||||
* HTLCs to its local commitment transaction */
|
||||
if (msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
|
||||
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
||||
goto out;
|
||||
|
@ -8,6 +8,7 @@
|
||||
*
|
||||
* 1. type: 32 (`open_channel`)
|
||||
* 2. data:
|
||||
* * [32:chain-hash]
|
||||
* * [32:temporary-channel-id]
|
||||
* * [8:funding-satoshis]
|
||||
* * [8:push-msat]
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* FIXME: Handle incoming gossip messages! */
|
||||
#include <bitcoin/block.h>
|
||||
#include <bitcoin/privkey.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/breakpoint/breakpoint.h>
|
||||
@ -248,7 +249,7 @@ static u8 *open_channel(struct state *state,
|
||||
"push-msat must be < %"PRIu64,
|
||||
1000 * state->funding_satoshis);
|
||||
|
||||
msg = towire_open_channel(state, &channel_id,
|
||||
msg = towire_open_channel(state, &genesis_blockhash.sha, &channel_id,
|
||||
state->funding_satoshis, state->push_msat,
|
||||
state->localconf.dust_limit_satoshis,
|
||||
state->localconf.max_htlc_value_in_flight_msat,
|
||||
@ -456,6 +457,7 @@ static u8 *recv_channel(struct state *state,
|
||||
struct pubkey their_funding_pubkey;
|
||||
secp256k1_ecdsa_signature theirsig, sig;
|
||||
struct bitcoin_tx *tx;
|
||||
struct sha256_double chain_hash;
|
||||
u8 *msg;
|
||||
|
||||
state->remoteconf = tal(state, struct channel_config);
|
||||
@ -467,7 +469,7 @@ static u8 *recv_channel(struct state *state,
|
||||
* `delayed-payment-basepoint` are not valid DER-encoded compressed
|
||||
* secp256k1 pubkeys.
|
||||
*/
|
||||
if (!fromwire_open_channel(peer_msg, NULL, &channel_id,
|
||||
if (!fromwire_open_channel(peer_msg, NULL, &chain_hash.sha, &channel_id,
|
||||
&state->funding_satoshis, &state->push_msat,
|
||||
&state->remoteconf->dust_limit_satoshis,
|
||||
&state->remoteconf->max_htlc_value_in_flight_msat,
|
||||
@ -485,6 +487,20 @@ static u8 *recv_channel(struct state *state,
|
||||
"Parsing open_channel %s",
|
||||
tal_hex(peer_msg, peer_msg));
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* The receiving MUST reject the channel if the `chain-hash` value
|
||||
* within the `open_channel` message is set to a hash of a chain
|
||||
* unknown to the receiver.
|
||||
*/
|
||||
if (!structeq(&chain_hash, &genesis_blockhash)) {
|
||||
peer_failed(PEER_FD, &state->cs, NULL,
|
||||
WIRE_OPENING_PEER_BAD_INITIAL_MESSAGE,
|
||||
"Unknown chain-hash %s",
|
||||
type_to_string(peer_msg, struct sha256_double,
|
||||
&chain_hash));
|
||||
}
|
||||
|
||||
/* BOLT #2 FIXME:
|
||||
*
|
||||
* The receiving node ... MUST fail the channel if `funding-satoshis`
|
||||
|
@ -8,21 +8,22 @@ error,0,channel-id,32
|
||||
error,32,len,2
|
||||
error,34,data,len
|
||||
open_channel,32
|
||||
open_channel,0,temporary-channel-id,32
|
||||
open_channel,32,funding-satoshis,8
|
||||
open_channel,40,push-msat,8
|
||||
open_channel,48,dust-limit-satoshis,8
|
||||
open_channel,56,max-htlc-value-in-flight-msat,8
|
||||
open_channel,64,channel-reserve-satoshis,8
|
||||
open_channel,72,htlc-minimum-msat,4
|
||||
open_channel,76,feerate-per-kw,4
|
||||
open_channel,80,to-self-delay,2
|
||||
open_channel,82,max-accepted-htlcs,2
|
||||
open_channel,84,funding-pubkey,33
|
||||
open_channel,117,revocation-basepoint,33
|
||||
open_channel,150,payment-basepoint,33
|
||||
open_channel,183,delayed-payment-basepoint,33
|
||||
open_channel,216,first-per-commitment-point,33
|
||||
open_channel,0,chain-hash,32
|
||||
open_channel,32,temporary-channel-id,32
|
||||
open_channel,64,funding-satoshis,8
|
||||
open_channel,72,push-msat,8
|
||||
open_channel,80,dust-limit-satoshis,8
|
||||
open_channel,88,max-htlc-value-in-flight-msat,8
|
||||
open_channel,96,channel-reserve-satoshis,8
|
||||
open_channel,104,htlc-minimum-msat,4
|
||||
open_channel,108,feerate-per-kw,4
|
||||
open_channel,112,to-self-delay,2
|
||||
open_channel,114,max-accepted-htlcs,2
|
||||
open_channel,116,funding-pubkey,33
|
||||
open_channel,149,revocation-basepoint,33
|
||||
open_channel,182,payment-basepoint,33
|
||||
open_channel,215,delayed-payment-basepoint,33
|
||||
open_channel,248,first-per-commitment-point,33
|
||||
accept_channel,33
|
||||
accept_channel,0,temporary-channel-id,32
|
||||
accept_channel,32,dust-limit-satoshis,8
|
||||
|
@ -162,6 +162,7 @@ struct msg_node_announcement {
|
||||
u8 *addresses;
|
||||
};
|
||||
struct msg_open_channel {
|
||||
struct sha256 chain_hash;
|
||||
struct channel_id temporary_channel_id;
|
||||
u64 funding_satoshis;
|
||||
u64 push_msat;
|
||||
@ -250,6 +251,7 @@ static void *towire_struct_open_channel(const tal_t *ctx,
|
||||
const struct msg_open_channel *s)
|
||||
{
|
||||
return towire_open_channel(ctx,
|
||||
&s->chain_hash,
|
||||
&s->temporary_channel_id,
|
||||
s->funding_satoshis,
|
||||
s->push_msat,
|
||||
@ -271,7 +273,8 @@ static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, c
|
||||
{
|
||||
struct msg_open_channel *s = tal(ctx, struct msg_open_channel);
|
||||
|
||||
if (fromwire_open_channel(p, plen,
|
||||
if (fromwire_open_channel(p, plen,
|
||||
&s->chain_hash,
|
||||
&s->temporary_channel_id,
|
||||
&s->funding_satoshis,
|
||||
&s->push_msat,
|
||||
|
Loading…
Reference in New Issue
Block a user