channeld: Fix tx_abort encoding

Switch to using same message format for `tx_abort` that wire_error and wire_warning use.

Changelog-None
This commit is contained in:
Dusty Daemon 2024-10-04 15:05:55 -04:00 committed by Rusty Russell
parent 4b3643d209
commit 7d1a43d5d5
4 changed files with 75 additions and 5 deletions

View File

@ -1709,7 +1709,8 @@ static void check_tx_abort(struct peer *peer, const u8 *msg)
struct inflight *inflight = last_inflight(peer);
struct bitcoin_outpoint *outpoint;
struct channel_id channel_id;
u8 *reason;
u8 *data;
char *reason;
if (fromwire_peektype(msg) != WIRE_TX_ABORT)
return;
@ -1721,7 +1722,7 @@ static void check_tx_abort(struct peer *peer, const u8 *msg)
tal_hex(tmpctx, msg));
}
if (!fromwire_tx_abort(tmpctx, msg, &channel_id, &reason))
if (!fromwire_tx_abort(tmpctx, msg, &channel_id, &data))
peer_failed_warn(peer->pps, &peer->channel_id,
"bad tx_abort %s", tal_hex(msg, msg));
@ -1736,10 +1737,17 @@ static void check_tx_abort(struct peer *peer, const u8 *msg)
status_info("Send tx_abort to master");
reason = sanitize_error(tmpctx, msg, &peer->channel_id);
status_info("Peer initiated tx_abort for reason: %s", reason);
wire_sync_write(MASTER_FD,
take(towire_channeld_splice_abort(NULL, false,
outpoint,
(char*)reason)));
tal_fmt(tmpctx,
"Peer aborted"
" for reason: %s",
reason))));
/* Give master a chance to pass the fd along */
status_info("Delaying closing of master fd by 1 second");
@ -1769,7 +1777,8 @@ static void splice_abort(struct peer *peer, const char *fmt, ...)
status_info("We are initiating tx_abort for reason: %s", reason);
peer_write(peer->pps,
take(towire_tx_abort(NULL, &peer->channel_id, (u8*)reason)));
take(towire_abortfmt(NULL, &peer->channel_id, "%s",
reason)));
do {
msg = peer_read(tmpctx, peer->pps);

View File

@ -287,7 +287,7 @@ msgdata,channeld_splice_state_error,state_error,wirestring,
msgtype,channeld_splice_abort,7223
msgdata,channeld_splice_abort,did_i_initiate,bool,
msgdata,channeld_splice_abort,inflight_outpoint,?bitcoin_outpoint,
msgdata,channeld_splice_abort,reason,?wirestring,
msgdata,channeld_splice_abort,reason,wirestring,
# master->channeld: Please enter stfu mode
msgtype,channeld_stfu,7224

Can't render this file because it has a wrong number of fields in line 16.

View File

@ -72,6 +72,43 @@ u8 *towire_warningfmt(const tal_t *ctx,
return msg;
}
u8 *towire_abortfmtv(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt,
va_list ap)
{
/* BOLT #1:
*
* The channel is referred to by `channel_id`, unless `channel_id` is
* 0 (i.e. all bytes are 0), in which case it refers to all
* channels. */
static const struct channel_id all_channels;
char *estr;
u8 *msg;
estr = tal_vfmt(ctx, fmt, ap);
/* We need tal_len to work, so we use copy. */
msg = towire_tx_abort(ctx, channel ? channel : &all_channels,
(u8 *)tal_dup_arr(estr, char, estr, strlen(estr), 0));
tal_free(estr);
return msg;
}
u8 *towire_abortfmt(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt, ...)
{
va_list ap;
u8 *msg;
va_start(ap, fmt);
msg = towire_abortfmtv(ctx, channel, fmt, ap);
va_end(ap);
return msg;
}
bool channel_id_is_all(const struct channel_id *channel_id)
{
return memeqzero(channel_id, sizeof(*channel_id));

View File

@ -54,6 +54,30 @@ u8 *towire_warningfmtv(const tal_t *ctx,
const char *fmt,
va_list ap);
/**
* towire_abortfmt - helper to turn string into WIRE_TX_ABORT.
*
* @ctx: context to allocate from
* @channel: specific channel to complain about, or NULL for all.
* @fmt: format for warning.
*/
u8 *towire_abortfmt(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt, ...) PRINTF_FMT(3,4);
/**
* towire_abortfmtv - helper to turn string into WIRE_TX_ABORT.
*
* @ctx: context to allocate from
* @channel: specific channel to complain about, or NULL for all.
* @fmt: format for warning.
* @ap: accumulated varargs.
*/
u8 *towire_abortfmtv(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt,
va_list ap);
/* BOLT #1:
*
* The channel is referred to by `channel_id`, unless `channel_id` is 0