[reliable payments] Move payment error deobfuscation to router #3063
This PR consists of two important pieces of #2761:
The text was updated successfully, but these errors were encountered:
The switch satisfies this interface, and makes it easy to mock the send method from the router.
This commit moves the responsibility of generating a unique payment ID from the switch to the router. This will make it easier for the router to keep track of which HTLCs were successfully forwarded onto the network, as it can query the switch for existing HTLCs as long as the paymentIDs are kept. The router is expected to maintain a map from paymentHash->paymentID, such that they can be replayed on restart. This also lets the router check the status of a sent payment after a restart, by querying the switch for the paymentID in question.
We will later persist the fields necessary to decrypt a received error.
With the following commits, it'll become important to not resuse paymentIDs, since there is no way to tell whether the HTLC in question has already been forwarded and settled/failed. We clarify this in the SendHTLC comments, and alter the tests to not attempt to resend an HTLC with a duplicate payment ID.
This lets us distinguish an critical error from a actual payment result (success or failure). This is important since we know that we can only attempt another payment when a final result from the previous payment attempt is received.
In this commit we move handing the deobfuscator from the router to the switch from when the payment is initiated, to when the result is queried. We do this because only the router can recreate the deobfuscator after a restart, and we are preparing for being able to handle results across restarts. Since the deobfuscator cannot be nil anymore, we can also get rid of that special case.