Skip to content

Commit

Permalink
chaintopology: free outstanding requests so we don't get responses wh…
Browse files Browse the repository at this point in the history
…ile shutting down.

I've never seen this, but the race looks possible so we should close it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed May 26, 2024
1 parent 740b9e4 commit 42b5f99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions lightningd/chaintopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 42b5f99

Please sign in to comment.