Browse Source

dev: add option flag for specifying temporary channel id

--dev-force-tmp-channel-id flag takes a 64-character hex string
to use as the temporary channel id. Useful for spec tests

[ Fixed crash in non-DEVELOPER mode --RR ]
Changelog-None
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
28cdccfb11
  1. 1
      lightningd/lightningd.c
  2. 2
      lightningd/lightningd.h
  3. 1
      lightningd/opening_control.c
  4. 13
      lightningd/options.c
  5. 1
      openingd/opening_wire.csv
  6. 17
      openingd/openingd.c

1
lightningd/lightningd.c

@ -126,6 +126,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_force_bip32_seed = NULL; ld->dev_force_bip32_seed = NULL;
ld->dev_force_channel_secrets = NULL; ld->dev_force_channel_secrets = NULL;
ld->dev_force_channel_secrets_shaseed = NULL; ld->dev_force_channel_secrets_shaseed = NULL;
ld->dev_force_tmp_channel_id = NULL;
#endif #endif
/*~ These are CCAN lists: an embedded double-linked list. It's not /*~ These are CCAN lists: an embedded double-linked list. It's not

2
lightningd/lightningd.h

@ -223,6 +223,8 @@ struct lightningd {
/* These are the forced channel secrets for the node. */ /* These are the forced channel secrets for the node. */
struct secrets *dev_force_channel_secrets; struct secrets *dev_force_channel_secrets;
struct sha256 *dev_force_channel_secrets_shaseed; struct sha256 *dev_force_channel_secrets_shaseed;
struct channel_id *dev_force_tmp_channel_id;
#endif /* DEVELOPER */ #endif /* DEVELOPER */
/* tor support */ /* tor support */

1
lightningd/opening_control.c

@ -965,6 +965,7 @@ void peer_start_openingd(struct peer *peer,
feature_negotiated(peer->features, feature_negotiated(peer->features,
OPT_STATIC_REMOTEKEY), OPT_STATIC_REMOTEKEY),
send_msg, send_msg,
IFDEV(peer->ld->dev_force_tmp_channel_id, NULL),
IFDEV(peer->ld->dev_fast_gossip, false)); IFDEV(peer->ld->dev_fast_gossip, false));
subd_send_msg(uc->openingd, take(msg)); subd_send_msg(uc->openingd, take(msg));
} }

13
lightningd/options.c

@ -449,6 +449,17 @@ static char *opt_force_bip32_seed(const char *optarg, struct lightningd *ld)
return NULL; return NULL;
} }
static char *opt_force_tmp_channel_id(const char *optarg, struct lightningd *ld)
{
tal_free(ld->dev_force_tmp_channel_id);
ld->dev_force_tmp_channel_id = tal(ld, struct channel_id);
if (!hex_decode(optarg, strlen(optarg),
ld->dev_force_tmp_channel_id,
sizeof(*ld->dev_force_tmp_channel_id)))
return tal_fmt(NULL, "Unable to parse channel id '%s'", optarg);
return NULL;
}
static char *opt_force_channel_secrets(const char *optarg, static char *opt_force_channel_secrets(const char *optarg,
struct lightningd *ld) struct lightningd *ld)
{ {
@ -535,6 +546,8 @@ static void dev_register_opts(struct lightningd *ld)
"Maximum number of blocks we wait for a channel " "Maximum number of blocks we wait for a channel "
"funding transaction to confirm, if we are the " "funding transaction to confirm, if we are the "
"fundee."); "fundee.");
opt_register_arg("--dev-force-tmp-channel-id", opt_force_tmp_channel_id, NULL, ld,
"Force the temporary channel id, instead of random");
} }
#endif /* DEVELOPER */ #endif /* DEVELOPER */

1
openingd/opening_wire.csv

@ -24,6 +24,7 @@ msgdata,opening_init,option_static_remotekey,bool,
# Optional msg to send. # Optional msg to send.
msgdata,opening_init,len,u16, msgdata,opening_init,len,u16,
msgdata,opening_init,msg,u8,len msgdata,opening_init,msg,u8,len
msgdata,opening_init,dev_temporary_channel_id,?byte,32
msgdata,opening_init,dev_fast_gossip,bool, msgdata,opening_init,dev_fast_gossip,bool,
# Openingd->master: they offered channel, should we continue? # Openingd->master: they offered channel, should we continue?

Can't render this file because it has a wrong number of fields in line 6.

17
openingd/openingd.c

@ -15,6 +15,7 @@
#include <ccan/breakpoint/breakpoint.h> #include <ccan/breakpoint/breakpoint.h>
#include <ccan/cast/cast.h> #include <ccan/cast/cast.h>
#include <ccan/fdpass/fdpass.h> #include <ccan/fdpass/fdpass.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <common/crypto_sync.h> #include <common/crypto_sync.h>
#include <common/derive_basepoints.h> #include <common/derive_basepoints.h>
@ -54,6 +55,11 @@
#define REQ_FD STDIN_FILENO #define REQ_FD STDIN_FILENO
#define HSM_FD 6 #define HSM_FD 6
#if DEVELOPER
/* If --dev-force-tmp-channel-id is set, it ends up here */
static struct channel_id *dev_force_tmp_channel_id;
#endif /* DEVELOPER */
/* Global state structure. This is only for the one specific peer and channel */ /* Global state structure. This is only for the one specific peer and channel */
struct state { struct state {
struct per_peer_state *pps; struct per_peer_state *pps;
@ -463,6 +469,11 @@ static bool setup_channel_funder(struct state *state)
* until we know their funding_pubkey) */ * until we know their funding_pubkey) */
temporary_channel_id(&state->channel_id); temporary_channel_id(&state->channel_id);
#if DEVELOPER
/* --dev-force-tmp-channel-id specified */
if (dev_force_tmp_channel_id)
state->channel_id = *dev_force_tmp_channel_id;
#endif
/* BOLT #2: /* BOLT #2:
* *
* The sending node: * The sending node:
@ -1420,6 +1431,7 @@ int main(int argc, char *argv[])
struct pollfd pollfd[3]; struct pollfd pollfd[3];
struct state *state = tal(NULL, struct state); struct state *state = tal(NULL, struct state);
struct secret *none; struct secret *none;
struct channel_id *force_tmp_channel_id;
subdaemon_setup(argc, argv); subdaemon_setup(argc, argv);
@ -1442,9 +1454,14 @@ int main(int argc, char *argv[])
&state->features, &state->features,
&state->option_static_remotekey, &state->option_static_remotekey,
&inner, &inner,
&force_tmp_channel_id,
&dev_fast_gossip)) &dev_fast_gossip))
master_badmsg(WIRE_OPENING_INIT, msg); master_badmsg(WIRE_OPENING_INIT, msg);
#if DEVELOPER
dev_force_tmp_channel_id = force_tmp_channel_id;
#endif
/* 3 == peer, 4 == gossipd, 5 = gossip_store, 6 = hsmd */ /* 3 == peer, 4 == gossipd, 5 = gossip_store, 6 = hsmd */
per_peer_state_set_fds(state->pps, 3, 4, 5); per_peer_state_set_fds(state->pps, 3, 4, 5);

Loading…
Cancel
Save