2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2020-05-15 12:30:25 +02:00
|
|
|
#include <common/json_helpers.h>
|
2021-09-16 07:00:42 +02:00
|
|
|
#include <common/type_to_string.h>
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
#include <lightningd/channel.h>
|
2019-07-21 13:39:15 +02:00
|
|
|
#include <lightningd/notification.h>
|
2018-12-12 14:36:11 +01:00
|
|
|
|
2019-08-10 23:32:13 +02:00
|
|
|
static struct notification *find_notification_by_topic(const char* topic)
|
|
|
|
{
|
|
|
|
static struct notification **notilist = NULL;
|
|
|
|
static size_t num_notis;
|
|
|
|
if (!notilist)
|
|
|
|
notilist = autodata_get(notifications, &num_notis);
|
|
|
|
|
|
|
|
for (size_t i=0; i<num_notis; i++)
|
|
|
|
if (streq(notilist[i]->topic, topic))
|
|
|
|
return notilist[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-28 15:58:46 +02:00
|
|
|
bool notifications_topic_is_native(const char *topic)
|
2018-12-12 14:36:11 +01:00
|
|
|
{
|
2019-08-10 23:32:13 +02:00
|
|
|
struct notification *noti = find_notification_by_topic(topic);
|
2021-04-28 15:58:46 +02:00
|
|
|
return noti != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool notifications_have_topic(const struct plugins *plugins, const char *topic)
|
|
|
|
{
|
2021-04-28 16:18:40 +02:00
|
|
|
struct plugin *plugin;
|
2021-04-28 15:58:46 +02:00
|
|
|
if (notifications_topic_is_native(topic))
|
2019-08-10 23:32:13 +02:00
|
|
|
return true;
|
|
|
|
|
2021-04-27 15:15:09 +02:00
|
|
|
/* Some plugin at some point announced it'd be emitting
|
2021-04-28 16:18:40 +02:00
|
|
|
* notifications to this topic. */
|
|
|
|
list_for_each(&plugins->plugins, plugin, list) {
|
|
|
|
for (size_t i = 0; i < tal_count(plugin->notification_topics); i++)
|
|
|
|
if (streq(plugin->notification_topics[i], topic))
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-27 15:15:09 +02:00
|
|
|
|
2018-12-12 14:36:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-12-13 13:58:40 +01:00
|
|
|
|
2019-09-02 16:26:11 +02:00
|
|
|
static void connect_notification_serialize(struct json_stream *stream,
|
2021-03-25 04:53:31 +01:00
|
|
|
const struct node_id *nodeid,
|
|
|
|
bool incoming,
|
|
|
|
const struct wireaddr_internal *addr)
|
2019-09-02 16:26:11 +02:00
|
|
|
{
|
|
|
|
json_add_node_id(stream, "id", nodeid);
|
2021-03-25 04:53:31 +01:00
|
|
|
json_add_string(stream, "direction", incoming ? "in" : "out");
|
2019-09-02 16:26:11 +02:00
|
|
|
json_add_address_internal(stream, "address", addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(connect,
|
|
|
|
connect_notification_serialize);
|
|
|
|
|
2021-03-25 04:53:31 +01:00
|
|
|
void notify_connect(struct lightningd *ld,
|
|
|
|
const struct node_id *nodeid,
|
|
|
|
bool incoming,
|
|
|
|
const struct wireaddr_internal *addr)
|
2018-12-13 13:58:40 +01:00
|
|
|
{
|
2019-09-02 16:26:11 +02:00
|
|
|
void (*serialize)(struct json_stream *,
|
2021-03-25 04:53:31 +01:00
|
|
|
const struct node_id *,
|
|
|
|
bool,
|
|
|
|
const struct wireaddr_internal *) = connect_notification_gen.serialize;
|
2019-09-02 16:26:11 +02:00
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, connect_notification_gen.topic);
|
2021-03-25 04:53:31 +01:00
|
|
|
serialize(n->stream, nodeid, incoming, addr);
|
2018-12-13 13:58:40 +01:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:28:05 +02:00
|
|
|
static void disconnect_notification_serialize(struct json_stream *stream,
|
|
|
|
struct node_id *nodeid)
|
|
|
|
{
|
|
|
|
json_add_node_id(stream, "id", nodeid);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(disconnect,
|
|
|
|
disconnect_notification_serialize);
|
|
|
|
|
2019-04-08 11:58:32 +02:00
|
|
|
void notify_disconnect(struct lightningd *ld, struct node_id *nodeid)
|
2018-12-13 13:58:40 +01:00
|
|
|
{
|
2019-09-02 16:28:05 +02:00
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct node_id *) = disconnect_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, disconnect_notification_gen.topic);
|
|
|
|
serialize(n->stream, nodeid);
|
2018-12-13 13:58:40 +01:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
|
|
|
|
/*'warning' is based on LOG_UNUSUAL/LOG_BROKEN level log
|
|
|
|
*(in plugin module, they're 'warn'/'error' level). */
|
2019-09-02 16:28:46 +02:00
|
|
|
static void warning_notification_serialize(struct json_stream *stream,
|
|
|
|
struct log_entry *l)
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
{
|
2019-09-02 16:28:46 +02:00
|
|
|
json_object_start(stream, "warning");
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
/* Choose "BROKEN"/"UNUSUAL" to keep consistent with the habit
|
|
|
|
* of plugin. But this may confuses the users who want to 'getlog'
|
|
|
|
* with the level indicated by notifications. It is the duty of a
|
|
|
|
* plugin to eliminate this misunderstanding.
|
|
|
|
*/
|
2019-09-02 16:28:46 +02:00
|
|
|
json_add_string(stream, "level",
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
l->level == LOG_BROKEN ? "error"
|
|
|
|
: "warn");
|
|
|
|
/* unsuaul/broken event is rare, plugin pay more attentions on
|
|
|
|
* the absolute time, like when channels failed. */
|
2019-09-02 16:28:46 +02:00
|
|
|
json_add_time(stream, "time", l->time.ts);
|
2020-10-28 11:46:22 +01:00
|
|
|
json_add_timeiso(stream, "timestamp", &l->time);
|
2021-11-24 20:59:18 +01:00
|
|
|
json_add_string(stream, "source", l->prefix->prefix);
|
2019-09-02 16:28:46 +02:00
|
|
|
json_add_string(stream, "log", l->log);
|
|
|
|
json_object_end(stream); /* .warning */
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(warning,
|
|
|
|
warning_notification_serialize);
|
|
|
|
|
|
|
|
void notify_warning(struct lightningd *ld, struct log_entry *l)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct log_entry *) = warning_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, warning_notification_gen.topic);
|
|
|
|
serialize(n->stream, l);
|
plugin: Add new notification type: warning
This notification bases on `LOG_BROKEN` and `LOG_UNUSUAL` level log.
--Introduction
A notification for topic `warning` is sent every time a new `BROKEN`/
`UNUSUAL` level(in plugins, we use `error`/`warn`) log generated, which
means an unusual/borken thing happens, such as channel failed,
message resolving failed...
```json
{
"warning": {
"level": "warn",
"time": "1559743608.565342521",
"source": "lightningd(17652): 0821f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c chan #7854:",
"log": "Peer permanent failure in CHANNELD_NORMAL: lightning_channeld: sent ERROR bad reestablish dataloss msg"
}
}
```
1. `level` is `warn` or `error`:
`warn` means something seems bad happened and it's under control, but
we'd better check it;
`error` means something extremely bad is out of control, and it may lead
to crash;
2. `time` is the second since epoch;
3. `source`, in fact, is the `prefix` of the log_entry. It means where
the event happened, it may have the following forms:
`<node_id> chan #<db_id_of_channel>:`, `lightningd(<lightningd_pid>):`,
`plugin-<plugin_name>:`, `<daemon_name>(<daemon_pid>):`, `jsonrpc:`,
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
--Note:
1. The main code uses `UNUSUAL`/`BROKEN`, and plugin module uses `warn`
/`error`, considering the consistency with plugin, warning choose `warn`
/`error`. But users who use c-lightning with plugins may want to
`getlog` with specified level when receive warning. It's the duty for
plugin dev to turn `warn`/`error` into `UNUSUAL`/`BROKEN` and present it
to the users, or pass it directly to `getlog`;
2. About time, `json_log()` in `log` module uses the Relative Time, from
the time when `log_book` inited to the time when this event happend.
But I consider the `UNUSUAL`/`BROKEN` event is rare, and it is very
likely to happen after running for a long time, so for users, they will
pay more attention to Absolute Time.
-- Related Change
1. Remove the definitions of `log`, `log_book`, `log_entry` from `log.c`
to `log.h`, then they can be used in warning declaration and definition.
2. Remove `void json_add_time(struct json_stream *result, const char
*fieldname, struct timespec ts)` from `log.c` to `json.c`, and add
related declaration in `json.h`. Now the notification function in
`notification.c` can call it.
2. Add a pointer to `struct lightningd` in `struct log_book`. This may
affect the independence of the `log` module, but storing a pointer to
`ld` is more direct;
2019-06-03 20:26:58 +02:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
2019-07-21 13:39:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-02 16:30:32 +02:00
|
|
|
static void invoice_payment_notification_serialize(struct json_stream *stream,
|
|
|
|
struct amount_msat amount,
|
|
|
|
struct preimage preimage,
|
|
|
|
const struct json_escape *label)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "invoice_payment");
|
|
|
|
json_add_string(stream, "msat",
|
|
|
|
type_to_string(tmpctx, struct amount_msat, &amount));
|
|
|
|
json_add_hex(stream, "preimage", &preimage, sizeof(preimage));
|
|
|
|
json_add_escaped_string(stream, "label", label);
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(invoice_payment,
|
|
|
|
invoice_payment_notification_serialize)
|
|
|
|
|
2019-07-21 13:39:15 +02:00
|
|
|
void notify_invoice_payment(struct lightningd *ld, struct amount_msat amount,
|
|
|
|
struct preimage preimage, const struct json_escape *label)
|
|
|
|
{
|
2019-09-02 16:30:32 +02:00
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct amount_msat,
|
|
|
|
struct preimage,
|
|
|
|
const struct json_escape *) = invoice_payment_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, invoice_payment_notification_gen.topic);
|
|
|
|
serialize(n->stream, amount, preimage, label);
|
2019-07-21 13:39:15 +02:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
2019-07-25 16:11:44 +02:00
|
|
|
|
2020-04-21 03:04:01 +02:00
|
|
|
static void invoice_creation_notification_serialize(struct json_stream *stream,
|
|
|
|
struct amount_msat *amount,
|
|
|
|
struct preimage preimage,
|
|
|
|
const struct json_escape *label)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "invoice_creation");
|
|
|
|
if (amount != NULL)
|
|
|
|
json_add_string(
|
|
|
|
stream, "msat",
|
|
|
|
type_to_string(tmpctx, struct amount_msat, amount));
|
|
|
|
|
|
|
|
json_add_hex(stream, "preimage", &preimage, sizeof(preimage));
|
|
|
|
json_add_escaped_string(stream, "label", label);
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(invoice_creation,
|
|
|
|
invoice_creation_notification_serialize)
|
|
|
|
|
|
|
|
void notify_invoice_creation(struct lightningd *ld, struct amount_msat *amount,
|
|
|
|
struct preimage preimage,
|
|
|
|
const struct json_escape *label)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct amount_msat *,
|
|
|
|
struct preimage,
|
|
|
|
const struct json_escape *) = invoice_creation_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, invoice_creation_notification_gen.topic);
|
|
|
|
serialize(n->stream, amount, preimage, label);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
|
|
|
|
2021-10-13 05:45:36 +02:00
|
|
|
/* FIXME: Use outpoint here! */
|
2019-09-02 16:31:15 +02:00
|
|
|
static void channel_opened_notification_serialize(struct json_stream *stream,
|
|
|
|
struct node_id *node_id,
|
|
|
|
struct amount_sat *funding_sat,
|
|
|
|
struct bitcoin_txid *funding_txid,
|
|
|
|
bool *funding_locked)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "channel_opened");
|
|
|
|
json_add_node_id(stream, "id", node_id);
|
|
|
|
json_add_amount_sat_only(stream, "amount", *funding_sat);
|
|
|
|
json_add_txid(stream, "funding_txid", funding_txid);
|
|
|
|
json_add_bool(stream, "funding_locked", funding_locked);
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(channel_opened,
|
|
|
|
channel_opened_notification_serialize)
|
|
|
|
|
2019-07-25 16:11:44 +02:00
|
|
|
void notify_channel_opened(struct lightningd *ld, struct node_id *node_id,
|
|
|
|
struct amount_sat *funding_sat, struct bitcoin_txid *funding_txid,
|
|
|
|
bool *funding_locked)
|
|
|
|
{
|
2019-09-02 16:31:15 +02:00
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct node_id *,
|
|
|
|
struct amount_sat *,
|
|
|
|
struct bitcoin_txid *,
|
|
|
|
bool *) = channel_opened_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, channel_opened_notification_gen.topic);
|
|
|
|
serialize(n->stream, node_id, funding_sat, funding_txid, funding_locked);
|
2019-07-25 16:11:44 +02:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
|
2020-09-08 16:11:05 +02:00
|
|
|
static void channel_state_changed_notification_serialize(struct json_stream *stream,
|
|
|
|
struct node_id *peer_id,
|
|
|
|
struct channel_id *cid,
|
|
|
|
struct short_channel_id *scid,
|
2020-10-28 11:46:21 +01:00
|
|
|
struct timeabs *timestamp,
|
2020-09-08 16:11:05 +02:00
|
|
|
enum channel_state old_state,
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
enum channel_state new_state,
|
|
|
|
enum state_change cause,
|
|
|
|
char *message)
|
2020-09-08 16:11:05 +02:00
|
|
|
{
|
|
|
|
json_object_start(stream, "channel_state_changed");
|
|
|
|
json_add_node_id(stream, "peer_id", peer_id);
|
2020-10-08 22:41:12 +02:00
|
|
|
json_add_channel_id(stream, "channel_id", cid);
|
2020-09-08 16:11:05 +02:00
|
|
|
if (scid)
|
|
|
|
json_add_short_channel_id(stream, "short_channel_id", scid);
|
|
|
|
else
|
|
|
|
json_add_null(stream, "short_channel_id");
|
2020-10-28 11:46:21 +01:00
|
|
|
json_add_timeiso(stream, "timestamp", timestamp);
|
2020-09-08 16:11:05 +02:00
|
|
|
json_add_string(stream, "old_state", channel_state_str(old_state));
|
|
|
|
json_add_string(stream, "new_state", channel_state_str(new_state));
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
json_add_string(stream, "cause", channel_change_state_reason_str(cause));
|
|
|
|
if (message != NULL)
|
|
|
|
json_add_string(stream, "message", message);
|
|
|
|
else
|
|
|
|
json_add_null(stream, "message");
|
2020-09-08 16:11:05 +02:00
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(channel_state_changed,
|
|
|
|
channel_state_changed_notification_serialize)
|
|
|
|
|
|
|
|
void notify_channel_state_changed(struct lightningd *ld,
|
|
|
|
struct node_id *peer_id,
|
|
|
|
struct channel_id *cid,
|
|
|
|
struct short_channel_id *scid,
|
2020-10-28 11:46:21 +01:00
|
|
|
struct timeabs *timestamp,
|
2020-09-08 16:11:05 +02:00
|
|
|
enum channel_state old_state,
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
enum channel_state new_state,
|
|
|
|
enum state_change cause,
|
|
|
|
char *message)
|
2020-09-08 16:11:05 +02:00
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
struct node_id *,
|
|
|
|
struct channel_id *,
|
|
|
|
struct short_channel_id *,
|
2020-10-28 11:46:21 +01:00
|
|
|
struct timeabs *timestamp,
|
2020-09-08 16:11:05 +02:00
|
|
|
enum channel_state,
|
feat: adds state change cause and message
This adds a `state_change` 'cause' to a channel.
A 'cause' is some initial 'reason' a channel was created or closed by:
/* Anything other than the reasons below. Should not happen. */
REASON_UNKNOWN,
/* Unconscious internal reasons, e.g. dev fail of a channel. */
REASON_LOCAL,
/* The operator or a plugin opened or closed a channel by intention. */
REASON_USER,
/* The remote closed or funded a channel with us by intention. */
REASON_REMOTE,
/* E.g. We need to close a channel because of bad signatures and such. */
REASON_PROTOCOL,
/* A channel was closed onchain, while we were offline. */
/* Note: This is very likely a conscious remote decision. */
REASON_ONCHAIN
If a 'cause' is known and a subsequent state change is made with
`REASON_UNKNOWN` the preceding cause will be used as reason, since a lot
(all `REASON_UNKNOWN`) state changes are a subsequent consequences of a prior
cause: local, user, remote, protocol or onchain.
Changelog-Added: Plugins: Channel closure resaon/cause to channel_state_changed notification
2020-10-28 11:46:12 +01:00
|
|
|
enum channel_state,
|
|
|
|
enum state_change,
|
|
|
|
char *message) = channel_state_changed_notification_gen.serialize;
|
2020-09-08 16:11:05 +02:00
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, channel_state_changed_notification_gen.topic);
|
2020-10-28 11:46:21 +01:00
|
|
|
serialize(n->stream, peer_id, cid, scid, timestamp, old_state, new_state, cause, message);
|
2020-09-08 16:11:05 +02:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:31:51 +02:00
|
|
|
static void forward_event_notification_serialize(struct json_stream *stream,
|
|
|
|
const struct htlc_in *in,
|
2020-02-13 03:11:01 +01:00
|
|
|
const struct short_channel_id *scid_out,
|
|
|
|
const struct amount_msat *amount_out,
|
2019-09-02 16:31:51 +02:00
|
|
|
enum forward_status state,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire failcode,
|
2019-09-02 16:31:51 +02:00
|
|
|
struct timeabs *resolved_time)
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
{
|
|
|
|
/* Here is more neat to initial a forwarding structure than
|
|
|
|
* to pass in a bunch of parameters directly*/
|
|
|
|
struct forwarding *cur = tal(tmpctx, struct forwarding);
|
|
|
|
cur->channel_in = *in->key.channel->scid;
|
|
|
|
cur->msat_in = in->msat;
|
2020-02-13 03:11:01 +01:00
|
|
|
if (scid_out) {
|
|
|
|
cur->channel_out = *scid_out;
|
|
|
|
if (amount_out) {
|
|
|
|
cur->msat_out = *amount_out;
|
2020-02-13 06:31:04 +01:00
|
|
|
if (!amount_msat_sub(&cur->fee,
|
|
|
|
in->msat, *amount_out))
|
|
|
|
abort();
|
2020-02-13 03:11:01 +01:00
|
|
|
} else {
|
|
|
|
cur->msat_out = AMOUNT_MSAT(0);
|
|
|
|
cur->fee = AMOUNT_MSAT(0);
|
|
|
|
}
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
} else {
|
|
|
|
cur->channel_out.u64 = 0;
|
|
|
|
cur->msat_out = AMOUNT_MSAT(0);
|
|
|
|
cur->fee = AMOUNT_MSAT(0);
|
|
|
|
}
|
2019-08-10 10:13:40 +02:00
|
|
|
cur->payment_hash = tal_dup(cur, struct sha256, &in->payment_hash);
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
cur->status = state;
|
|
|
|
cur->failcode = failcode;
|
|
|
|
cur->received_time = in->received_time;
|
|
|
|
cur->resolved_time = tal_steal(cur, resolved_time);
|
|
|
|
|
2019-09-02 16:31:51 +02:00
|
|
|
json_format_forwarding_object(stream, "forward_event", cur);
|
|
|
|
}
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
|
2019-09-02 16:31:51 +02:00
|
|
|
REGISTER_NOTIFICATION(forward_event,
|
|
|
|
forward_event_notification_serialize);
|
|
|
|
|
|
|
|
void notify_forward_event(struct lightningd *ld,
|
|
|
|
const struct htlc_in *in,
|
2020-02-13 03:11:01 +01:00
|
|
|
const struct short_channel_id *scid_out,
|
|
|
|
const struct amount_msat *amount_out,
|
2019-09-02 16:31:51 +02:00
|
|
|
enum forward_status state,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire failcode,
|
2019-09-02 16:31:51 +02:00
|
|
|
struct timeabs *resolved_time)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct htlc_in *,
|
2020-02-13 03:11:01 +01:00
|
|
|
const struct short_channel_id *,
|
|
|
|
const struct amount_msat *,
|
2019-09-02 16:31:51 +02:00
|
|
|
enum forward_status,
|
2020-08-31 03:13:25 +02:00
|
|
|
enum onion_wire,
|
2019-09-02 16:31:51 +02:00
|
|
|
struct timeabs *) = forward_event_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n
|
|
|
|
= jsonrpc_notification_start(NULL, forward_event_notification_gen.topic);
|
2020-02-13 03:11:01 +01:00
|
|
|
serialize(n->stream, in, scid_out, amount_out, state, failcode, resolved_time);
|
Plugin: New notification type, forward_event
`forward_event`
A notification for topic `forward_event` is sent every time the status
of a forward payment is set. The json format is same as the API
`listforwards`.
```json
{
"forward_event": {
"payment_hash": "f5a6a059a25d1e329d9b094aeeec8c2191ca037d3f5b0662e21ae850debe8ea2",
"in_channel": "103x2x1",
"out_channel": "103x1x1",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "settled",
"received_time": 1560696342.368,
"resolved_time": 1560696342.556
}
}
```
or
```json
{
"forward_event": {
"payment_hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"in_channel": "103x2x1",
"out_channel": "110x1x0",
"in_msatoshi": 100001001,
"in_msat": "100001001msat",
"out_msatoshi": 100000000,
"out_msat": "100000000msat",
"fee": 1001,
"fee_msat": "1001msat",
"status": "local_failed",
"failcode": 16392,
"failreason": "WIRE_PERMANENT_CHANNEL_FAILURE",
"received_time": 1560696343.052
}
}
```
- The status includes `offered`, `settled`, `failed` and `local_failed`,
and they are all string type in json.
- When the forward payment is valid for us, we'll set `offered`
and send the forward payment to next hop to resolve;
- When the payment forwarded by us gets paid eventually, the forward
payment will change the status from `offered` to `settled`;
- If payment fails locally(like failing to resolve locally) or the
corresponding htlc with next hop fails(like htlc timeout), we will
set the status as `local_failed`. `local_failed` may be set before
setting `offered` or after setting `offered`. In fact, from the
time we receive the htlc of the previous hop, all we can know the
cause of the failure is treated as `local_failed`. `local_failed`
only occuors locally or happens in the htlc between us and next hop;
- If `local_failed` is set before `offered`, this
means we just received htlc from the previous hop and haven't
generate htlc for next hop. In this case, the json of `forward_event`
sets the fields of `out_msatoshi`, `out_msat`,`fee` and `out_channel`
as 0;
- Note: In fact, for this case we may be not sure if this incoming
htlc represents a pay to us or a payment we need to forward.
We just simply treat all incoming failed to resolve as
`local_failed`.
- Only in `local_failed` case, json includes `failcode` and
`failreason` fields;
- `failed` means the payment forwarded by us fails in the
latter hops, and the failure isn't related to us, so we aren't
accessed to the fail reason. `failed` must be set after
`offered`.
- `failed` case doesn't include `failcode` and `failreason`
fields;
- `received_time` means when we received the htlc of this payment from
the previous peer. It will be contained into all status case;
- `resolved_time` means when the htlc of this payment between us and the
next peer was resolved. The resolved result may success or fail, so
only `settled` and `failed` case contain `resolved_time`;
- The `failcode` and `failreason` are defined in [BOLT 4][bolt4-failure-codes].
2019-06-15 15:09:09 +02:00
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
plugin: A new notification type, 'sendpay_success'
`sendpay_success`
A notification for topic `sendpay_success` is sent every time a sendpay
success(with `complete` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when these cammand succeeds.
```json
{
"sendpay_success": {
"id": 1,
"payment_hash": "5c85bf402b87d4860f4a728e2e58a2418bda92cd7aea0ce494f11670cfbfb206",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561390572,
"status": "complete",
"payment_preimage": "9540d98095fd7f37687ebb7759e733934234d4f934e34433d4998a37de3733ee"
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_success` will always return the result anytime when sendpay
successes if is was subscribed.
2019-06-25 09:27:35 +02:00
|
|
|
|
|
|
|
static void sendpay_success_notification_serialize(struct json_stream *stream,
|
|
|
|
const struct wallet_payment *payment)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "sendpay_success");
|
|
|
|
json_add_payment_fields(stream, payment);
|
|
|
|
json_object_end(stream); /* .sendpay_success */
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(sendpay_success,
|
|
|
|
sendpay_success_notification_serialize);
|
|
|
|
|
|
|
|
void notify_sendpay_success(struct lightningd *ld,
|
|
|
|
const struct wallet_payment *payment)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct wallet_payment *) = sendpay_success_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "sendpay_success");
|
|
|
|
serialize(n->stream, payment);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
|
|
|
|
static void sendpay_failure_notification_serialize(struct json_stream *stream,
|
|
|
|
const struct wallet_payment *payment,
|
2020-01-26 13:52:29 +01:00
|
|
|
errcode_t pay_errcode,
|
2020-01-23 00:38:04 +01:00
|
|
|
const struct onionreply *onionreply,
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
const struct routing_failure *fail,
|
|
|
|
char *errmsg)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "sendpay_failure");
|
|
|
|
|
|
|
|
/* In line with the format of json error returned
|
|
|
|
* by sendpay_fail(). */
|
2020-01-26 13:52:29 +01:00
|
|
|
json_add_member(stream, "code", false, "%" PRIerrcode, pay_errcode);
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
json_add_string(stream, "message", errmsg);
|
|
|
|
|
|
|
|
json_object_start(stream, "data");
|
|
|
|
json_sendpay_fail_fields(stream,
|
|
|
|
payment,
|
|
|
|
pay_errcode,
|
|
|
|
onionreply,
|
|
|
|
fail);
|
|
|
|
|
|
|
|
json_object_end(stream); /* .data */
|
|
|
|
json_object_end(stream); /* .sendpay_failure */
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(sendpay_failure,
|
|
|
|
sendpay_failure_notification_serialize);
|
|
|
|
|
|
|
|
void notify_sendpay_failure(struct lightningd *ld,
|
|
|
|
const struct wallet_payment *payment,
|
2020-01-26 13:52:29 +01:00
|
|
|
errcode_t pay_errcode,
|
2020-01-23 00:38:04 +01:00
|
|
|
const struct onionreply *onionreply,
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
const struct routing_failure *fail,
|
2020-01-07 16:31:00 +01:00
|
|
|
const char *errmsg)
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct wallet_payment *,
|
2020-01-26 13:52:29 +01:00
|
|
|
errcode_t,
|
2020-01-23 00:38:04 +01:00
|
|
|
const struct onionreply *,
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
const struct routing_failure *,
|
2020-01-07 16:31:00 +01:00
|
|
|
const char *) = sendpay_failure_notification_gen.serialize;
|
plugin: Another new notification type, 'sendpay_failure'
(The json when sendpay successes is too different when sendpay fails, so
divide the sendpay result into two notifications: `sendpay_success` and
`sendpay_failure`)
`sendpay_failure`
A notification for topic `sendpay_failure` is sent every time a sendpay
success(with `failed` status). The json is same as the return value of
command `sendpay`/`waitsendpay` when this cammand fails.
```json
{
"sendpay_failure": {
"code": 204,
"message": "failed: WIRE_UNKNOWN_NEXT_PEER (reply from remote)",
"data": {
"id": 2,
"payment_hash": "9036e3bdbd2515f1e653cb9f22f8e4c49b73aa2c36e937c926f43e33b8db8851",
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"msatoshi": 100000000,
"amount_msat": "100000000msat",
"msatoshi_sent": 100001001,
"amount_sent_msat": "100001001msat",
"created_at": 1561395134,
"status": "failed",
"erring_index": 1,
"failcode": 16394,
"failcodename": "WIRE_UNKNOWN_NEXT_PEER",
"erring_node": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59",
"erring_channel": "103x2x1",
"erring_direction": 0
}
}
}
```
`sendpay` doesn't wait for the result of sendpay and `waitsendpay`
returns the result of sendpay in specified time or timeout, but
`sendpay_failure` will always return the result anytime when sendpay
fails if is was subscribed.
2019-06-25 09:45:16 +02:00
|
|
|
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "sendpay_failure");
|
|
|
|
serialize(n->stream, payment, pay_errcode, onionreply, fail, errmsg);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
2020-03-19 00:35:59 +01:00
|
|
|
|
|
|
|
static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type,
|
|
|
|
struct mvt_id *id)
|
|
|
|
{
|
|
|
|
switch (mvt_type) {
|
|
|
|
case CHAIN_MVT:
|
|
|
|
/* some 'journal entries' don't have a txid */
|
|
|
|
if (id->tx_txid)
|
|
|
|
json_add_string(stream, "txid",
|
|
|
|
type_to_string(tmpctx, struct bitcoin_txid,
|
|
|
|
id->tx_txid));
|
|
|
|
/* some chain ledger entries aren't associated with a utxo
|
|
|
|
* e.g. journal updates (due to penalty/state loss) and
|
|
|
|
* chain_fee entries */
|
2021-10-13 05:45:36 +02:00
|
|
|
if (id->outpoint) {
|
2020-03-19 00:35:59 +01:00
|
|
|
json_add_string(stream, "utxo_txid",
|
|
|
|
type_to_string(tmpctx, struct bitcoin_txid,
|
2021-10-13 05:45:36 +02:00
|
|
|
&id->outpoint->txid));
|
|
|
|
json_add_u32(stream, "vout", id->outpoint->n);
|
2020-03-19 00:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* on-chain htlcs include a payment hash */
|
|
|
|
if (id->payment_hash)
|
|
|
|
json_add_sha256(stream, "payment_hash", id->payment_hash);
|
|
|
|
return;
|
|
|
|
case CHANNEL_MVT:
|
|
|
|
json_add_sha256(stream, "payment_hash", id->payment_hash);
|
|
|
|
if (id->part_id)
|
2020-04-14 21:01:18 +02:00
|
|
|
json_add_u64(stream, "part_id", *id->part_id);
|
2020-03-19 00:35:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void coin_movement_notification_serialize(struct json_stream *stream,
|
|
|
|
struct coin_mvt *mvt)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "coin_movement");
|
|
|
|
json_add_num(stream, "version", mvt->version);
|
|
|
|
json_add_node_id(stream, "node_id", mvt->node_id);
|
|
|
|
json_add_u64(stream, "movement_idx", mvt->counter);
|
|
|
|
json_add_string(stream, "type", mvt_type_str(mvt->type));
|
|
|
|
json_add_string(stream, "account_id", mvt->account_id);
|
|
|
|
json_mvt_id(stream, mvt->type, &mvt->id);
|
|
|
|
json_add_amount_msat_only(stream, "credit", mvt->credit);
|
|
|
|
json_add_amount_msat_only(stream, "debit", mvt->debit);
|
|
|
|
json_add_string(stream, "tag", mvt_tag_str(mvt->tag));
|
2020-04-03 23:52:35 +02:00
|
|
|
|
|
|
|
/* Only chain movements have blockheights. A blockheight
|
|
|
|
* of 'zero' means we haven't seen this tx confirmed yet. */
|
|
|
|
if (mvt->type == CHAIN_MVT) {
|
|
|
|
if (mvt->blockheight)
|
|
|
|
json_add_u32(stream, "blockheight", mvt->blockheight);
|
|
|
|
else
|
|
|
|
json_add_null(stream, "blockheight");
|
|
|
|
}
|
2020-03-19 00:35:59 +01:00
|
|
|
json_add_u32(stream, "timestamp", mvt->timestamp);
|
2020-04-15 05:40:28 +02:00
|
|
|
json_add_string(stream, "coin_type", mvt->bip173_name);
|
2020-03-19 00:35:59 +01:00
|
|
|
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(coin_movement,
|
|
|
|
coin_movement_notification_serialize);
|
|
|
|
|
|
|
|
void notify_coin_mvt(struct lightningd *ld,
|
|
|
|
const struct coin_mvt *mvt)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct coin_mvt *) = coin_movement_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "coin_movement");
|
|
|
|
serialize(n->stream, mvt);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
2020-10-09 00:21:20 +02:00
|
|
|
|
|
|
|
static void openchannel_peer_sigs_serialize(struct json_stream *stream,
|
|
|
|
const struct channel_id *cid,
|
|
|
|
const struct wally_psbt *psbt)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "openchannel_peer_sigs");
|
|
|
|
json_add_channel_id(stream, "channel_id", cid);
|
|
|
|
json_add_psbt(stream, "signed_psbt", psbt);
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(openchannel_peer_sigs,
|
|
|
|
openchannel_peer_sigs_serialize);
|
|
|
|
|
|
|
|
void notify_openchannel_peer_sigs(struct lightningd *ld,
|
|
|
|
const struct channel_id *cid,
|
|
|
|
const struct wally_psbt *psbt)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct channel_id *cid,
|
|
|
|
const struct wally_psbt *) = openchannel_peer_sigs_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "openchannel_peer_sigs");
|
|
|
|
serialize(n->stream, cid, psbt);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
2020-12-17 22:28:51 +01:00
|
|
|
|
|
|
|
static void channel_open_failed_serialize(struct json_stream *stream,
|
|
|
|
const struct channel_id *cid)
|
|
|
|
{
|
|
|
|
json_object_start(stream, "channel_open_failed");
|
|
|
|
json_add_channel_id(stream, "channel_id", cid);
|
|
|
|
json_object_end(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_NOTIFICATION(channel_open_failed,
|
|
|
|
channel_open_failed_serialize);
|
|
|
|
|
|
|
|
void notify_channel_open_failed(struct lightningd *ld,
|
|
|
|
const struct channel_id *cid)
|
|
|
|
{
|
|
|
|
void (*serialize)(struct json_stream *,
|
|
|
|
const struct channel_id *) = channel_open_failed_notification_gen.serialize;
|
|
|
|
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "channel_open_failed");
|
|
|
|
serialize(n->stream, cid);
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
plugins_notify(ld->plugins, take(n));
|
|
|
|
}
|
2021-09-03 12:16:18 +02:00
|
|
|
|
2021-09-09 10:02:19 +02:00
|
|
|
REGISTER_NOTIFICATION(shutdown, NULL);
|
2021-09-03 12:16:18 +02:00
|
|
|
|
|
|
|
bool notify_plugin_shutdown(struct lightningd *ld, struct plugin *p)
|
|
|
|
{
|
|
|
|
struct jsonrpc_notification *n =
|
|
|
|
jsonrpc_notification_start(NULL, "shutdown");
|
|
|
|
|
|
|
|
jsonrpc_notification_end(n);
|
|
|
|
return plugin_single_notify(p, take(n));
|
|
|
|
}
|