From 4b3643d2090e10e4a9bc29dea0c9d69e86a8dd9f Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Fri, 4 Oct 2024 15:14:21 -0400 Subject: [PATCH] splice: Clean up error messages for RPC Added and updated error messages when splicing to make it more clear to the user why a splice is failing. Changelog-Changed: Improved error messaging for splice commands. --- channeld/channeld.c | 22 +++++++++++++++++----- common/jsonrpc_errors.h | 1 + lightningd/channel_control.c | 27 ++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 503f6fb60..923450044 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -235,14 +235,15 @@ static void end_stfu_mode(struct peer *peer) status_debug("Left STFU mode."); } -static void maybe_send_stfu(struct peer *peer) +static bool maybe_send_stfu(struct peer *peer) { if (!peer->want_stfu) - return; + return false; if (pending_updates(peer->channel, LOCAL, false)) { status_info("Pending updates prevent us from STFU mode at this" " time."); + return false; } else if (!peer->stfu_sent[LOCAL]) { status_debug("Sending peer that we want to STFU."); @@ -269,6 +270,8 @@ static void maybe_send_stfu(struct peer *peer) peer->on_stfu_success = NULL; } } + + return true; } /* Durring reestablish, STFU mode is assumed if continuing a splice */ @@ -1666,7 +1669,7 @@ static bool have_they_signed_inflight(const struct peer *peer, return has_sig; } -/* this checks if local has signed everything buy the funding input */ +/* This checks if local has signed everything but the funding input */ static bool missing_user_signatures(const struct peer *peer, const struct inflight *inflight) { @@ -3387,7 +3390,7 @@ static void resume_splice_negotiation(struct peer *peer, &inws), &their_txsigs_tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, - "Splicing bad tx_signatures %s", + "Splicing bad tx_signatures msg %s", tal_hex(msg, msg)); if (peer->splicing) @@ -4296,7 +4299,16 @@ static void handle_stfu_req(struct peer *peer, const u8 *inmsg) peer->stfu_initiator = LOCAL; peer->want_stfu = true; - maybe_send_stfu(peer); + + if (!maybe_send_stfu(peer)) { + msg = towire_channeld_splice_state_error(NULL, tal_fmt(tmpctx, + "Pending updates" + " prevent us from STFU" + " mode at this" + " time.")); + wire_sync_write(MASTER_FD, take(msg)); + return; + } } static void handle_abort_req(struct peer *peer, const u8 *inmsg) diff --git a/common/jsonrpc_errors.h b/common/jsonrpc_errors.h index 000ae8b3a..da9e33772 100644 --- a/common/jsonrpc_errors.h +++ b/common/jsonrpc_errors.h @@ -84,6 +84,7 @@ enum jsonrpc_errcode { SPLICE_LOW_FEE = 359, SPLICE_HIGH_FEE = 360, SPLICE_ABORT = 362, + SPLICE_CHANNEL_ERROR = 363, /* `connect` errors */ CONNECT_NO_KNOWN_ADDRESS = 400, diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e545714a0..21a923d86 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -1625,6 +1625,27 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds) return 0; } +/* If we get a disconnecting warning or error during a splice command, let + * the user know out of an abundance of politeness. + * After, we forward the event onto the standard `channel_errmsg`. */ +static void channel_control_errmsg(struct channel *channel, + struct peer_fd *peer_fd, + const char *desc, + const u8 *err_for_them, + bool disconnect, + bool warning) +{ + struct lightningd *ld = channel->peer->ld; + struct splice_command *cc = splice_command_for_chan(ld, channel); + if (cc && disconnect) { + was_pending(command_fail(cc->cmd, SPLICE_CHANNEL_ERROR, + "Splice command failed:" + " %s", desc)); + } + + channel_errmsg(channel, peer_fd, desc, err_for_them, disconnect, warning); +} + bool peer_start_channeld(struct channel *channel, struct peer_fd *peer_fd, const u8 *fwd_msg, @@ -1674,7 +1695,7 @@ bool peer_start_channeld(struct channel *channel, channel->log, true, channeld_wire_name, channel_msg, - channel_errmsg, + channel_control_errmsg, channel_set_billboard, take(&peer_fd->fd), take(&hsmfd), NULL)); @@ -2139,9 +2160,9 @@ static struct command_result *channel_for_splice(struct command *cmd, if (!feature_negotiated(cmd->ld->our_features, (*channel)->peer->their_features, - OPT_EXPERIMENTAL_SPLICE)) + OPT_SPLICE)) return command_fail(cmd, SPLICE_NOT_SUPPORTED, - "splicing not supported"); + "Peer does not support splicing"); if (!(*channel)->owner) return command_fail(cmd, SPLICE_WRONG_OWNER,