2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2021-02-02 13:49:01 +01:00
|
|
|
#include <assert.h>
|
2019-06-03 20:11:25 +02:00
|
|
|
#include <ccan/breakpoint/breakpoint.h>
|
2017-02-24 06:52:55 +01:00
|
|
|
#include <ccan/tal/str/str.h>
|
2018-02-23 06:53:47 +01:00
|
|
|
#include <common/peer_billboard.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 14:23:29 +01:00
|
|
|
#include <common/peer_io.h>
|
2020-08-25 04:19:38 +02:00
|
|
|
#include <common/peer_status_wiregen.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/status.h>
|
2020-08-25 04:19:38 +02:00
|
|
|
#include <common/status_wiregen.h>
|
2018-01-10 05:46:54 +01:00
|
|
|
#include <common/wire_error.h>
|
2017-02-24 06:52:55 +01:00
|
|
|
|
2019-06-03 20:11:25 +02:00
|
|
|
/* Fatal error here, return peer control to lightningd */
|
|
|
|
static void NORETURN
|
|
|
|
peer_fatal_continue(const u8 *msg TAKES, const struct per_peer_state *pps)
|
|
|
|
{
|
|
|
|
int reason = fromwire_peektype(msg);
|
|
|
|
breakpoint();
|
|
|
|
status_send(msg);
|
|
|
|
|
|
|
|
status_send_fd(pps->peer_fd);
|
|
|
|
exit(0x80 | (reason & 0xFF));
|
|
|
|
}
|
|
|
|
|
2017-02-24 06:52:55 +01:00
|
|
|
/* We only support one channel per peer anyway */
|
2021-02-02 13:49:01 +01:00
|
|
|
static void NORETURN
|
|
|
|
peer_failed(struct per_peer_state *pps,
|
|
|
|
bool warn,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *desc)
|
2017-02-24 06:52:55 +01:00
|
|
|
{
|
2021-02-02 13:49:01 +01:00
|
|
|
u8 *msg;
|
2018-01-10 05:46:54 +01:00
|
|
|
|
2021-02-02 13:49:01 +01:00
|
|
|
if (warn) {
|
|
|
|
msg = towire_warningfmt(desc, channel_id, "%s", desc);
|
|
|
|
} else {
|
|
|
|
msg = towire_errorfmt(desc, channel_id, "%s", desc);
|
|
|
|
}
|
2022-01-08 14:23:29 +01:00
|
|
|
peer_write(pps, msg);
|
2018-08-09 02:25:29 +02:00
|
|
|
|
|
|
|
/* Tell master the error so it can re-xmit. */
|
2018-02-19 02:06:15 +01:00
|
|
|
msg = towire_status_peer_error(NULL, channel_id,
|
2021-02-02 13:47:01 +01:00
|
|
|
desc,
|
2021-02-02 13:49:01 +01:00
|
|
|
warn,
|
|
|
|
msg);
|
2018-02-23 06:53:47 +01:00
|
|
|
peer_billboard(true, desc);
|
2019-06-03 20:11:25 +02:00
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
2021-02-02 13:49:01 +01:00
|
|
|
void peer_failed_warn(struct per_peer_state *pps,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
const char *desc;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
peer_failed(pps, true, channel_id, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_err(struct per_peer_state *pps,
|
|
|
|
const struct channel_id *channel_id,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
const char *desc;
|
|
|
|
|
2021-02-03 03:51:41 +01:00
|
|
|
assert(channel_id);
|
2021-02-02 13:49:01 +01:00
|
|
|
va_start(ap, fmt);
|
|
|
|
desc = tal_vfmt(tmpctx, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
peer_failed(pps, false, channel_id, desc);
|
|
|
|
}
|
|
|
|
|
2021-02-02 13:46:01 +01:00
|
|
|
/* We're failing because peer sent us an error/warning message */
|
2019-06-03 20:11:25 +02:00
|
|
|
void peer_failed_received_errmsg(struct per_peer_state *pps,
|
2018-02-19 02:06:15 +01:00
|
|
|
const char *desc,
|
2019-12-13 11:16:14 +01:00
|
|
|
const struct channel_id *channel_id,
|
2021-02-02 13:47:01 +01:00
|
|
|
bool warning)
|
2018-02-19 02:06:15 +01:00
|
|
|
{
|
2018-08-02 08:49:55 +02:00
|
|
|
u8 *msg;
|
|
|
|
|
2022-06-20 03:30:36 +02:00
|
|
|
/* LND sends "internal error" and we close the channel. But
|
|
|
|
* prior to 0.11 we would turn this into a warning, and they
|
|
|
|
* would recover after a reconnect. So we downgrade, but snark
|
|
|
|
* about it in the logs. */
|
2022-06-23 14:41:26 +02:00
|
|
|
if (!warning && strends(desc, "internal error")) {
|
2022-06-20 03:30:36 +02:00
|
|
|
status_unusual("lnd sent 'internal error':"
|
|
|
|
" let's give it some space");
|
|
|
|
warning = true;
|
|
|
|
}
|
2022-01-08 14:29:29 +01:00
|
|
|
msg = towire_status_peer_error(NULL, channel_id, desc, warning,
|
2019-07-26 04:11:29 +02:00
|
|
|
NULL);
|
2021-02-02 13:46:01 +01:00
|
|
|
peer_billboard(true, "Received %s", desc);
|
2019-06-03 20:11:25 +02:00
|
|
|
peer_fatal_continue(take(msg), pps);
|
2018-02-19 02:06:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void peer_failed_connection_lost(void)
|
|
|
|
{
|
2019-06-03 20:11:25 +02:00
|
|
|
status_send_fatal(take(towire_status_peer_connection_lost(NULL)));
|
2017-02-24 06:52:55 +01:00
|
|
|
}
|