mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
temp_channel_id: move to common
We actually do need this for dualopend's, specifically for returning errors to open_channel2
This commit is contained in:
parent
c3a387a6d8
commit
924aaf180e
4 changed files with 21 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <bitcoin/pubkey.h>
|
#include <bitcoin/pubkey.h>
|
||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
#include <common/channel_id.h>
|
#include <common/channel_id.h>
|
||||||
|
#include <common/pseudorand.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
#include <wire/wire.h>
|
#include <wire/wire.h>
|
||||||
|
|
||||||
|
@ -46,6 +47,23 @@ void derive_channel_id_v2(struct channel_id *channel_id,
|
||||||
memcpy(channel_id, &sha, sizeof(*channel_id));
|
memcpy(channel_id, &sha, sizeof(*channel_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* BOLT #2:
|
||||||
|
*
|
||||||
|
* The sending node:
|
||||||
|
*...
|
||||||
|
* - MUST ensure `temporary_channel_id` is unique from any other channel ID
|
||||||
|
* with the same peer.
|
||||||
|
*/
|
||||||
|
void temporary_channel_id(struct channel_id *channel_id)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
/* Randomness FTW. */
|
||||||
|
for (i = 0; i < sizeof(*channel_id); i++)
|
||||||
|
channel_id->id[i] = pseudorand(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id)
|
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id)
|
||||||
{
|
{
|
||||||
towire(pptr, channel_id, sizeof(*channel_id));
|
towire(pptr, channel_id, sizeof(*channel_id));
|
||||||
|
|
|
@ -26,6 +26,8 @@ void derive_channel_id(struct channel_id *channel_id,
|
||||||
void derive_channel_id_v2(struct channel_id *channel_id,
|
void derive_channel_id_v2(struct channel_id *channel_id,
|
||||||
const struct pubkey *basepoint_1,
|
const struct pubkey *basepoint_1,
|
||||||
const struct pubkey *basepoint_2);
|
const struct pubkey *basepoint_2);
|
||||||
|
|
||||||
|
void temporary_channel_id(struct channel_id *channel_id);
|
||||||
/* Marshalling/unmarshalling functions */
|
/* Marshalling/unmarshalling functions */
|
||||||
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
|
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
|
||||||
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include <common/peer_failed.h>
|
#include <common/peer_failed.h>
|
||||||
#include <common/peer_status_wiregen.h>
|
#include <common/peer_status_wiregen.h>
|
||||||
#include <common/penalty_base.h>
|
#include <common/penalty_base.h>
|
||||||
#include <common/pseudorand.h>
|
|
||||||
#include <common/read_peer_msg.h>
|
#include <common/read_peer_msg.h>
|
||||||
#include <common/status.h>
|
#include <common/status.h>
|
||||||
#include <common/subdaemon.h>
|
#include <common/subdaemon.h>
|
||||||
|
@ -214,22 +213,6 @@ static void set_reserve(struct state *state, const struct amount_sat dust_limit)
|
||||||
= dust_limit;
|
= dust_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BOLT #2:
|
|
||||||
*
|
|
||||||
* The sending node:
|
|
||||||
*...
|
|
||||||
* - MUST ensure `temporary_channel_id` is unique from any other channel ID
|
|
||||||
* with the same peer.
|
|
||||||
*/
|
|
||||||
static void temporary_channel_id(struct channel_id *channel_id)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
/* Randomness FTW. */
|
|
||||||
for (i = 0; i < sizeof(*channel_id); i++)
|
|
||||||
channel_id->id[i] = pseudorand(256);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*~ Handle random messages we might get during opening negotiation, (eg. gossip)
|
/*~ Handle random messages we might get during opening negotiation, (eg. gossip)
|
||||||
* returning the first non-handled one, or NULL if we aborted negotiation. */
|
* returning the first non-handled one, or NULL if we aborted negotiation. */
|
||||||
static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
|
static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
|
||||||
|
|
|
@ -10,6 +10,7 @@ ALL_C_SOURCES += $(WIRE_TEST_SRC)
|
||||||
ALL_TEST_PROGRAMS += $(WIRE_TEST_PROGRAMS)
|
ALL_TEST_PROGRAMS += $(WIRE_TEST_PROGRAMS)
|
||||||
|
|
||||||
WIRE_TEST_COMMON_OBJS := \
|
WIRE_TEST_COMMON_OBJS := \
|
||||||
|
common/pseudorand.o \
|
||||||
common/setup.o \
|
common/setup.o \
|
||||||
common/utils.o
|
common/utils.o
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue