Browse Source

lightningd: remove --dev-hsm-seed option.

We can create the hsm file from python directly; that works even if we
don't have DEVELOPER set, and is simpler.

We add a test that the aliases are correct.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
ac51231166
  1. 1
      lightningd/lightningd.c
  2. 3
      lightningd/lightningd.h
  3. 27
      lightningd/options.c
  4. 11
      tests/test_lightningd.py
  5. 18
      tests/utils.py

1
lightningd/lightningd.c

@ -50,7 +50,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
#if DEVELOPER #if DEVELOPER
ld->dev_debug_subdaemon = NULL; ld->dev_debug_subdaemon = NULL;
ld->dev_disconnect_fd = -1; ld->dev_disconnect_fd = -1;
ld->dev_hsm_seed = NULL;
ld->dev_subdaemon_fail = false; ld->dev_subdaemon_fail = false;
ld->no_reconnect = false; ld->no_reconnect = false;

3
lightningd/lightningd.h

@ -171,9 +171,6 @@ struct lightningd {
/* If we want to debug a subdaemon. */ /* If we want to debug a subdaemon. */
const char *dev_debug_subdaemon; const char *dev_debug_subdaemon;
/* If we want to set a specific non-random HSM seed. */
const u8 *dev_hsm_seed;
/* If we have a --dev-disconnect file */ /* If we have a --dev-disconnect file */
int dev_disconnect_fd; int dev_disconnect_fd;

27
lightningd/options.c

@ -344,17 +344,6 @@ static void config_register_opts(struct lightningd *ld)
} }
#if DEVELOPER #if DEVELOPER
static char *opt_set_hsm_seed(const char *arg, struct lightningd *ld)
{
assert(arg != NULL);
ld->dev_hsm_seed = tal_hexdata(ld, arg, strlen(arg));
if (ld->dev_hsm_seed)
return NULL;
return tal_fmt(NULL, "bad hex string '%s'", arg);
}
static void dev_register_opts(struct lightningd *ld) static void dev_register_opts(struct lightningd *ld)
{ {
opt_register_noarg("--dev-no-reconnect", opt_set_bool, opt_register_noarg("--dev-no-reconnect", opt_set_bool,
@ -369,8 +358,6 @@ static void dev_register_opts(struct lightningd *ld)
"Time between gossip broadcasts in milliseconds"); "Time between gossip broadcasts in milliseconds");
opt_register_arg("--dev-disconnect=<filename>", opt_subd_dev_disconnect, opt_register_arg("--dev-disconnect=<filename>", opt_subd_dev_disconnect,
NULL, ld, "File containing disconnection points"); NULL, ld, "File containing disconnection points");
opt_register_arg("--dev-hsm-seed=<seed>", opt_set_hsm_seed,
NULL, ld, "Hex-encoded seed for HSM");
} }
#endif #endif
@ -771,20 +758,6 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[])
else else
log_debug(ld->log, "Not guessing addresses: %s", log_debug(ld->log, "Not guessing addresses: %s",
ld->portnum ? "manually set" : "port set to zero"); ld->portnum ? "manually set" : "port set to zero");
#if DEVELOPER
if (ld->dev_hsm_seed) {
int fd;
unlink("hsm_secret");
fd = open("hsm_secret", O_CREAT|O_WRONLY, 0400);
if (fd < 0 ||
!write_all(fd, ld->dev_hsm_seed, tal_len(ld->dev_hsm_seed))
|| fsync(fd) != 0)
fatal("dev-hsm-seed: Could not write file: %s",
strerror(errno));
close(fd);
}
#endif
} }
/* FIXME: This is a hack! Expose somehow in ccan/opt.*/ /* FIXME: This is a hack! Expose somehow in ccan/opt.*/

11
tests/test_lightningd.py

@ -454,6 +454,17 @@ class LightningDTests(BaseLightningDTests):
l2.rpc.invoice, 123456, 'inv2', '?', l2.rpc.invoice, 123456, 'inv2', '?',
None, None, invoice_preimage) None, None, invoice_preimage)
def test_names(self):
for key, alias, color in [('0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'JUNIORBEAM', '0266e4'),
('022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'SILENTARTIST', '022d22'),
('035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d', 'HOPPINGFIRE', '035d2b'),
('0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199', 'JUNIORFELONY', '0382ce'),
('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'SOMBERFIRE', '032cf1'),
('0265b6ab5ec860cd257865d61ef0bbf5b3339c36cbda8b26b74e7f1dca490b6518', 'LOUDPHOTO', '0265b6')]:
n = self.node_factory.get_node()
assert n.daemon.is_in_log('public key {}, alias {}.* \(color #{}\)'
.format(key, alias, color))
def test_invoice(self): def test_invoice(self):
l1 = self.node_factory.get_node() l1 = self.node_factory.get_node()
l2 = self.node_factory.get_node() l2 = self.node_factory.get_node()

18
tests/utils.py

@ -1,4 +1,3 @@
import binascii
import logging import logging
import os import os
import re import re
@ -233,12 +232,6 @@ class BitcoinD(TailableProc):
# As of 0.16, generate() is removed; use generatetoaddress. # As of 0.16, generate() is removed; use generatetoaddress.
self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress()) self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())
# lightning-1 => 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518 aka JUNIORBEAM #0266e4
# lightning-2 => 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59 aka SILENTARTIST #022d22
# lightning-3 => 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d aka HOPPINGFIRE #035d2b
# lightning-4 => 0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de199 aka JUNIORFELONY #0382ce
# lightning-5 => 032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e aka SOMBERFIRE #032cf1
class LightningD(TailableProc): class LightningD(TailableProc):
def __init__(self, lightning_dir, bitcoin_dir, port=9735, random_hsm=False): def __init__(self, lightning_dir, bitcoin_dir, port=9735, random_hsm=False):
@ -261,17 +254,18 @@ class LightningD(TailableProc):
for k, v in opts.items(): for k, v in opts.items():
self.opts[k] = v self.opts[k] = v
if not os.path.exists(lightning_dir):
os.makedirs(lightning_dir)
# Last 32-bytes of final part of dir -> seed. # Last 32-bytes of final part of dir -> seed.
seed = (bytes(re.search('([^/]+)/*$', lightning_dir).group(1), encoding='utf-8') + bytes(32))[:32] seed = (bytes(re.search('([^/]+)/*$', lightning_dir).group(1), encoding='utf-8') + bytes(32))[:32]
if not random_hsm:
with open(os.path.join(lightning_dir, 'hsm_secret'), 'wb') as f:
f.write(seed)
if DEVELOPER: if DEVELOPER:
self.opts['dev-broadcast-interval'] = 1000 self.opts['dev-broadcast-interval'] = 1000
if not random_hsm:
self.opts['dev-hsm-seed'] = binascii.hexlify(seed).decode('ascii')
self.prefix = 'lightningd(%d)' % (port) self.prefix = 'lightningd(%d)' % (port)
if not os.path.exists(lightning_dir):
os.makedirs(lightning_dir)
@property @property
def cmd_line(self): def cmd_line(self):

Loading…
Cancel
Save