Always release `MonitorEvent`s to `ChannelManager` after 3 blocks
authorMatt Corallo <git@bluematt.me>
Thu, 14 Oct 2021 23:38:08 +0000 (23:38 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 20 Oct 2021 00:06:18 +0000 (00:06 +0000)
commite6bc2b541e8bccab7d72c8fa6828c5675a1a7431
treef8382eea98977ff7eda01dba6e515a54794e68a8
parent3016ed2d9146bfff116f035404b333ba950a1195
Always release `MonitorEvent`s to `ChannelManager` after 3 blocks

If we have a `ChannelMonitor` update from an on-chain event which
returns a `TemporaryFailure`, we block `MonitorEvent`s from that
`ChannelMonitor` until the update is persisted. This prevents
duplicate payment send events to the user after payments get
reloaded from monitors on restart.

However, if the event being avoided isn't going to generate a
PaymentSent, but instead result in us claiming an HTLC from an
upstream channel (ie the HTLC was forwarded), then the result of a
user delaying the event is that we delay getting our money, not a
duplicate event.

Because user persistence may take an arbitrary amount of time, we
need to bound the amount of time we can possibly wait to return
events, which we do here by bounding it to 3 blocks.

Thanks to Val for catching this in review.
lightning/src/chain/chainmonitor.rs