Drop forwarded HTLCs which were still pending at persist-time 2022-12-jit-reload-consistency
authorMatt Corallo <git@bluematt.me>
Tue, 13 Dec 2022 03:27:23 +0000 (03:27 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 13 Dec 2022 19:33:58 +0000 (19:33 +0000)
commit2d6818376c581062d9951134ac5c7f312ec9d105
treef46785b7e8b3e1a21bd10aaff10e0c72012061db
parent769f590d51d08bafbc82d85e9a59bc04fd9adbbb
Drop forwarded HTLCs which were still pending at persist-time

If, after forwarding an intercepted payment to our counterparty, we
restart with a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update not having been persisted,
we'll still have the intercepted HTLC in the
`pending_intercepted_htlcs` map on start (and potentially a pending
`HTLCIntercepted` event). This will cause us to allow the user to
handle the forwarded HTLC twice, potentially double-forwarding it.

This builds on 0bb87ddad71d2e33199ebad79e9f709f869f2130, which
provided a preemptive fix for the general relay case (though it was
not an actual issue at the time). We simply check for the HTLCs
having been forwarded on startup and remove them from the map.

Fixes #1858
lightning/src/ln/channelmanager.rs
lightning/src/ln/reload_tests.rs