-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swaps): new PreimageResolved swap phase
This creates a new phase for SwapDeals called `PreimageResolved` that represents the part after the maker has completed its payment to taker and resolved the preimage, but before it has settled its incoming payment using the preimage. Swaps that have reached this phase are considered atomic - our outgoing payment has been settle and we've acquired the ability to settle our incoming payment - even if they're not complete. Therefore, the maker ends the swap timeout and gives the call to settle the incoming payment as long as it needs to complete while keeping the hold on the order to prevent it from being filled a second time. Should a swap fail the `settleInvoice` call, it enters swap SwapRecovery where settling the payment will be attempted one more time but only after ensuring we are connected to the SwapClient responsible for that payment. Previously, deals that hit an error upon the `settleInvoice` would not fail the deal and send it to recovery until the timeout was reached. We persist the preimage to the database immediately upon reaching the `PreimageResolved` phase and then use that preimage in SwapRecovery if it is available, rather than querying the swap client for the outgoing payment to lookup the preimage again. We modify the timeout behavior for the maker in the swap. The maker will no longer "fail" a deal once it has begun sending its payment to the taker due to a swap timing out. Instead it will only notify the taker that its time limit has been reached, and a cooperative taker will cancel its invoice and call off the swap. The maker also tracks the elapsed time for a swap, and if its payment to taker succeeds after the time out period it penalizes the taker for accepting payment and settling its invoice too late. Takers that delay before they settle payment can abuse the free options problem. On the swap recovery side, we no longer fail a recovered deal if a settle invoice call fails. Instead, we continuosly attempt settle invoice calls until one succeeds. Longer term we can permanently stop settle invoice attempts if we can recognize the sorts of errors that indicate permanent failure such as htlc expiration or an unrecognized invoice hash. Resolves #1654. Resolves #1659.
- Loading branch information
Showing
12 changed files
with
469 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.