plugins/topology: use memleak annotation instead of global_gossmap hammer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-09-07 13:36:06 +09:30 committed by Christian Decker
parent a0d531d515
commit 127539a993
2 changed files with 30 additions and 3 deletions

View File

@ -684,6 +684,14 @@ done:
return command_finished(cmd, js);
}
#if DEVELOPER
static void memleak_mark(struct plugin *p, struct htable *memtable)
{
memleak_remove_region(memtable, global_gossmap,
tal_bytelen(global_gossmap));
}
#endif
static const char *init(struct plugin *p,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
@ -694,9 +702,9 @@ static const char *init(struct plugin *p,
take(json_out_obj(NULL, NULL, NULL)),
"{id:%}", JSON_SCAN(json_to_node_id, &local_id));
global_gossmap = notleak_with_children(gossmap_load(NULL,
GOSSIP_STORE_FILENAME,
&num_cupdates_rejected));
global_gossmap = gossmap_load(NULL,
GOSSIP_STORE_FILENAME,
&num_cupdates_rejected);
if (!global_gossmap)
plugin_err(plugin, "Could not load gossmap %s: %s",
GOSSIP_STORE_FILENAME, strerror(errno));
@ -705,6 +713,9 @@ static const char *init(struct plugin *p,
plugin_log(plugin, LOG_DBG,
"gossmap ignored %zu channel updates",
num_cupdates_rejected);
#if DEVELOPER
plugin_set_memleak_handler(p, memleak_mark);
#endif
return NULL;
}

View File

@ -1966,6 +1966,22 @@ def test_addgossip(node_factory):
l3.rpc.addgossip(badupdate)
def test_topology_leak(node_factory, bitcoind):
l1, l2, l3 = node_factory.line_graph(3)
l1.rpc.listchannels()
bitcoind.generate_block(5)
# Wait until l1 sees all the channels.
wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4)
# Close and wait for gossip to catchup.
txid = l2.rpc.close(l3.info['id'])['txid']
bitcoind.generate_block(1, txid)
wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 2)
def test_parms_listforwards(node_factory):
"""
Simple test to ensure that the order of the listforwards