mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
lightningd/channel: derive local channel_id.
We weren't setting it, but the peer wasn't checking it either. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
b6fea5b429
commit
d06303c8a2
@ -945,6 +945,9 @@ static void init_channel(struct peer *peer, const u8 *msg)
|
||||
status_failed(WIRE_CHANNEL_BAD_COMMAND, "%s",
|
||||
tal_hex(msg, msg));
|
||||
|
||||
/* channel_id is set from funding txout */
|
||||
derive_channel_id(&peer->channel_id, &funding_txid, funding_txout);
|
||||
|
||||
/* We derive everything from the one secret seed. */
|
||||
derive_basepoints(&seed, &funding_pubkey[LOCAL], &points[LOCAL],
|
||||
&peer->our_secrets, &peer->shaseed,
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <bitcoin/privkey.h>
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/breakpoint/breakpoint.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/fdpass/fdpass.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <errno.h>
|
||||
@ -150,22 +149,6 @@ static void set_reserve(u64 *reserve, u64 funding)
|
||||
*reserve = (funding + 99) / 100;
|
||||
}
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* This message introduces the `channel-id` which identifies , which is
|
||||
* derived from the funding transaction by combining the `funding-txid` and
|
||||
* the `funding-output-index` using big-endian exclusive-OR
|
||||
* (ie. `funding-output-index` alters the last two bytes).
|
||||
*/
|
||||
static void derive_channel_id(struct channel_id *channel_id,
|
||||
struct sha256_double *txid, u16 txout)
|
||||
{
|
||||
BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid));
|
||||
memcpy(channel_id, txid, sizeof(*channel_id));
|
||||
channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8;
|
||||
channel_id->id[sizeof(*channel_id)-1] ^= txout;
|
||||
}
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A sending node MUST ensure `temporary-channel-id` is unique from any other
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <bitcoin/shadouble.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
@ -178,3 +179,20 @@ static char *fmt_short_channel_id(const tal_t *ctx,
|
||||
}
|
||||
REGISTER_TYPE_TO_STRING(short_channel_id, fmt_short_channel_id);
|
||||
REGISTER_TYPE_TO_HEXSTR(channel_id);
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* This message introduces the `channel-id` which identifies , which is
|
||||
* derived from the funding transaction by combining the `funding-txid` and
|
||||
* the `funding-output-index` using big-endian exclusive-OR
|
||||
* (ie. `funding-output-index` alters the last two bytes).
|
||||
*/
|
||||
void derive_channel_id(struct channel_id *channel_id,
|
||||
struct sha256_double *txid, u16 txout)
|
||||
{
|
||||
BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid));
|
||||
memcpy(channel_id, txid, sizeof(*channel_id));
|
||||
channel_id->id[sizeof(*channel_id)-2] ^= txout >> 8;
|
||||
channel_id->id[sizeof(*channel_id)-1] ^= txout;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,9 @@ struct ipv6 {
|
||||
};
|
||||
struct preimage;
|
||||
|
||||
void derive_channel_id(struct channel_id *channel_id,
|
||||
struct sha256_double *txid, u16 txout);
|
||||
|
||||
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
|
||||
int fromwire_peektype(const u8 *cursor);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user