Skip to content

Commit

Permalink
common: add peer_error flag to treat this error as "soft".
Browse files Browse the repository at this point in the history
The spec says to close the channel if they send us an error, but we
need to be more lenient to preserve channels with other
implementations.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jul 26, 2019
1 parent f7a890c commit dd79813
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions common/peer_failed.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void peer_failed(struct per_peer_state *pps,

/* Tell master the error so it can re-xmit. */
msg = towire_status_peer_error(NULL, channel_id,
desc, pps,
desc, false, pps,
err);
peer_billboard(true, desc);
tal_free(desc);
Expand All @@ -59,7 +59,7 @@ void peer_failed_received_errmsg(struct per_peer_state *pps,

if (!channel_id)
channel_id = &all_channels;
msg = towire_status_peer_error(NULL, channel_id, desc, pps, NULL);
msg = towire_status_peer_error(NULL, channel_id, desc, false, pps, NULL);
peer_billboard(true, "Received error from peer: %s", desc);
peer_fatal_continue(take(msg), pps);
}
Expand Down
2 changes: 2 additions & 0 deletions common/peer_status_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ msgtype,status_peer_error,0xFFF4
# This is implied if error_for_them, but master tries not to parse packets.
msgdata,status_peer_error,channel,channel_id,
msgdata,status_peer_error,desc,wirestring,
# Take a deep breath, then try reconnecting to the precious little snowflake.
msgdata,status_peer_error,soft_error,bool,
msgdata,status_peer_error,pps,per_peer_state,
msgdata,status_peer_error,len,u16,
msgdata,status_peer_error,error_for_them,u8,len
1 change: 0 additions & 1 deletion lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static void json_add_invoice(struct json_stream *response,
"amount_received_msat");
json_add_u64(response, "paid_at", inv->paid_timestamp);
}

if (inv->description)
json_add_string(response, "description", inv->description);

Expand Down
1 change: 1 addition & 0 deletions lightningd/onchain_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ static void onchain_error(struct channel *channel,
struct per_peer_state *pps UNUSED,
const struct channel_id *channel_id UNUSED,
const char *desc,
bool soft_error UNUSED,
const u8 *err_for_them UNUSED)
{
/* FIXME: re-launch? */
Expand Down
1 change: 1 addition & 0 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ static void opening_channel_errmsg(struct uncommitted_channel *uc,
struct per_peer_state *pps,
const struct channel_id *channel_id UNUSED,
const char *desc,
bool soft_error UNUSED,
const u8 *err_for_them UNUSED)
{
/* Close fds, if any. */
Expand Down
10 changes: 10 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ void channel_errmsg(struct channel *channel,
struct per_peer_state *pps,
const struct channel_id *channel_id UNUSED,
const char *desc,
bool soft_error,
const u8 *err_for_them)
{
notify_disconnect(channel->peer->ld, &channel->peer->id);
Expand All @@ -407,6 +408,15 @@ void channel_errmsg(struct channel *channel,
err_for_them,
tal_count(err_for_them), 0);

/* Other implementations chose to ignore errors early on. Not
* surprisingly, they now spew out spurious errors frequently,
* and we would close the channel on them. */
if (soft_error) {
channel_fail_reconnect_later(channel, "%s: (ignoring) %s",
channel->owner->name, desc);
return;
}

/* BOLT #1:
*
* A sending node:
Expand Down
1 change: 1 addition & 0 deletions lightningd/peer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void channel_errmsg(struct channel *channel,
struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *desc,
bool soft_error,
const u8 *err_for_them);

u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx);
Expand Down
9 changes: 6 additions & 3 deletions lightningd/subd.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,18 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[3])
char *desc;
struct per_peer_state *pps;
u8 *err_for_them;
bool soft_error;

if (!fromwire_status_peer_error(msg, msg,
&channel_id, &desc,
&channel_id, &desc, &soft_error,
&pps, &err_for_them))
return false;

per_peer_state_set_fds_arr(pps, fds);

/* Don't free sd; we may be about to free channel. */
sd->channel = NULL;
sd->errcb(channel, pps, &channel_id, desc, err_for_them);
sd->errcb(channel, pps, &channel_id, desc, soft_error, err_for_them);
return true;
}

Expand Down Expand Up @@ -561,7 +562,7 @@ static void destroy_subd(struct subd *sd)
sd->errcb(channel, NULL, NULL,
tal_fmt(sd, "Owning subdaemon %s died (%i)",
sd->name, status),
NULL);
false, NULL);
if (!outer_transaction)
db_commit_transaction(db);
}
Expand Down Expand Up @@ -611,6 +612,7 @@ static struct subd *new_subd(struct lightningd *ld,
struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *desc,
bool soft_error,
const u8 *err_for_them),
void (*billboardcb)(void *channel,
bool perm,
Expand Down Expand Up @@ -701,6 +703,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *desc,
bool soft_error,
const u8 *err_for_them),
void (*billboardcb)(void *channel, bool perm,
const char *happenings),
Expand Down
4 changes: 3 additions & 1 deletion lightningd/subd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct subd {
struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *desc,
bool soft_error,
const u8 *err_for_them);

/* Callback to display information for listpeers RPC */
Expand Down Expand Up @@ -120,6 +121,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
struct per_peer_state *pps,
const struct channel_id *channel_id,
const char *desc,
bool soft_error,
const u8 *err_for_them),
void (*billboardcb)(void *channel, bool perm,
const char *happenings),
Expand All @@ -133,7 +135,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
(channel), \
struct per_peer_state *, \
const struct channel_id *, \
const char *, const u8 *), \
const char *, bool, const u8 *), \
typesafe_cb_postargs(void, void *, (billboardcb), \
(channel), bool, \
const char *), \
Expand Down
2 changes: 1 addition & 1 deletion lightningd/test/run-find_my_abspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enu
bool fromwire_status_peer_billboard(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, bool *perm UNNEEDED, wirestring **happenings UNNEEDED)
{ fprintf(stderr, "fromwire_status_peer_billboard called!\n"); abort(); }
/* Generated stub for fromwire_status_peer_error */
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct channel_id *channel UNNEEDED, wirestring **desc UNNEEDED, struct per_peer_state **pps UNNEEDED, u8 **error_for_them UNNEEDED)
bool fromwire_status_peer_error(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct channel_id *channel UNNEEDED, wirestring **desc UNNEEDED, bool *soft_error UNNEEDED, struct per_peer_state **pps UNNEEDED, u8 **error_for_them UNNEEDED)
{ fprintf(stderr, "fromwire_status_peer_error called!\n"); abort(); }
/* Generated stub for get_log_book */
struct log_book *get_log_book(const struct log *log UNNEEDED)
Expand Down

0 comments on commit dd79813

Please sign in to comment.