Make payments not duplicatively fail/succeed on reload/reconnect
authorMatt Corallo <git@bluematt.me>
Sun, 9 May 2021 19:19:11 +0000 (19:19 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 20 May 2021 16:30:27 +0000 (16:30 +0000)
commit3aa4aa8880642e87cb6e38194b000e6dfab74faa
treebd383384e9e806e40cf627f3eccdb0bc4c50c2dd
parent5d74cae6c5665a0bd917b24b4fcaf181ff6b5450
Make payments not duplicatively fail/succeed on reload/reconnect

We currently generate duplicative PaymentFailed/PaymentSent events
in two cases:

a) If we receive a update_fulfill_htlc message, followed by a
   disconnect, then a resend of the same update_fulfill_htlc
   message, we will generate a PaymentSent event for each message.

b) When a Channel is closed, any outbound HTLCs which were relayed
   through it are simply dropped when the Channel is. From there,
   the ChannelManager relies on the ChannelMonitor having a copy of
   the relevant fail-/claim-back data and processes the HTLC
   fail/claim when the ChannelMonitor tells it to.

   If, due to an on-chain event, an HTLC is failed/claimed, and
   then we serialize the ChannelManager, but do not re-serialize
   the relevant ChannelMonitor, we may end up getting a duplicative
   event.

In order to provide the expected consistency, we add explicit
tracking of pending outbound payments using their unique
session_priv field which is generated when the payment is sent.
Then, before generating PaymentFailed/PaymentSent events, we check
that the session_priv for the payment is still pending.

Thix fixes #209.
lightning/src/ln/channelmanager.rs
lightning/src/util/events.rs