lightningd: log when we fail to get an fd from hsmd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-05-09 12:51:14 +09:30
parent 3bfe622413
commit 857c0042ef
6 changed files with 49 additions and 6 deletions

View file

@ -1528,6 +1528,13 @@ bool peer_start_channeld(struct channel *channel,
| HSM_PERM_SIGN_CLOSING_TX
| HSM_PERM_SIGN_SPLICE_TX
| HSM_PERM_LOCK_OUTPOINT);
if (hsmfd < 0) {
log_broken(channel->log, "Could not get hsm fd: %s",
strerror(errno));
force_peer_disconnect(ld, channel->peer,
"Failed to get hsm fd");
return false;
}
channel_set_owner(channel,
new_channel_subd(channel, ld,

View file

@ -376,6 +376,13 @@ void peer_start_closingd(struct channel *channel, struct peer_fd *peer_fd)
hsmfd = hsm_get_client_fd(ld, &channel->peer->id, channel->dbid,
HSM_PERM_SIGN_CLOSING_TX
| HSM_PERM_COMMITMENT_POINT);
if (hsmfd < 0) {
log_broken(channel->log, "Could not get hsm fd for closing: %s",
strerror(errno));
force_peer_disconnect(ld, channel->peer,
"Failed to get hsm fd for closingd");
return;
}
channel_set_owner(channel,
new_channel_subd(channel, ld,

View file

@ -4065,6 +4065,12 @@ bool peer_start_dualopend(struct peer *peer,
| HSM_PERM_SIGN_REMOTE_TX
| HSM_PERM_SIGN_WILL_FUND_OFFER
| HSM_PERM_LOCK_OUTPOINT);
if (hsmfd < 0) {
channel_internal_error(channel,
"Getting hsm fd for dualopend: %s",
strerror(errno));
return false;
}
channel->owner = new_channel_subd(channel,
peer->ld,
@ -4141,6 +4147,15 @@ bool peer_restart_dualopend(struct peer *peer,
| HSM_PERM_SIGN_WILL_FUND_OFFER
| HSM_PERM_LOCK_OUTPOINT);
if (hsmfd < 0) {
log_broken(channel->log, "Could not get hsmfd: %s",
strerror(errno));
/* Disconnect it. */
force_peer_disconnect(peer->ld, peer,
"Failed to get hsm fd for dualopend");
return false;
}
channel_set_owner(channel,
new_channel_subd(channel, peer->ld,
"lightning_dualopend",

View file

@ -26,7 +26,6 @@ static int hsm_get_fd(struct lightningd *ld,
u64 dbid,
u64 permissions)
{
int hsm_fd;
const u8 *msg;
msg = towire_hsmd_client_hsmfd(NULL, id, dbid, permissions);
@ -34,10 +33,7 @@ static int hsm_get_fd(struct lightningd *ld,
if (!fromwire_hsmd_client_hsmfd_reply(msg))
fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg));
hsm_fd = fdpass_recv(ld->hsm_fd);
if (hsm_fd < 0)
fatal("Could not read fd from HSM: %s", strerror(errno));
return hsm_fd;
return fdpass_recv(ld->hsm_fd);
}
int hsm_get_client_fd(struct lightningd *ld,
@ -52,7 +48,11 @@ int hsm_get_client_fd(struct lightningd *ld,
int hsm_get_global_fd(struct lightningd *ld, u64 permissions)
{
return hsm_get_fd(ld, &ld->id, 0, permissions);
int fd = hsm_get_fd(ld, &ld->id, 0, permissions);
if (fd < 0)
fatal("Could not read fd from HSM: %s", strerror(errno));
return fd;
}
static unsigned int hsm_msg(struct subd *hsmd,

View file

@ -1540,6 +1540,11 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
channel->dbid,
HSM_PERM_SIGN_ONCHAIN_TX
| HSM_PERM_COMMITMENT_POINT);
if (hsmfd < 0) {
log_broken(channel->log, "Could not get hsm fd for onchaind: %s",
strerror(errno));
return KEEP_WATCHING;
}
channel_set_owner(channel, new_channel_subd(channel, ld,
"lightning_onchaind",

View file

@ -936,6 +936,15 @@ bool peer_start_openingd(struct peer *peer, struct peer_fd *peer_fd)
HSM_PERM_COMMITMENT_POINT
| HSM_PERM_SIGN_REMOTE_TX);
if (hsmfd < 0) {
uncommitted_channel_disconnect(uc, LOG_BROKEN,
tal_fmt(tmpctx,
"Getting hsmfd for lightning_openingd: %s",
strerror(errno)));
tal_free(uc);
return false;
}
uc->open_daemon = new_channel_subd(peer, peer->ld,
"lightning_openingd",
uc, &peer->id, uc->log,