lightningd: implement receiving warnings.

This takes from the draft spec at https://github.com/lightningnetwork/lightning-rfc/pull/834

Note that if this draft does not get included, the peer will simply
ignore the warning message (we always close the connection afterwards
anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: we now report the new (draft) warning message.
This commit is contained in:
Rusty Russell
2021-02-02 23:16:01 +10:30
parent f0659d0ab0
commit a7c5a1f1d2
12 changed files with 55 additions and 20 deletions

View File

@@ -53,11 +53,16 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
struct channel_id dummy;
u8 *data;
size_t i;
bool warning;
if (!channel_id)
channel_id = &dummy;
if (!fromwire_error(ctx, errmsg, channel_id, &data))
if (fromwire_error(ctx, errmsg, channel_id, &data))
warning = false;
else if (fromwire_warning(ctx, errmsg, channel_id, &data))
warning = true;
else
return tal_fmt(ctx, "Invalid ERROR message '%s'",
tal_hex(ctx, errmsg));
@@ -79,9 +84,10 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
}
}
return tal_fmt(ctx, "channel %s: %.*s",
channel_id_is_all(channel_id)
? "ALL"
: type_to_string(ctx, struct channel_id, channel_id),
return tal_fmt(ctx, "%s%s%s: %.*s",
warning ? "warning" : "error",
channel_id_is_all(channel_id) ? "": " channel ",
channel_id_is_all(channel_id) ? ""
: type_to_string(tmpctx, struct channel_id, channel_id),
(int)tal_count(data), (char *)data);
}