channeld: simply exit if hsmd vanishes.

We currently die when gossipd vanishes, but our direct connection will
go away.  We then complain if the node is shutting down while we're talking
to hsmd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-01-29 14:03:05 +10:30
parent 1c71c9849b
commit 1abbc3d06a
4 changed files with 22 additions and 19 deletions

View File

@ -4,6 +4,7 @@ CHANNELD_HEADERS := \
channeld/full_channel_error_names_gen.h \
channeld/channeld_wiregen.h \
channeld/channeld_htlc.h \
channeld/channeld.h \
channeld/commit_tx.h \
channeld/full_channel.h \
channeld/full_channel_error.h \

View File

@ -15,6 +15,7 @@
#include <ccan/cast/cast.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <channeld/channeld.h>
#include <channeld/channeld_wiregen.h>
#include <channeld/full_channel.h>
#include <channeld/watchtower.h>
@ -193,23 +194,17 @@ static void billboard_update(const struct peer *peer)
peer_billboard(false, update);
}
static const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES)
const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES)
{
u8 *msg;
int type = fromwire_peektype(req);
/* hsmd goes away at shutdown. That's OK. */
if (!wire_sync_write(HSM_FD, req))
status_failed(STATUS_FAIL_HSM_IO,
"Writing %s to HSM: %s",
hsmd_wire_name(type),
strerror(errno));
exit(0);
msg = wire_sync_read(ctx, HSM_FD);
if (!msg)
status_failed(STATUS_FAIL_HSM_IO,
"Reading resp to %s: %s",
hsmd_wire_name(type),
strerror(errno));
exit(0);
return msg;
}

10
channeld/channeld.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef LIGHTNING_CHANNELD_CHANNELD_H
#define LIGHTNING_CHANNELD_CHANNELD_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/take/take.h>
#include <ccan/tal/tal.h>
const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES);
#endif /* LIGHTNING_CHANNELD_CHANNELD_H */

View File

@ -1,6 +1,7 @@
#include "config.h"
#include <bitcoin/feerate.h>
#include <bitcoin/script.h>
#include <channeld/channeld.h>
#include <channeld/watchtower.h>
#include <common/features.h>
#include <common/htlc_tx.h>
@ -26,7 +27,7 @@ penalty_tx_create(const tal_t *ctx,
struct bitcoin_tx *tx;
struct keyset keyset;
size_t weight;
u8 *msg;
const u8 *msg;
struct amount_sat fee, min_out, amt;
struct bitcoin_signature sig;
u32 locktime = 0;
@ -105,16 +106,12 @@ penalty_tx_create(const tal_t *ctx,
bitcoin_tx_finalize(tx);
u8 *hsm_sign_msg =
towire_hsmd_sign_penalty_to_us(ctx, &remote_per_commitment_secret,
towire_hsmd_sign_penalty_to_us(tmpctx, &remote_per_commitment_secret,
tx, wscript);
if (!wire_sync_write(hsm_fd, take(hsm_sign_msg)))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Writing sign request to hsm");
msg = wire_sync_read(tmpctx, hsm_fd);
if (!msg || !fromwire_hsmd_sign_tx_reply(msg, &sig))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
msg = hsm_req(tmpctx, hsm_sign_msg);
if (!fromwire_hsmd_sign_tx_reply(msg, &sig))
status_failed(STATUS_FAIL_HSM_IO,
"Reading sign_tx_reply: %s", tal_hex(tmpctx, msg));
witness = bitcoin_witness_sig_and_element(tx, &sig, &ONE, sizeof(ONE),