From 1abbc3d06a106933b9a00ba5b3388f29391fd25d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 29 Jan 2022 14:03:05 +1030 Subject: [PATCH] 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 --- channeld/Makefile | 1 + channeld/channeld.c | 15 +++++---------- channeld/channeld.h | 10 ++++++++++ channeld/watchtower.c | 15 ++++++--------- 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 channeld/channeld.h diff --git a/channeld/Makefile b/channeld/Makefile index 2c9e89d75..bef41c69a 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -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 \ diff --git a/channeld/channeld.c b/channeld/channeld.c index dfc392318..fb90922d2 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/channeld/channeld.h b/channeld/channeld.h new file mode 100644 index 000000000..a2b26b082 --- /dev/null +++ b/channeld/channeld.h @@ -0,0 +1,10 @@ +#ifndef LIGHTNING_CHANNELD_CHANNELD_H +#define LIGHTNING_CHANNELD_CHANNELD_H +#include "config.h" +#include +#include +#include + +const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES); + +#endif /* LIGHTNING_CHANNELD_CHANNELD_H */ diff --git a/channeld/watchtower.c b/channeld/watchtower.c index 20d273d65..e91dc4f89 100644 --- a/channeld/watchtower.c +++ b/channeld/watchtower.c @@ -1,6 +1,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -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),