Browse Source

temp_channel_id: move to common

We actually do need this for dualopend's, specifically for returning
errors to open_channel2
ppa
niftynei 4 years ago
committed by Christian Decker
parent
commit
924aaf180e
  1. 18
      common/channel_id.c
  2. 2
      common/channel_id.h
  3. 17
      openingd/openingd.c
  4. 1
      wire/test/Makefile

18
common/channel_id.c

@ -1,6 +1,7 @@
#include <bitcoin/pubkey.h>
#include <bitcoin/tx.h>
#include <common/channel_id.h>
#include <common/pseudorand.h>
#include <common/type_to_string.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));
}
/* 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)
{
towire(pptr, channel_id, sizeof(*channel_id));

2
common/channel_id.h

@ -26,6 +26,8 @@ void derive_channel_id(struct channel_id *channel_id,
void derive_channel_id_v2(struct channel_id *channel_id,
const struct pubkey *basepoint_1,
const struct pubkey *basepoint_2);
void temporary_channel_id(struct channel_id *channel_id);
/* Marshalling/unmarshalling functions */
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
void fromwire_channel_id(const u8 **cursor, size_t *max,

17
openingd/openingd.c

@ -33,7 +33,6 @@
#include <common/peer_failed.h>
#include <common/peer_status_wiregen.h>
#include <common/penalty_base.h>
#include <common/pseudorand.h>
#include <common/read_peer_msg.h>
#include <common/status.h>
#include <common/subdaemon.h>
@ -214,22 +213,6 @@ static void set_reserve(struct state *state, const struct amount_sat 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)
* returning the first non-handled one, or NULL if we aborted negotiation. */
static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,

1
wire/test/Makefile

@ -10,6 +10,7 @@ ALL_C_SOURCES += $(WIRE_TEST_SRC)
ALL_TEST_PROGRAMS += $(WIRE_TEST_PROGRAMS)
WIRE_TEST_COMMON_OBJS := \
common/pseudorand.o \
common/setup.o \
common/utils.o

Loading…
Cancel
Save