lightningd: don't crash if replaying blocks for onchaind during shutdown.

```
lightningd-1 2024-11-15T04:06:47.660Z UNUSUAL lightningd: JSON-RPC shutdown
lightningd-1 2024-11-15T04:06:47.665Z DEBUG   lightningd: io_break: start_json_stream
lightningd-1 2024-11-15T04:06:47.666Z DEBUG   lightningd: io_loop_with_timers: main
lightningd-1 2024-11-15T04:06:47.672Z DEBUG   connectd: REPLY WIRE_CONNECTD_START_SHUTDOWN_REPLY with 0 fds
lightningd-1 2024-11-15T04:06:47.674Z DEBUG   lightningd: io_break: connectd_start_shutdown_reply
lightningd-1 2024-11-15T04:06:47.680Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-onchaind-chan#1: Status closed, but not exited. Killing
lightningd-1 2024-11-15T04:06:47.715Z **BROKEN** lightningd: FATAL SIGNAL 11 (version e627dbf-modded)
------------------------------- Valgrind errors --------------------------------
Valgrind error file: valgrind-errors.43310
==43310== Invalid read of size 8
==43310==    at 0x1B5717: subd_send_msg (subd.c:842)
==43310==    by 0x17563A: onchain_tx_depth (onchain_control.c:177)
==43310==    by 0x175E92: replay_block (onchain_control.c:391)
==43310==    by 0x12E30C: getrawblockbyheight_callback (bitcoind.c:506)
==43310==    by 0x1A5AC0: plugin_response_handle (plugin.c:663)
==43310==    by 0x1A5D3C: plugin_read_json_one (plugin.c:775)
==43310==    by 0x1A5F79: plugin_read_json (plugin.c:826)
==43310==    by 0x38F320: next_plan (io.c:60)
==43310==    by 0x38FF76: do_plan (io.c:422)
==43310==    by 0x38FFDD: io_ready (io.c:439)
==43310==    by 0x392411: io_loop (poll.c:455)
==43310==    by 0x1AB630: shutdown_plugins (plugin.c:2588)
==43310==  Address 0x58 is not stack'd, malloc'd or (recently) free'd
==43310== 
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-11-15 16:33:39 +10:30
parent 102e22347d
commit cac20129c6

View File

@ -383,6 +383,10 @@ static void replay_block(struct bitcoind *bitcoind,
struct replay_tx *rtx;
struct replay_tx_hash_iter rit;
/* If we're shutting down, this can happen! */
if (!channel->owner)
return;
/* Tell onchaind that all existing txs have reached a new depth */
for (rtx = replay_tx_hash_first(channel->onchaind_replay_watches, &rit);
rtx;