From b5b834a37b003b56a1b1028568638d3b859dfd98 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 28 May 2024 09:06:24 +0930 Subject: [PATCH] chaintopology: free outstanding requests so we don't get responses while shutting down. I've never seen this, but the race looks possible so we should close it. Signed-off-by: Rusty Russell --- lightningd/chaintopology.c | 10 +++++++--- lightningd/chaintopology.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 1947be25ea3e..4140c0008ed4 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -565,7 +565,7 @@ static void start_fee_estimate(struct chain_topology *topo) { topo->updatefee_timer = NULL; /* Based on timer, update fee estimates. */ - bitcoind_estimate_fees(topo, topo->bitcoind, update_feerates_repeat, NULL); + bitcoind_estimate_fees(topo->request_ctx, topo->bitcoind, update_feerates_repeat, NULL); } struct rate_conversion { @@ -1076,7 +1076,7 @@ static void try_extend_tip(struct chain_topology *topo) { topo->extend_timer = NULL; trace_span_start("extend_tip", topo); - bitcoind_getrawblockbyheight(topo, topo->bitcoind, topo->tip->height + 1, + bitcoind_getrawblockbyheight(topo->request_ctx, topo->bitcoind, topo->tip->height + 1, get_new_block, topo); } @@ -1218,6 +1218,7 @@ struct chain_topology *new_topology(struct lightningd *ld, struct logger *log) topo->extend_timer = NULL; topo->rebroadcast_timer = NULL; topo->checkchain_timer = NULL; + topo->request_ctx = tal(topo, char); list_head_init(topo->sync_waiters); return topo; @@ -1276,7 +1277,7 @@ static void retry_sync_getchaininfo_done(struct bitcoind *bitcoind, const char * static void retry_sync(struct chain_topology *topo) { topo->checkchain_timer = NULL; - bitcoind_getchaininfo(topo, topo->bitcoind, get_block_height(topo), + bitcoind_getchaininfo(topo->request_ctx, topo->bitcoind, get_block_height(topo), retry_sync_getchaininfo_done, topo); } @@ -1499,4 +1500,7 @@ void stop_topology(struct chain_topology *topo) tal_free(topo->checkchain_timer); tal_free(topo->extend_timer); tal_free(topo->updatefee_timer); + + /* Don't handle responses to any existing requests. */ + tal_free(topo->request_ctx); } diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index c1fa70adceab..948876e1ff08 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -130,6 +130,9 @@ struct chain_topology { /* Timers we're running. */ struct oneshot *checkchain_timer, *extend_timer, *updatefee_timer, *rebroadcast_timer; + /* Parent context for requests (to bcli plugin) we have outstanding. */ + tal_t *request_ctx; + /* Bitcoin transactions we're broadcasting */ struct outgoing_tx_map *outgoing_txs;