Browse Source

memleak: 'generify' the memleak calling to code for openingd/dualopend

Switch on name of subd(aemon) as to whether to call dualopend or
openingd for memleak results
pyln
niftynei 4 years ago
committed by Rusty Russell
parent
commit
9f006fdf03
  1. 2
      lightningd/memdump.c
  2. 81
      lightningd/opening_common.c
  3. 7
      lightningd/opening_common.h
  4. 66
      lightningd/opening_control.c
  5. 6
      lightningd/opening_control.h

2
lightningd/memdump.c

@ -18,7 +18,7 @@
#include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h>
#include <lightningd/log.h>
#include <lightningd/opening_control.h>
#include <lightningd/opening_common.h>
#include <lightningd/peer_control.h>
#include <lightningd/subd.h>
#include <stdio.h>

81
lightningd/opening_common.c

@ -8,6 +8,8 @@
#include <lightningd/opening_common.h>
#include <lightningd/peer_control.h>
#include <lightningd/subd.h>
#include <openingd/dualopend_wiregen.h>
#include <openingd/openingd_wiregen.h>
#include <wallet/wallet.h>
static void destroy_uncommitted_channel(struct uncommitted_channel *uc)
@ -144,3 +146,82 @@ void channel_config(struct lightningd *ld,
/* This is filled in by lightning_openingd, for consistency. */
ours->channel_reserve = AMOUNT_SAT(UINT64_MAX);
}
#if DEVELOPER
/* Indented to avoid include ordering check */
#include <lightningd/memdump.h>
static void opening_died_forget_memleak(struct subd *open_daemon,
struct command *cmd)
{
/* FIXME: We ignore the remaining opening daemons in this case. */
opening_memleak_done(cmd, NULL);
}
/* Mutual recursion */
static void opening_memleak_req_next(struct command *cmd, struct peer *prev);
static void opening_memleak_req_done(struct subd *open_daemon,
const u8 *msg, const int *fds UNUSED,
struct command *cmd)
{
bool found_leak;
struct uncommitted_channel *uc = open_daemon->channel;
tal_del_destructor2(open_daemon, opening_died_forget_memleak, cmd);
if (!fromwire_openingd_dev_memleak_reply(msg, &found_leak) &&
!fromwire_dual_open_dev_memleak_reply(msg,
&found_leak)) {
was_pending(command_fail(cmd, LIGHTNINGD,
"Bad opening_dev_memleak"));
return;
}
if (found_leak) {
opening_memleak_done(cmd, open_daemon);
return;
}
opening_memleak_req_next(cmd, uc->peer);
}
static void opening_memleak_req_next(struct command *cmd, struct peer *prev)
{
struct peer *p;
u8 *msg;
list_for_each(&cmd->ld->peers, p, list) {
struct subd *open_daemon;
if (!p->uncommitted_channel)
continue;
if (p == prev) {
prev = NULL;
continue;
}
if (prev != NULL)
continue;
open_daemon = p->uncommitted_channel->open_daemon;
if (!open_daemon)
continue;
if (streq(open_daemon->name, "dualopend"))
msg = towire_dual_open_dev_memleak(NULL);
else
msg = towire_openingd_dev_memleak(NULL);
subd_req(p, open_daemon, take(msg), -1, 0,
opening_memleak_req_done, cmd);
/* Just in case it dies before replying! */
tal_add_destructor2(p->uncommitted_channel->open_daemon,
opening_died_forget_memleak, cmd);
return;
}
opening_memleak_done(cmd, NULL);
}
void opening_dev_memleak(struct command *cmd)
{
opening_memleak_req_next(cmd, NULL);
}
#endif /* DEVELOPER */

7
lightningd/opening_common.h

@ -101,4 +101,11 @@ void channel_config(struct lightningd *ld,
struct channel_config *ours,
u32 *max_to_self_delay,
struct amount_msat *min_effective_htlc_capacity);
#if DEVELOPER
struct command;
/* Calls report_leak_info() async. */
void opening_dev_memleak(struct command *cmd);
#endif
#endif /* LIGHTNING_LIGHTNINGD_OPENING_COMMON_H */

66
lightningd/opening_control.c

@ -1148,72 +1148,6 @@ static const struct json_command fund_channel_complete_command = {
};
AUTODATA(json_command, &fund_channel_complete_command);
#if DEVELOPER
/* Indented to avoid include ordering check */
#include <lightningd/memdump.h>
static void opening_died_forget_memleak(struct subd *openingd,
struct command *cmd)
{
/* FIXME: We ignore the remaining openingds in this case. */
opening_memleak_done(cmd, NULL);
}
/* Mutual recursion */
static void opening_memleak_req_next(struct command *cmd, struct peer *prev);
static void opening_memleak_req_done(struct subd *openingd,
const u8 *msg, const int *fds UNUSED,
struct command *cmd)
{
bool found_leak;
struct uncommitted_channel *uc = openingd->channel;
tal_del_destructor2(openingd, opening_died_forget_memleak, cmd);
if (!fromwire_openingd_dev_memleak_reply(msg, &found_leak)) {
was_pending(command_fail(cmd, LIGHTNINGD,
"Bad opening_dev_memleak"));
return;
}
if (found_leak) {
opening_memleak_done(cmd, openingd);
return;
}
opening_memleak_req_next(cmd, uc->peer);
}
static void opening_memleak_req_next(struct command *cmd, struct peer *prev)
{
struct peer *p;
list_for_each(&cmd->ld->peers, p, list) {
if (!p->uncommitted_channel)
continue;
if (p == prev) {
prev = NULL;
continue;
}
if (prev != NULL)
continue;
subd_req(p,
p->uncommitted_channel->open_daemon,
take(towire_openingd_dev_memleak(NULL)),
-1, 0, opening_memleak_req_done, cmd);
/* Just in case it dies before replying! */
tal_add_destructor2(p->uncommitted_channel->open_daemon,
opening_died_forget_memleak, cmd);
return;
}
opening_memleak_done(cmd, NULL);
}
void opening_dev_memleak(struct command *cmd)
{
opening_memleak_req_next(cmd, NULL);
}
#endif /* DEVELOPER */
struct subd *peer_get_owning_subd(struct peer *peer)
{
struct channel *channel;

6
lightningd/opening_control.h

@ -18,12 +18,6 @@ void peer_start_openingd(struct peer *peer,
struct per_peer_state *pps,
const u8 *msg);
#if DEVELOPER
struct command;
/* Calls report_leak_info() async. */
void opening_dev_memleak(struct command *cmd);
#endif
struct subd *peer_get_owning_subd(struct peer *peer);
#endif /* LIGHTNING_LIGHTNINGD_OPENING_CONTROL_H */

Loading…
Cancel
Save