lightningd: use hsm_get_client_fd() helper for global daemons too.

We couldn't use it before because it asserted dbid was non-zero.  Remove
assert and save some code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>



Header from folded patch 'fixup!_lightningd__use_hsm_get_client_fd()_helper_for_global_daemons_too.patch':

fixup! lightningd: use hsm_get_client_fd() helper for global daemons too.

Suggested-by: @ZmnSCPxj
This commit is contained in:
Rusty Russell 2018-09-20 12:37:41 +09:30 committed by Christian Decker
parent cc48e794c9
commit 04c77f4853
4 changed files with 22 additions and 26 deletions

View File

@ -14,6 +14,7 @@
#include <hsmd/gen_hsm_wire.h>
#include <lightningd/channel.h>
#include <lightningd/connect_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/json.h>
#include <lightningd/jsonrpc.h>
#include <lightningd/jsonrpc_errors.h>
@ -333,7 +334,6 @@ int connectd_init(struct lightningd *ld)
int fds[2];
u8 *msg;
int hsmfd;
u64 capabilities = HSM_CAP_ECDH;
struct wireaddr_internal *wireaddrs = ld->proposed_wireaddr;
enum addr_listen_announce *listen_announce = ld->proposed_listen_announce;
bool allow_localhost = false;
@ -345,17 +345,7 @@ int connectd_init(struct lightningd *ld)
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
fatal("Could not socketpair for connectd<->gossipd");
msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, 0, capabilities);
if (!wire_sync_write(ld->hsm_fd, msg))
fatal("Could not write to HSM: %s", strerror(errno));
msg = wire_sync_read(tmpctx, ld->hsm_fd);
if (!fromwire_hsm_client_hsmfd_reply(msg))
fatal("Malformed hsmfd response: %s", tal_hex(msg, msg));
hsmfd = fdpass_recv(ld->hsm_fd);
if (hsmfd < 0)
fatal("Could not read fd from HSM: %s", strerror(errno));
hsmfd = hsm_get_global_fd(ld, HSM_CAP_ECDH);
ld->connectd = new_global_subd(ld, "lightning_connectd",
connect_wire_type_name, connectd_msg,

View File

@ -148,19 +148,8 @@ void gossip_init(struct lightningd *ld, int connectd_fd)
{
u8 *msg;
int hsmfd;
u64 capabilities = HSM_CAP_SIGN_GOSSIP;
msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, 0, capabilities);
if (!wire_sync_write(ld->hsm_fd, msg))
fatal("Could not write to HSM: %s", strerror(errno));
msg = wire_sync_read(tmpctx, ld->hsm_fd);
if (!fromwire_hsm_client_hsmfd_reply(msg))
fatal("Malformed hsmfd response: %s", tal_hex(msg, msg));
hsmfd = fdpass_recv(ld->hsm_fd);
if (hsmfd < 0)
fatal("Could not read fd from HSM: %s", strerror(errno));
hsmfd = hsm_get_global_fd(ld, HSM_CAP_SIGN_GOSSIP);
ld->gossip = new_global_subd(ld, "lightning_gossipd",
gossip_wire_type_name, gossip_msg,

View File

@ -19,7 +19,7 @@
#include <wally_bip32.h>
#include <wire/wire_sync.h>
int hsm_get_client_fd(struct lightningd *ld,
static int hsm_get_fd(struct lightningd *ld,
const struct pubkey *id,
u64 dbid,
int capabilities)
@ -27,7 +27,6 @@ int hsm_get_client_fd(struct lightningd *ld,
int hsm_fd;
u8 *msg;
assert(dbid);
msg = towire_hsm_client_hsmfd(NULL, id, dbid, capabilities);
if (!wire_sync_write(ld->hsm_fd, take(msg)))
fatal("Could not write to HSM: %s", strerror(errno));
@ -42,6 +41,21 @@ int hsm_get_client_fd(struct lightningd *ld,
return hsm_fd;
}
int hsm_get_client_fd(struct lightningd *ld,
const struct pubkey *id,
u64 dbid,
int capabilities)
{
assert(dbid);
return hsm_get_fd(ld, id, dbid, capabilities);
}
int hsm_get_global_fd(struct lightningd *ld, int capabilities)
{
return hsm_get_fd(ld, &ld->id, 0, capabilities);
}
static unsigned int hsm_msg(struct subd *hsmd,
const u8 *msg, const int *fds UNUSED)
{

View File

@ -15,5 +15,8 @@ int hsm_get_client_fd(struct lightningd *ld,
u64 dbid,
int capabilities);
/* Ask HSM for an fd for a global subdaemon to use (gossipd, connectd) */
int hsm_get_global_fd(struct lightningd *ld, int capabilities);
void hsm_init(struct lightningd *ld);
#endif /* LIGHTNING_LIGHTNINGD_HSM_CONTROL_H */