Skip to content

Commit 72ca305

Browse files
committed
lightnind: add connectd's reported events to the db.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 648bba9 commit 72ca305

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lightningd/connect_control.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ static void connect_failed(struct lightningd *ld,
270270
{
271271
struct connect *c;
272272

273+
/* Don't record twice. */
274+
if (errcode != CONNECT_DISCONNECTED_DURING)
275+
wallet_save_network_event(ld, id,
276+
NETWORK_EVENT_CONNECTFAIL,
277+
errmsg,
278+
connect_nsec);
279+
273280
/* We can have multiple connect commands: fail them all */
274281
while ((c = find_connect(ld, id)) != NULL) {
275282
/* They delete themselves from list */
@@ -494,6 +501,11 @@ static void handle_ping_latency(struct lightningd *ld, const u8 *msg)
494501

495502
log_peer_trace(ld->log, &id, "Ping latency: %"PRIu64"nsec",
496503
nsec);
504+
505+
wallet_save_network_event(ld, &id,
506+
NETWORK_EVENT_PING,
507+
NULL,
508+
nsec);
497509
}
498510

499511
static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fds)

lightningd/peer_control.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,11 @@ void peer_connected(struct lightningd *ld, const u8 *msg)
17501750
fatal("Connectd gave bad CONNECT_PEER_CONNECTED message %s",
17511751
tal_hex(msg, msg));
17521752

1753+
wallet_save_network_event(ld, &id,
1754+
NETWORK_EVENT_CONNECT,
1755+
hook_payload->incoming ? NULL : connect_reason,
1756+
connect_nsec);
1757+
17531758
/* If we connected, and it's a normal address */
17541759
if (!hook_payload->incoming
17551760
&& hook_payload->addr.itype == ADDR_INTERNAL_WIREADDR
@@ -2098,6 +2103,10 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
20982103
fatal("Connectd gave bad PEER_DISCONNECT_DONE message %s",
20992104
tal_hex(msg, msg));
21002105

2106+
wallet_save_network_event(ld, &id,
2107+
NETWORK_EVENT_DISCONNECT,
2108+
NULL, duration_nsec);
2109+
21012110
/* If we still have peer, it's disconnected now */
21022111
/* FIXME: We should keep peers until it tells us they're disconnected,
21032112
* and not free when no more channels. */

lightningd/test/run-invoice-select-inchan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,13 @@ char *wallet_offer_find(const tal_t *ctx UNNEEDED,
10931093
enum offer_status *status)
10941094

10951095
{ fprintf(stderr, "wallet_offer_find called!\n"); abort(); }
1096+
/* Generated stub for wallet_save_network_event */
1097+
void wallet_save_network_event(struct lightningd *ld UNNEEDED,
1098+
const struct node_id *peer_id UNNEEDED,
1099+
enum network_event etype UNNEEDED,
1100+
const char *reason UNNEEDED,
1101+
u64 duration_nsec UNNEEDED)
1102+
{ fprintf(stderr, "wallet_save_network_event called!\n"); abort(); }
10961103
/* Generated stub for wallet_total_forward_fees */
10971104
struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED)
10981105
{ fprintf(stderr, "wallet_total_forward_fees called!\n"); abort(); }

0 commit comments

Comments
 (0)