Reorder the BP loop to make manager persistence more reliable 2022-04-event-process-try-lock
authorMatt Corallo <git@bluematt.me>
Thu, 21 Apr 2022 02:30:16 +0000 (02:30 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 26 Apr 2022 15:29:16 +0000 (15:29 +0000)
commit050b19cd9bceb9e3620f9233279f848b1f264475
treebe16fc7c35b4fea1c7518aaa681b27291a2ec54a
parentd0f69f77bd6ed40bff7ef1026f23e4444a5a884a
Reorder the BP loop to make manager persistence more reliable

The main loop of the background processor has this line:
`peer_manager.process_events(); // Note that this may block on ChannelManager's locking`
which does, indeed, sometimes block waiting on the `ChannelManager`
to finish whatever its doing. Specifically, its the only place in
the background processor loop that we block waiting on the
`ChannelManager`, so if the `ChannelManager` is relatively busy, we
may end up being blocked there most of the time.

This should be fine, except today we had a user who's node was
particularly slow in processing some channel updates, resulting in
the background processor being blocked there (as expected). Then,
when the channel updates were completed (and persisted) the next
thing the background processor did was hand the user events to
process, creating yet more channel updates. Ultimately, the users'
node crashed before finishing the event processing. This left us
with an updated monitor on disk and an outdated manager, and they
lost the channel on startup.

Here we simply move the above quoted line to after the normal event
processing, ensuring the next thing we do after blocking on
`ChannelManager` locks is persist the manager, prior to event
handling.
lightning-background-processor/src/lib.rs