From d7b5882f613190bc86072699c52ef5bfad045f49 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 2 Mar 2018 19:29:17 +1030 Subject: [PATCH] routing: don't free a single nc on prune, only entire channel. Signed-off-by: Rusty Russell --- gossipd/routing.c | 26 ++++++++------------------ tests/test_lightningd.py | 11 ++--------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index d2aaec609..a7e0d9142 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1328,30 +1328,20 @@ void route_prune(struct routing_state *rstate) if (!chan->public) continue; - for (int i = 0; i < 2; i++) { - struct node_connection *nc = chan->connections[i]; - - if (!nc) - continue; - - if (nc->last_timestamp > highwater) { - /* Still alive */ - continue; - } - + if (chan->connections[0]->last_timestamp < highwater + && chan->connections[1]->last_timestamp < highwater) { status_trace( - "Pruning channel %s/%d from network view (age %"PRIu64"s)", + "Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)", type_to_string(trc, struct short_channel_id, &chan->scid), - nc->flags & 0x1, - now - nc->last_timestamp); + now - chan->connections[0]->last_timestamp, + now - chan->connections[1]->last_timestamp); - /* This may free nodes, so do outside loop. */ - tal_steal(pruned, nc); + /* This may perturb iteration so do outside loop. */ + tal_steal(pruned, chan); } } - /* This frees all the node_connections: may free routing_channel and - * even nodes. */ + /* This frees all the routing_channels and maybe even nodes. */ tal_free(pruned); } diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 134bde8ba..5c63ed0de 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -1898,15 +1898,8 @@ class LightningDTests(BaseLightningDTests): time.sleep(1) l3.stop() - l1.daemon.wait_for_logs([ - "Pruning channel {}/{} from network view".format(scid2, 0), - "Pruning channel {}/{} from network view".format(scid2, 1), - ]) - - l2.daemon.wait_for_logs([ - "Pruning channel {}/{} from network view".format(scid2, 0), - "Pruning channel {}/{} from network view".format(scid2, 1), - ]) + l1.daemon.wait_for_log("Pruning channel {} from network view".format(scid2)) + l2.daemon.wait_for_log("Pruning channel {} from network view".format(scid2)) assert scid2 not in [c['short_channel_id'] for c in l1.rpc.listchannels()['channels']] assert scid2 not in [c['short_channel_id'] for c in l2.rpc.listchannels()['channels']]