mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +01:00
connectd: add own err codes instead of generic -1
Make it possible for connectd to send an error code to lightningd in addition to the error message. Introduce two new error codes, replacing the catch-all -1. This change, together with https://github.com/ElementsProject/lightning/pull/3395 will implement https://github.com/ElementsProject/lightning/issues/3366 Changelog-Changed: The `connect` command now returns its own error codes instead of a generic -1.
This commit is contained in:
committed by
Christian Decker
parent
3cf91b23b9
commit
fc75d8a9e6
@@ -44,6 +44,10 @@
|
|||||||
#define FUNDING_PEER_NOT_CONNECTED 305
|
#define FUNDING_PEER_NOT_CONNECTED 305
|
||||||
#define FUNDING_UNKNOWN_PEER 306
|
#define FUNDING_UNKNOWN_PEER 306
|
||||||
|
|
||||||
|
/* `connect` errors */
|
||||||
|
#define CONNECT_NO_KNOWN_ADDRESS 400
|
||||||
|
#define CONNECT_ALL_ADDRESSES_FAILED 401
|
||||||
|
|
||||||
/* Errors from `invoice` command */
|
/* Errors from `invoice` command */
|
||||||
#define INVOICE_LABEL_ALREADY_EXISTS 900
|
#define INVOICE_LABEL_ALREADY_EXISTS 900
|
||||||
#define INVOICE_PREIMAGE_ALREADY_EXISTS 901
|
#define INVOICE_PREIMAGE_ALREADY_EXISTS 901
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ msgdata,connectctl_connect_to_peer,addrhint,?wireaddr_internal,
|
|||||||
# Connectd->master: connect failed.
|
# Connectd->master: connect failed.
|
||||||
msgtype,connectctl_connect_failed,2020
|
msgtype,connectctl_connect_failed,2020
|
||||||
msgdata,connectctl_connect_failed,id,node_id,
|
msgdata,connectctl_connect_failed,id,node_id,
|
||||||
|
msgdata,connectctl_connect_failed,failcode,u32,
|
||||||
msgdata,connectctl_connect_failed,failreason,wirestring,
|
msgdata,connectctl_connect_failed,failreason,wirestring,
|
||||||
msgdata,connectctl_connect_failed,seconds_to_delay,u32,
|
msgdata,connectctl_connect_failed,seconds_to_delay,u32,
|
||||||
msgdata,connectctl_connect_failed,addrhint,?wireaddr_internal,
|
msgdata,connectctl_connect_failed,addrhint,?wireaddr_internal,
|
||||||
|
|||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <common/daemon_conn.h>
|
#include <common/daemon_conn.h>
|
||||||
#include <common/decode_array.h>
|
#include <common/decode_array.h>
|
||||||
#include <common/features.h>
|
#include <common/features.h>
|
||||||
|
#include <common/jsonrpc_errors.h>
|
||||||
#include <common/memleak.h>
|
#include <common/memleak.h>
|
||||||
#include <common/ping.h>
|
#include <common/ping.h>
|
||||||
#include <common/pseudorand.h>
|
#include <common/pseudorand.h>
|
||||||
@@ -565,22 +566,24 @@ static void connect_failed(struct daemon *daemon,
|
|||||||
const struct node_id *id,
|
const struct node_id *id,
|
||||||
u32 seconds_waited,
|
u32 seconds_waited,
|
||||||
const struct wireaddr_internal *addrhint,
|
const struct wireaddr_internal *addrhint,
|
||||||
|
u32 errcode,
|
||||||
const char *errfmt, ...)
|
const char *errfmt, ...)
|
||||||
PRINTF_FMT(5,6);
|
PRINTF_FMT(6,7);
|
||||||
|
|
||||||
static void connect_failed(struct daemon *daemon,
|
static void connect_failed(struct daemon *daemon,
|
||||||
const struct node_id *id,
|
const struct node_id *id,
|
||||||
u32 seconds_waited,
|
u32 seconds_waited,
|
||||||
const struct wireaddr_internal *addrhint,
|
const struct wireaddr_internal *addrhint,
|
||||||
|
u32 errcode,
|
||||||
const char *errfmt, ...)
|
const char *errfmt, ...)
|
||||||
{
|
{
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *err;
|
char *errmsg;
|
||||||
u32 wait_seconds;
|
u32 wait_seconds;
|
||||||
|
|
||||||
va_start(ap, errfmt);
|
va_start(ap, errfmt);
|
||||||
err = tal_vfmt(tmpctx, errfmt, ap);
|
errmsg = tal_vfmt(tmpctx, errfmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
/* Wait twice as long to reconnect, between min and max. */
|
/* Wait twice as long to reconnect, between min and max. */
|
||||||
@@ -594,11 +597,11 @@ static void connect_failed(struct daemon *daemon,
|
|||||||
* happened. We leave it to lightningd to decide if it wants to try
|
* happened. We leave it to lightningd to decide if it wants to try
|
||||||
* again, with the wait_seconds as a hint of how long before
|
* again, with the wait_seconds as a hint of how long before
|
||||||
* asking. */
|
* asking. */
|
||||||
msg = towire_connectctl_connect_failed(NULL, id, err, wait_seconds,
|
msg = towire_connectctl_connect_failed(NULL, id, errcode, errmsg,
|
||||||
addrhint);
|
wait_seconds, addrhint);
|
||||||
daemon_conn_send(daemon->master, take(msg));
|
daemon_conn_send(daemon->master, take(msg));
|
||||||
|
|
||||||
status_peer_debug(id, "Failed connected out: %s", err);
|
status_peer_debug(id, "Failed connected out: %s", errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*~ This is the destructor for the (unsuccessful) connection. We accumulate
|
/*~ This is the destructor for the (unsuccessful) connection. We accumulate
|
||||||
@@ -717,7 +720,8 @@ static void try_connect_one_addr(struct connecting *connect)
|
|||||||
if (connect->addrnum == tal_count(connect->addrs)) {
|
if (connect->addrnum == tal_count(connect->addrs)) {
|
||||||
connect_failed(connect->daemon, &connect->id,
|
connect_failed(connect->daemon, &connect->id,
|
||||||
connect->seconds_waited,
|
connect->seconds_waited,
|
||||||
connect->addrhint, "%s", connect->errors);
|
connect->addrhint, CONNECT_ALL_ADDRESSES_FAILED,
|
||||||
|
"%s", connect->errors);
|
||||||
tal_free(connect);
|
tal_free(connect);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1428,6 +1432,7 @@ static void try_connect_peer(struct daemon *daemon,
|
|||||||
* to retry; an address may get gossiped or appear on the DNS seed. */
|
* to retry; an address may get gossiped or appear on the DNS seed. */
|
||||||
if (tal_count(addrs) == 0) {
|
if (tal_count(addrs) == 0) {
|
||||||
connect_failed(daemon, id, seconds_waited, addrhint,
|
connect_failed(daemon, id, seconds_waited, addrhint,
|
||||||
|
CONNECT_NO_KNOWN_ADDRESS,
|
||||||
"Unable to connect, no address known for peer");
|
"Unable to connect, no address known for peer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
37
doc/lightning-connect.7
generated
37
doc/lightning-connect.7
generated
@@ -40,14 +40,41 @@ another node\. Once the peer is connected a channel can be opened with
|
|||||||
|
|
||||||
On success the peer \fIid\fR is returned\.
|
On success the peer \fIid\fR is returned\.
|
||||||
|
|
||||||
|
.SH ERRORS
|
||||||
|
|
||||||
The following error codes may occur:
|
On failure, one of the following errors will be returned:
|
||||||
|
|
||||||
.IP \[bu]
|
.nf
|
||||||
-1: Catchall nonspecific error\. This may occur if the host is not
|
.RS
|
||||||
valid or there are problems communicating with the peer\. \fBconnect\fR
|
{ "code" : 400, "message" : "Unable to connect, no address known for peer" }
|
||||||
will make up to 10 attempts to connect to the peer before giving up\.
|
|
||||||
|
|
||||||
|
|
||||||
|
.RE
|
||||||
|
|
||||||
|
.fi
|
||||||
|
|
||||||
|
If some addresses are known but connecting to all of them failed, the message
|
||||||
|
will contain details about the failures:
|
||||||
|
|
||||||
|
.nf
|
||||||
|
.RS
|
||||||
|
{ "code" : 401, "message" : "..." }
|
||||||
|
|
||||||
|
|
||||||
|
.RE
|
||||||
|
|
||||||
|
.fi
|
||||||
|
|
||||||
|
If the given parameters are wrong:
|
||||||
|
|
||||||
|
.nf
|
||||||
|
.RS
|
||||||
|
{ "code" : -32602, "message" : "..." }
|
||||||
|
|
||||||
|
|
||||||
|
.RE
|
||||||
|
|
||||||
|
.fi
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
|
|
||||||
Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
|
Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
|
||||||
|
|||||||
@@ -37,10 +37,21 @@ RETURN VALUE
|
|||||||
|
|
||||||
On success the peer *id* is returned.
|
On success the peer *id* is returned.
|
||||||
|
|
||||||
The following error codes may occur:
|
ERRORS
|
||||||
- -1: Catchall nonspecific error. This may occur if the host is not
|
------
|
||||||
valid or there are problems communicating with the peer. **connect**
|
|
||||||
will make up to 10 attempts to connect to the peer before giving up.
|
On failure, one of the following errors will be returned:
|
||||||
|
|
||||||
|
{ "code" : 400, "message" : "Unable to connect, no address known for peer" }
|
||||||
|
|
||||||
|
If some addresses are known but connecting to all of them failed, the message
|
||||||
|
will contain details about the failures:
|
||||||
|
|
||||||
|
{ "code" : 401, "message" : "..." }
|
||||||
|
|
||||||
|
If the given parameters are wrong:
|
||||||
|
|
||||||
|
{ "code" : -32602, "message" : "..." }
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
------
|
------
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <hsmd/capabilities.h>
|
#include <hsmd/capabilities.h>
|
||||||
#include <hsmd/gen_hsm_wire.h>
|
#include <hsmd/gen_hsm_wire.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <lightningd/channel.h>
|
#include <lightningd/channel.h>
|
||||||
#include <lightningd/connect_control.h>
|
#include <lightningd/connect_control.h>
|
||||||
#include <lightningd/hsm_control.h>
|
#include <lightningd/hsm_control.h>
|
||||||
@@ -231,21 +232,23 @@ void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
|
|||||||
static void connect_failed(struct lightningd *ld, const u8 *msg)
|
static void connect_failed(struct lightningd *ld, const u8 *msg)
|
||||||
{
|
{
|
||||||
struct node_id id;
|
struct node_id id;
|
||||||
char *err;
|
u32 errcode;
|
||||||
|
char *errmsg;
|
||||||
struct connect *c;
|
struct connect *c;
|
||||||
u32 seconds_to_delay;
|
u32 seconds_to_delay;
|
||||||
struct wireaddr_internal *addrhint;
|
struct wireaddr_internal *addrhint;
|
||||||
struct channel *channel;
|
struct channel *channel;
|
||||||
|
|
||||||
if (!fromwire_connectctl_connect_failed(tmpctx, msg, &id, &err,
|
if (!fromwire_connectctl_connect_failed(tmpctx, msg, &id, &errcode, &errmsg,
|
||||||
&seconds_to_delay, &addrhint))
|
&seconds_to_delay, &addrhint) ||
|
||||||
|
errcode > INT_MAX)
|
||||||
fatal("Connect gave bad CONNECTCTL_CONNECT_FAILED message %s",
|
fatal("Connect gave bad CONNECTCTL_CONNECT_FAILED message %s",
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
|
|
||||||
/* We can have multiple connect commands: fail them all */
|
/* We can have multiple connect commands: fail them all */
|
||||||
while ((c = find_connect(ld, &id)) != NULL) {
|
while ((c = find_connect(ld, &id)) != NULL) {
|
||||||
/* They delete themselves from list */
|
/* They delete themselves from list */
|
||||||
was_pending(command_fail(c->cmd, LIGHTNINGD, "%s", err));
|
was_pending(command_fail(c->cmd, (int)errcode, "%s", errmsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have an active channel, then reconnect. */
|
/* If we have an active channel, then reconnect. */
|
||||||
|
|||||||
Reference in New Issue
Block a user