Avoid attempting to forward to a closed chan on stale-data reload
authorMatt Corallo <git@bluematt.me>
Thu, 17 Nov 2022 05:55:45 +0000 (05:55 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 5 Dec 2022 20:27:35 +0000 (20:27 +0000)
commit0bb87ddad71d2e33199ebad79e9f709f869f2130
treed348a248b6f5f579034a1c17c650d69e909f787e
parente142f67917c56bee74af1e0f33bbede2803e4b15
Avoid attempting to forward to a closed chan on stale-data reload

If, after forwarding a payment to our counterparty, we restart with
a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update was not persisted, we'll still
have the forwarded HTLC in the `forward_htlcs` map on start. This
will cause us to generate a (spurious) `PendingHTLCsForwardable`
event. However, when we go to forward said HTLC, we'll notice the
channel has been closed and leave it up to the `ChannelMontior` to
finalize the HTLC.

This is all fine today - we won't lose any funds, we'll just
generate an excess forwardable event and then fail to forward.
However, in the future when we allow for forward-time channel
changes this could break. Thus, its worth adding tests for this
behavior today, and, while we're at it, removing the spurious
forwardable HTLCs event.
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/reload_tests.rs