Block the mon update removing a preimage until upstream mon writes
authorMatt Corallo <git@bluematt.me>
Thu, 7 Sep 2023 02:22:52 +0000 (02:22 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 12 Sep 2023 19:03:17 +0000 (19:03 +0000)
commit5ff51b7805969bcd867572bc8102e0efb827765d
treeb7adca5879a4cbb851bec739d9833a52bd1c7a30
parente37a40080c565ae1fa0c3e8a058367191d35143b
Block the mon update removing a preimage until upstream mon writes

When we forward a payment and receive an `update_fulfill_htlc`
message from the downstream channel, we immediately claim the HTLC
on the upstream channel, before even doing a `commitment_signed`
dance on the downstream channel. This implies that our
`ChannelMonitorUpdate`s "go out" in the right order - first we
ensure we'll get our money by writing the preimage down, then we
write the update that resolves giving money on the downstream node.

This is safe as long as `ChannelMonitorUpdate`s complete in the
order in which they are generated, but of course looking forward we
want to support asynchronous updates, which may complete in any
order.

Thus, here, we enforce the correct ordering by blocking the
downstream `ChannelMonitorUpdate` until the upstream one completes.
Like the `PaymentSent` event handling we do so only for the
`revoke_and_ack` `ChannelMonitorUpdate`, ensuring the
preimage-containing upstream update has a full RTT to complete
before we actually manage to slow anything down.
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs