Skip to content

Commit 689ff1d

Browse files
rustyrussellendothermicdev
authored andcommitted
lightnind: add connectd's reported events to the db.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 13571b5 commit 689ff1d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lightningd/connect_control.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ static void connect_failed(struct lightningd *ld,
262262
{
263263
struct connect *c;
264264

265+
/* Don't record twice. */
266+
if (errcode != CONNECT_DISCONNECTED_DURING)
267+
wallet_save_network_event(ld, id,
268+
NETWORK_EVENT_CONNECTFAIL,
269+
errmsg,
270+
connect_nsec,
271+
connect_attempted);
272+
265273
/* We can have multiple connect commands: fail them all */
266274
while ((c = find_connect(ld, id)) != NULL) {
267275
/* They delete themselves from list */
@@ -490,6 +498,12 @@ static void handle_ping_latency(struct lightningd *ld, const u8 *msg)
490498

491499
log_peer_trace(ld->log, &id, "Ping latency: %"PRIu64"nsec",
492500
nsec);
501+
502+
wallet_save_network_event(ld, &id,
503+
NETWORK_EVENT_PING,
504+
NULL,
505+
nsec,
506+
false);
493507
}
494508

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

lightningd/peer_control.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,12 @@ void handle_peer_connected(struct lightningd *ld, const u8 *msg)
17441744
connect_nsec = 0;
17451745
}
17461746

1747+
wallet_save_network_event(ld, &id,
1748+
NETWORK_EVENT_CONNECT,
1749+
hook_payload->incoming ? NULL : connect_reason,
1750+
connect_nsec,
1751+
false);
1752+
17471753
/* If we connected, and it's a normal address */
17481754
if (!hook_payload->incoming
17491755
&& hook_payload->addr.itype == ADDR_INTERNAL_WIREADDR
@@ -2089,6 +2095,10 @@ static void peer_disconnected(struct lightningd *ld,
20892095
struct disconnect_command *i, *next;
20902096
struct peer *p;
20912097

2098+
wallet_save_network_event(ld, id,
2099+
NETWORK_EVENT_DISCONNECT,
2100+
NULL, connected_time_nsec, false);
2101+
20922102
/* If we still have peer, it's disconnected now */
20932103
p = peer_by_id(ld, id);
20942104
if (p) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ char *wallet_offer_find(const tal_t *ctx UNNEEDED,
687687
enum offer_status *status)
688688

689689
{ fprintf(stderr, "wallet_offer_find called!\n"); abort(); }
690+
/* Generated stub for wallet_save_network_event */
691+
void wallet_save_network_event(struct lightningd *ld UNNEEDED,
692+
const struct node_id *peer_id UNNEEDED,
693+
enum network_event etype UNNEEDED,
694+
const char *reason UNNEEDED,
695+
u64 duration_nsec UNNEEDED,
696+
bool connect_attempted UNNEEDED)
697+
{ fprintf(stderr, "wallet_save_network_event called!\n"); abort(); }
690698
/* Generated stub for wallet_total_forward_fees */
691699
struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED)
692700
{ fprintf(stderr, "wallet_total_forward_fees called!\n"); abort(); }

0 commit comments

Comments
 (0)