Don't drop `ChannelMonitor` `Event`s until they're processed 2023-06-mon-event-less-race
authorMatt Corallo <git@bluematt.me>
Tue, 20 Jun 2023 22:52:27 +0000 (22:52 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 10 Jul 2023 16:52:04 +0000 (16:52 +0000)
commit4206e7119bfef5eb13923f1bab185438e46fc446
tree7b08ae917da683905ffa62b79d9f9eda114532fc
parent0d1072b7c3fb5366742473c38069c421cdd60b87
Don't drop `ChannelMonitor` `Event`s until they're processed

We currently assume the owner of `ChannelMonitor`s won't persist
the `ChannelMonitor` while `Event`s are being processed. This is
fine, except (a) its generally hard to do so and (b) the
`ChainMonitor` doesn't even do this.

Thus, in rare cases, a user could begin processing events which
are, generated by connecting a transaction or a new best-block,
take some time to do so, and while doing so process a further chain
event, causing persistece. This could lose the event being
processed alltogether, which could lose the user funds.

This should be very rare, but may have been made slightly more
reachable with (a) the async event processing making it more
common to do networking in event handling, (b) the new future
generation in the `ChainMonitor`, which now wakes the
`background-processor` directly when chain actions happen on the
`ChainMonitor`.
lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs