]> git.bitcoin.ninja Git - rust-lightning/commit
Stop using a constant for monitor `update_id`s after closure
authorMatt Corallo <git@bluematt.me>
Sun, 6 Oct 2024 19:58:29 +0000 (19:58 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 10 Oct 2024 20:52:30 +0000 (20:52 +0000)
commit94a50a07e0d8f8d8c359a1e1ae9ca61c14861629
tree27f3bbdadace03b223233b917a5b7680951983ac
parent78221ccc832bfdf19bf68b8e72a5e21ef73024f0
Stop using a constant for monitor `update_id`s after closure

Because `ChannelManager` doesn't have a corresponding `Channel`
after the channels are closed, we'd always used an `update_id` of
`u64::MAX` for any `ChannelMonitorUpdate`s we need to build after
the channel is closed.

This completely breaks the abstraction of `update_id`s and leaks
into persistence logic - because we might have more than one
`ChannelMonitorUpdate` with the same (`u64::MAX`) value, suddenly
instead of being able to safely use `update_id` as IDs, the
`MonitorUpdatingPersister` has to have special logic to handle
this.

Worse, because we don't have a unique ID with which to refer to
post-close `ChannelMonitorUpdate`s we cannot track when they
complete async persistence. This means we cannot properly support
async persist for forwarded payments where the inbound edge has hit
the chain prior to the preimage coming to us.

Here we rectify this by using consistent `update_id`s even after a
channel has closed. In order to do so we have to keep some state
for all channels for which the `ChannelMonitor` has not been
archived (after which point we can be confident we will not need to
update them). While this violates our long-standing policy of
having no state at all in `ChannelManager`s for closed channels,
its only a `(ChannelId, u64)` pair per channel, so shouldn't be
problematic for any of our users (as they already store a whole
honkin `ChannelMonitor` for these channels anyway).

While limited changes are made to the connection-count-limiting
logic, reviewers should carefully analyze the interactions the new
map created here has with that logic.
lightning-persister/src/test_utils.rs
lightning/src/chain/channelmonitor.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/reload_tests.rs
lightning/src/util/persist.rs