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

sweep: add wallet inputs to reach dust limit #3814

Merged
merged 9 commits into from
Dec 18, 2019

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Dec 10, 2019

This PR enables the sweeper to sweep inputs that are positively-yielding, but by itself wouldn't reach the dust limit for the sweep transaction output value at the chosen fee rate.

They way to deal with this is to attach additional wallet input(s) to bring up the output value of the transaction.

This is a preparation for sweeping anchor outputs that are too small to reach the dust limit of the sweep tx output.

There are also a few commits in this PR that aren't strictly necessary for the functionality that this PR adds, but are included anyway to prevent touching the code again in the follow-up.

Next step after this PR is to add forced sweeping of negatively yielding inputs.

@joostjager joostjager changed the title sweep: add wallet inputs to reach dust limit sweep: add wallet inputs to reach dust limit [do not review] Dec 10, 2019
We need it to be set in order to properly test the sweeper handling the
dust limit on regtest.
@joostjager joostjager force-pushed the sweeper-add-utxo branch 3 times, most recently from bd3d6c8 to 215c322 Compare December 12, 2019 13:17
@joostjager joostjager force-pushed the sweeper-add-utxo branch 2 times, most recently from 26a6329 to 3dea473 Compare December 13, 2019 09:58
Using a fee rate just as an identifier can be confusing.
Fixes a bug where bucket sizes were not the configured size, but the
configured size plus the min relay fee.
Prepares for adding more input-specific sweep parameters.
Get rid of needless referencing of the embedded object.
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Good PR! Excellent commit structure, and a nice cleanup :)

sweep/sweeper.go Show resolved Hide resolved
sweep/tx_input_set.go Show resolved Hide resolved
sweep/sweeper.go Show resolved Hide resolved
sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/txgenerator.go Outdated Show resolved Hide resolved
sweep/txgenerator.go Outdated Show resolved Hide resolved
sweep/txgenerator.go Outdated Show resolved Hide resolved
sweep/txgenerator.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/txgenerator.go Outdated Show resolved Hide resolved
@joostjager joostjager force-pushed the sweeper-add-utxo branch 3 times, most recently from d98a1d1 to fb6377d Compare December 13, 2019 13:02
@joostjager
Copy link
Contributor Author

Unit test added

@joostjager joostjager added this to the 0.9.0 milestone Dec 13, 2019
@joostjager joostjager added v0.9.0 chain handling channel closing Related to the closing of channels cooperatively and uncooperatively utxo sweeping labels Dec 13, 2019
@joostjager joostjager changed the title sweep: add wallet inputs to reach dust limit [do not review] sweep: add wallet inputs to reach dust limit Dec 13, 2019
sweep/sweeper.go Show resolved Hide resolved
sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Show resolved Hide resolved
sweep/sweeper.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Show resolved Hide resolved
t.inputTotal = newInputTotal
t.outputValue = newOutputValue
t.inputs = append(t.inputs, input)
t.weightEstimate = newWeightEstimate
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like all these counters could be calculated on demand instead (just pointing it out, still up for discussion whether that is better than just keeping running counters).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a later commit, i would also need the fromWallet state. I am not too convinced of it. When you add 20 inputs, 200 (virtual) add operations will be executed. (1+2+3+...+20).

@wpaulino what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a new input would make us recalculate everything, but the performance impact is likely negligible unless there are lots of inputs. I'm fine with leaving things as is given that the code is already there.

sweep/txgenerator.go Outdated Show resolved Hide resolved
sweep/sweeper.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Show resolved Hide resolved

// Retrieve wallet utxos. Only consider confirmed utxos to prevent
// problems around RBF rules for unconfirmed inputs.
utxos, err := t.wallet.ListUnspentWitness(1, math.MaxInt32)
Copy link
Contributor

Choose a reason for hiding this comment

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

to avoid having the wallet as a field on the input set, the list of utxos can be passed into this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but then we'd always get utxos, even if the dust limit is already reached. could also move that out then. but not sure if it is better

sweep/interface.go Outdated Show resolved Hide resolved
t.inputTotal = newInputTotal
t.outputValue = newOutputValue
t.inputs = append(t.inputs, input)
t.weightEstimate = newWeightEstimate
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a new input would make us recalculate everything, but the performance impact is likely negligible unless there are lots of inputs. I'm fine with leaving things as is given that the code is already there.

sweep/tx_input_set.go Outdated Show resolved Hide resolved
sweep/tx_input_set.go Show resolved Hide resolved
sweep/sweeper.go Show resolved Hide resolved
sweep/tx_input_set_test.go Outdated Show resolved Hide resolved
A refactoring that introduces no functional changes. This prepares for
the addition of wallet utxos to push the sweep tx above the dust limit.

It also enabled access to input-specific sweep parameters during tx
generation. This will be used in later commits to control the sweep
process.
We need access to additional wallet functionality. This commit creates
an interface to prevent passing in multiple function pointers.
Prepares for adding another level of nesting.
This commit allows sweeper to sweep inputs that on its own are not able
to form a sweep transaction that meets the dust limit.

This functionality is useful for sweeping small outputs. In the future,
this will be particularly important to sweep anchors. Anchors will
typically be spent with a relatively large fee to pay for the parent tx.
It will then be necessary to attach an additional wallet utxo.
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@joostjager joostjager merged commit 7ecbe22 into lightningnetwork:master Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anchors chain handling channel closing Related to the closing of channels cooperatively and uncooperatively utxo sweeping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants