Skip to content

Commit a7c5a1f

Browse files
committed
lightningd: implement receiving warnings.
This takes from the draft spec at lightning/bolts#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 <[email protected]> Changelog-Added: Protocol: we now report the new (draft) warning message.
1 parent f0659d0 commit a7c5a1f

File tree

12 files changed

+55
-20
lines changed

12 files changed

+55
-20
lines changed

channeld/channeld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
19281928
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
19291929
case WIRE_PING:
19301930
case WIRE_PONG:
1931+
case WIRE_WARNING:
19311932
case WIRE_ERROR:
19321933
case WIRE_ONION_MESSAGE:
19331934
abort();

common/peer_failed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void peer_failed(struct per_peer_state *pps,
4949
peer_fatal_continue(take(msg), pps);
5050
}
5151

52-
/* We're failing because peer sent us an error message */
52+
/* We're failing because peer sent us an error/warning message */
5353
void peer_failed_received_errmsg(struct per_peer_state *pps,
5454
const char *desc,
5555
const struct channel_id *channel_id,
@@ -62,7 +62,7 @@ void peer_failed_received_errmsg(struct per_peer_state *pps,
6262
channel_id = &all_channels;
6363
msg = towire_status_peer_error(NULL, channel_id, desc, soft_error, pps,
6464
NULL);
65-
peer_billboard(true, "Received error from peer: %s", desc);
65+
peer_billboard(true, "Received %s", desc);
6666
peer_fatal_continue(take(msg), pps);
6767
}
6868

common/read_peer_msg.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ u8 *peer_or_gossip_sync_read(const tal_t *ctx,
6969

7070
bool is_peer_error(const tal_t *ctx, const u8 *msg,
7171
const struct channel_id *channel_id,
72-
char **desc, bool *all_channels)
72+
char **desc, bool *all_channels,
73+
bool *warning)
7374
{
7475
struct channel_id err_chanid;
7576

76-
if (fromwire_peektype(msg) != WIRE_ERROR)
77+
if (fromwire_peektype(msg) == WIRE_ERROR)
78+
*warning = false;
79+
else if (fromwire_peektype(msg) == WIRE_WARNING)
80+
*warning = true;
81+
else
7782
return false;
7883

7984
*desc = sanitize_error(ctx, msg, &err_chanid);
@@ -154,7 +159,7 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps,
154159
const u8 *msg TAKES)
155160
{
156161
char *err;
157-
bool all_channels;
162+
bool all_channels, warning;
158163
struct channel_id actual;
159164

160165
#if DEVELOPER
@@ -181,12 +186,13 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps,
181186
return true;
182187
}
183188

184-
if (is_peer_error(tmpctx, msg, channel_id, &err, &all_channels)) {
189+
if (is_peer_error(tmpctx, msg, channel_id, &err, &all_channels,
190+
&warning)) {
185191
if (err)
186192
peer_failed_received_errmsg(pps, err,
187193
all_channels
188194
? NULL : channel_id,
189-
soft_error);
195+
warning || soft_error);
190196

191197
/* Ignore unknown channel errors. */
192198
goto handled;

common/read_peer_msg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ u8 *peer_or_gossip_sync_read(const tal_t *ctx,
3434
* @channel_id: the channel id of the current channel.
3535
* @desc: set to non-NULL if this describes a channel we care about.
3636
* @all_channels: set to true if this applies to all channels.
37+
* @warning: set to true if this is a warning, not an error.
3738
*
3839
* If @desc is NULL, ignore this message. Otherwise, that's usually passed
3940
* to peer_failed_received_errmsg().
4041
*/
4142
bool is_peer_error(const tal_t *ctx, const u8 *msg,
4243
const struct channel_id *channel_id,
43-
char **desc, bool *all_channels);
44+
char **desc, bool *all_channels, bool *warning);
4445

4546
/**
4647
* is_wrong_channel - if it's a message about a different channel, return true

common/wire_error.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
5353
struct channel_id dummy;
5454
u8 *data;
5555
size_t i;
56+
bool warning;
5657

5758
if (!channel_id)
5859
channel_id = &dummy;
5960

60-
if (!fromwire_error(ctx, errmsg, channel_id, &data))
61+
if (fromwire_error(ctx, errmsg, channel_id, &data))
62+
warning = false;
63+
else if (fromwire_warning(ctx, errmsg, channel_id, &data))
64+
warning = true;
65+
else
6166
return tal_fmt(ctx, "Invalid ERROR message '%s'",
6267
tal_hex(ctx, errmsg));
6368

@@ -79,9 +84,10 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
7984
}
8085
}
8186

82-
return tal_fmt(ctx, "channel %s: %.*s",
83-
channel_id_is_all(channel_id)
84-
? "ALL"
85-
: type_to_string(ctx, struct channel_id, channel_id),
87+
return tal_fmt(ctx, "%s%s%s: %.*s",
88+
warning ? "warning" : "error",
89+
channel_id_is_all(channel_id) ? "": " channel ",
90+
channel_id_is_all(channel_id) ? ""
91+
: type_to_string(tmpctx, struct channel_id, channel_id),
8692
(int)tal_count(data), (char *)data);
8793
}

common/wire_error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ u8 *towire_errorfmtv(const tal_t *ctx,
4343
bool channel_id_is_all(const struct channel_id *channel_id);
4444

4545
/**
46-
* sanitize_error - extract and sanitize contents of WIRE_ERROR.
46+
* sanitize_error - extract and sanitize contents of WIRE_ERROR/WIRE_WARNING.
4747
*
4848
* @ctx: context to allocate from
49-
* @errmsg: the wire_error
49+
* @errmsg: the wire_error or wire_warning
5050
* @channel: (out) channel it's referring to, or NULL if don't care.
5151
*/
5252
char *sanitize_error(const tal_t *ctx, const u8 *errmsg,

gossipd/gossipd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
737737
goto handled_relay;
738738

739739
/* These are non-gossip messages (!is_msg_for_gossipd()) */
740+
case WIRE_WARNING:
740741
case WIRE_INIT:
741742
case WIRE_ERROR:
742743
case WIRE_OPEN_CHANNEL:

openingd/dualopend.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
972972
u8 *msg;
973973
bool from_gossipd;
974974
char *err;
975-
bool all_channels;
975+
bool all_channels, warning;
976976
struct channel_id actual;
977977

978978
/* The event loop is responsible for freeing tmpctx, so our
@@ -1011,7 +1011,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
10111011

10121012
/* A helper which decodes an error. */
10131013
if (is_peer_error(tmpctx, msg, &state->channel_id,
1014-
&err, &all_channels)) {
1014+
&err, &all_channels, &warning)) {
10151015
/* BOLT #1:
10161016
*
10171017
* - if no existing channel is referred to by the
@@ -1355,6 +1355,7 @@ static bool run_tx_interactive(struct state *state,
13551355
break;
13561356
case WIRE_INIT:
13571357
case WIRE_ERROR:
1358+
case WIRE_WARNING:
13581359
case WIRE_OPEN_CHANNEL:
13591360
case WIRE_ACCEPT_CHANNEL:
13601361
case WIRE_FUNDING_CREATED:

openingd/openingd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
199199
u8 *msg;
200200
bool from_gossipd;
201201
char *err;
202-
bool all_channels;
202+
bool all_channels, warning;
203203
struct channel_id actual;
204204

205205
/* The event loop is responsible for freeing tmpctx, so our
@@ -238,7 +238,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
238238

239239
/* A helper which decodes an error. */
240240
if (is_peer_error(tmpctx, msg, &state->channel_id,
241-
&err, &all_channels)) {
241+
&err, &all_channels, &warning)) {
242242
/* BOLT #1:
243243
*
244244
* - if no existing channel is referred to by the
@@ -262,7 +262,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
262262
NULL, false);
263263
}
264264
negotiation_aborted(state, am_opener,
265-
tal_fmt(tmpctx, "They sent error %s",
265+
tal_fmt(tmpctx, "They sent %s",
266266
err));
267267
/* Return NULL so caller knows to stop negotiating. */
268268
return NULL;

wire/extracted_peer_warning.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- wire/peer_exp_wire.csv 2021-01-14 11:00:27.526336550 +1030
2+
+++ - 2021-01-21 15:31:37.071118999 +1030
3+
@@ -10,6 +10,10 @@
4+
msgdata,error,channel_id,channel_id,
5+
msgdata,error,len,u16,
6+
msgdata,error,data,byte,len
7+
+msgtype,warning,1
8+
+msgdata,warning,channel_id,channel_id,
9+
+msgdata,warning,len,u16,
10+
+msgdata,warning,data,byte,len
11+
msgtype,ping,18
12+
msgdata,ping,num_pong_bytes,u16,
13+
msgdata,ping,byteslen,u16,

0 commit comments

Comments
 (0)