Loop In#34
Conversation
This commit adds the required code to persist loop in swaps. It also introduces the file loop.go to which shared code is moved. Sharing of contract serialization/deserialization code has been reverted. The prepay fields do not apply to loop in, but were part of the shared contract struct. Without also adding a migration, it wouldn't be possible to keep the shared code. In general it is probably more flexible to keep the contract serialization code separated between in and out swaps.
Allow user to specify that htlc will be published by an external source. In that case no internal htlc tx will be published. To facilitate sending to the htlc address, the swap initiation response is extended with that address.
Roasbeef
left a comment
There was a problem hiding this comment.
Excited to eventually roll this out on mainnet! Comments from the prior earlier review look to be addressed. After running a few more Loops I noticed two things:
- Loop In quotes still show "loop out"
- We mark the Loop In as complete after the HTLC is swept, rather than as soon as the invoice has been settled
| // TODO: Add miner fee of timeout tx to swap cost balance. | ||
| } | ||
|
|
||
| // Wait for a final state of the swap invoice. It should either be |
There was a problem hiding this comment.
I think we should move this to be above waiting for the HTLC spend, or be concurrent even. I tried another Loop in on testnet now and realized that things are shown as pending until the HTLC is swept on chain. However, from the PoV of the client, the Loop In process is complete once its invoice is settled, as it now has more outbound capacity.
There was a problem hiding this comment.
Everywhere in loop swaps are only marked complete when all information needed for accounting is there. For loop in on the client, this means the htlc sweep tx needs to be confirmed and the swap invoice either canceled or settled. Also after a restart, a swap that is completed from the user PoV, still needs to be resumed to complete the accounting info.
An intermediate state that the swap transitions to when the invoice is paid could be a solution here.
There was a problem hiding this comment.
Added a commit that adds this intermediate state.
|
The README should also be updated to instruct users to build with the |
b2e7bf4 to
db39b37
Compare
a25b081 to
907a118
Compare
|
@Roasbeef ptal |
|
Panic on |
|
Nvm, it was due to me having issued a swap using the old DB format. |
| return s.sendUpdate(ctx) | ||
| } | ||
|
|
||
| // setState updates the swap state and last update timestamp. |
There was a problem hiding this comment.
I think we should also roll in persistState into this method as well. Otherwise, I see a few instances above, where we modify the swap state, but don't persist it to the database.
There was a problem hiding this comment.
Scratch that, I see it's persisted for the first thing that causes it to break out of the loop.
| return nil | ||
| } | ||
|
|
||
| func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error { |
There was a problem hiding this comment.
I think we should instead make this an command for the loop binary, but it isn't blocking and can be done in a follow up.
This PR adds loop in functionality to the Lightning Loop client.
Loop in allows a lightning channel to be 'refilled' with on-chain coins. It allows a channel to remain open and offers an alternative over closing and reopening the channel.
High level flow
Usage
Similar to Loop Out. A new command has been added to the
loopcommand line tool:loop in <amt>Also the
--externalflag can be supplied. In that case step 2 of the flow above is skipped and the user is given the opportunity to publish the htlc manually. An example use of this is to withdraw from an exchange into a lightning channel by looping in.There is also the
--channelflag that allows selection of the channel to loop in to. This functionality is not implemented yet.Testnet only
Loop in is currently only supported on testnet. There are still several changes required to
lndfor it to be used on mainnet.