-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(connext): unlock expired transfer apps #1857
Conversation
|
lib/connextclient/ConnextClient.ts
Outdated
@@ -455,6 +457,20 @@ class ConnextClient extends SwapClient { | |||
preimage: transferStatusResponse.preImage?.slice(2), | |||
}; | |||
case 'EXPIRED': | |||
const expiredTransferUnlocked$ = defer(() => from(this.settleInvoice(rHash, '', currency))).pipe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused as to what this is doing (some comments might be good). Why are we "settling" a payment where we are the sender? I know that "invoice" is not exactly a connext term/concept, maybe we should just use the connext call/terminology directly here rather than settleInvoice
which is a generic SwapClient method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the connext transfer (HTLC) expires the funds are not automatically returned to the channel balance. Expired transfer apps can be unlocked by both the receiver and sender by calling /hashlock-resolve
with the paymentId
.
In this PR the settleInvoice
function has been modified to always include the paymentId
in the body of the request in case the transfer has been expired.
It's worth noting that the node also periodically cleans up the expired transfer apps, but from UX perspective it's better if this happens from xud side. This ensures that the funds locked in the transfer app are available to the user sooner.
I've added a short comment above the settleInvoice
call.
maybe we should just use the connext call/terminology directly here rather than settleInvoice which is a generic SwapClient method
Are you suggesting to create a wrapper function here that internally calls settleInvoice
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the explanation this makes sense. I think it would be great to put a brief summary of this in a line or two of comments right above this call.
I think calling settleInvoice
here with a blank preimage is still a bit odd, I would just go ahead and call /hashlock-resolve
directly like so:
await this.sendRequest('/hashlock-resolve', 'POST', {
assetId,
paymentId: sha256(['address', 'bytes32'], [assetId, `0x${rHash}`]),
});
And the settleInvoice call can be left as it currently is unless you think the payment id is useful to include even when we have the preimage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
And the settleInvoice call can be left as it currently is unless you think the payment id is useful to include even when we have the preimage?
Yep, removed payment id from settleInvoice.
36b67cc
to
be3a940
Compare
be3a940
to
ae09eb7
Compare
Integration test already exists in this PR.
Tests should now pass. |
EDIT: removed. Wrong issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you.
This PR adds logic to attempt to unlock expired connext transfer apps when receiving
EXPIRED
response from/hashlock-status
.Closes #1849