Skip to content
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

work-in-progress! loopout: can set exact amount #313

Closed
wants to merge 1 commit into from

Conversation

ratpoison4
Copy link

@ratpoison4 ratpoison4 commented Oct 31, 2020

This was proposed here: #234 (comment)

I implemented logic of another Tx output here: sweep/sweeper.go
The logic of when to add which output is quite complex, so I added unit test for this (TestDeduceDestinations).
I am not familiar with the code, but I tried to pass everywhere new parameters. in OutRequest: DestAmount and ChangeAddr. In LoopOutQuoteRequest: WithChange. Careful review is required.

Also I don't know how to add an integration test and to test it in the wild (on testnet). Could you help me with this, please?

Pull Request Checklist

  • Update release_notes.md if your PR contains major features, breaking changes or bugfixes

@ratpoison4
Copy link
Author

Conflicts resolved and release_notes.md updated.

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave this a high-level review because the author asked me to. Thanks for your work!

I like the idea of specifying a destination amount and using a change address for the rest. I think this is easier to implement than trying to scale the swap amount in order to send a specific amount to an address without change.

I do think this needs quite some work, though. I feel like there are quite a few edge cases lingering that need to be handled, especially in high fee environments.
And the database persistence of the parameters is also missing.

cmd/loop/loopout.go Outdated Show resolved Hide resolved
// Calculate weight for this tx.
var weightEstimate input.TxWeightEstimator
switch destAddr.(type) {
return feeOnlyDest, feeOnlyChange, feeBoth, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of returning three different fees and checking them all in loopout.go, this method should already decide what destination(s) to use and only return the fee for that. Otherwise this code is quite hard to follow with passing the data back and forth.


return feeRate.FeeForWeight(int64(weight)), nil
return []destination{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if silently failing here is good UX. Especially if the command line flag doesn't mention the behavior. Perhaps we should instead make sure that the swap amount is sufficiently larger than the destination amount?
Perhaps swap_amt >= max_sweep_fee + dest_amt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

max_sweep_fee is actually known as max_miner_fee


// Where to send change in case DestAmount is specified. Optional.
// Used together with DestAmount.
ChangeAddr btcutil.Address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data also needs to be stored in the swap database. Otherwise if you restart before sweeping, it will be lost.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should deserializeLoopOutContract and serializeLoopOutContract be updated?

They use some custom binary format. I guess the change of the format should be backward-compatible, so that strings produced by old serializeLoopOutContract are successfully decoded by new deserializeLoopOutContract. I'll add two new fields in the end and in deserializeLoopOutContract if I get EOF trying to read the first field, I'll consider that ok, because it is an old format.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I get EOF trying to read the first field, I'll consider that ok, because it is an old format.

I see migration files. I think, I should add a migration.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ratpoison4
Copy link
Author

Found and fixed another issue: in loopOut when making QuoteRequest we should pass WithChange depending on dest_amount.

@guggero
Copy link
Member

guggero commented Nov 30, 2020

Concept ACK!

As explained on Slack, I think we do want this feature but are going to hold off on further review until the "work in progress" state is removed to hopefully reduce the number of review iterations needed.
Please take the following steps to continue:

  • Split code into logical, incremental commit structure for easy review. each commit should have a rationale in the commit message and compile on its own
  • Even though this isn't stated explicitly in the Loop docs, we do want contributors to stick to lnd's contribution guidelines, especially when it comes to code style and formatting: https://github.com/lightningnetwork/lnd/blob/master/docs/code_contribution_guidelines.md
  • Run the code on testnet to make sure it works end to end, comment the results on the PR
  • Once all that is done, I think the "work in progress" can be removed from the title which also increases chances of getting more review

Thank you for your time and effort.

@lightninglabs-deploy
Copy link

@ratpoison4, remember to re-request review from reviewers for your latest update

1 similar comment
@lightninglabs-deploy
Copy link

@ratpoison4, remember to re-request review from reviewers for your latest update

@guggero
Copy link
Member

guggero commented Dec 12, 2021

Closing due to inactivity.

@guggero guggero closed this Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants