Sweeper: support Inputs with required locktimes and txOuts#4750
Sweeper: support Inputs with required locktimes and txOuts#4750halseth merged 10 commits intolightningnetwork:masterfrom
Conversation
Roasbeef
left a comment
There was a problem hiding this comment.
First pass, solid diff. Still need to fully grok the process of zipping/merging the valid input sets. Also I don't see any changes to the resolver to send these outputs directly to the sweeper, I take it that'll come in another PR?
1eaae13 to
b1ab6c2
Compare
Tried to keep it simple. Should perhaps make it even simpler/dumber for this first iteration? (it is not really where review time should be spent I feel).
Yep, will come in a follow up soon (tm) |
Roasbeef
left a comment
There was a problem hiding this comment.
Updated my mental model of the current state of the sweeper by re-reading this package thoroughly since it's shifted a good bit since I had a major review in this area. Didn't generate any additional major comments on my end, though the existing more minor comments still stand. If we're to get what we need in to activate anchors by default in a timely manner, then we'll need to ensure we have quick review cycles on this as well as the planned follow up PRs.
LGTM 🥗
sweep/tx_input_set.go
Outdated
There was a problem hiding this comment.
As mentioned above this shouldn't happen since the 2 of 2's must be above the dust limit in order to be considered, but good defensive clause to have nevertheless.
sweep/txgenerator.go
Outdated
There was a problem hiding this comment.
Same logic is duplicated above from lines 169-175, non-blocking comment.
d971f1a to
151b2db
Compare
sweep/sweeper.go
Outdated
| // If the fee rate is less than a's, we break. All the | ||
| // remining clusters from bs have lower fee rate. | ||
| if b.sweepFeeRate < a.sweepFeeRate { | ||
| break |
There was a problem hiding this comment.
Not sure if I'm missing something, but don't we need to include the remaining input clusters from as before the break? Otherwise they won't be returned as part of finalClusters.
There was a problem hiding this comment.
Confirmed with this diff:
diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go
index 0104903cc..f6123837e 100644
--- a/sweep/sweeper_test.go
+++ b/sweep/sweeper_test.go
@@ -1513,10 +1513,10 @@ func TestZipClusters(t *testing.T) {
createCluster(testInputsA, 5000),
},
bs: []inputCluster{
- createCluster(testInputsB, 7000),
+ createCluster(testInputsB, 3000),
},
res: []inputCluster{
- createCluster(testInputsC, 7000),
+ createCluster(testInputsC, 5000),
},
},
{
@@ -1558,8 +1558,9 @@ func TestZipClusters(t *testing.T) {
for _, test := range testCases {
zipped := zipClusters(test.as, test.bs)
if !reflect.DeepEqual(zipped, test.res) {
- t.Fatalf("[%s] unexpected result: %v",
- test.name, spew.Sdump(zipped))
+ t.Fatalf("[%s] unexpected result: got %v, want %v",
+ test.name, spew.Sdump(zipped),
+ spew.Sdump(test.res))
}
}
}Tests fail as only bs is added and items from as are omitted all together. The diff just makes the fee rate of bs lower than all of as so the break gets hit immediately.
An even simpler scenario to consider if when bs is empty (we cluster by lock time and all the inputs have a lock time). With this logic, they'll all be dropped.
There was a problem hiding this comment.
Another way of stating is that at each step for as, it either should be:
- merged in with
bs - or added to the final cluster (non-merged)
The break here means that the last statement can be skipped all together at times.
151b2db to
0a4036a
Compare
This is needed to sweep second level HTLC transactions that are signed using SINGLE|ANYONECANPAY, since the input and ouput must be aligned.
If inputs require outputs to be added at the same time, this will change the weight and amount calculations, so we must account for that. We wait to get the weight estimator for the sweep tx until needed, such that we can easily choose whether to include a change output or not in the estimate. This is needed for the case where the second level transactions can pay for their own fee, so no change output is needed.
We also increase the value of the wallet UTXO, as it is needed when we want to afford fees for larger transactions.
Now that inputs might have accompanied outputs to be added to the sweep tx, we add them to the sweep transaction first, and account for it when calculating the change amount.
0a4036a to
beaf8f6
Compare
Add tests that inputs with required TXOuts gets aggregated and swept, while keeping locktimes satisfied.
beaf8f6 to
8d2e6de
Compare
This PR adds support for inputs that put extra restrictions on the sweep tx, namely a locktime and accompanied output.
Two methods are added to the
Inputinterface that for most normal inputs will do nothing:For certain inputs though, this is needed. Most notably we plan to use this for sweeping and aggregation of second level HTLC transactions for anchor channels. Since these transactions are pre-signed by the channel counterparty using sighash
SINGLE|ANYONECANPAY, they can be altered at will as long as the locktime and input-ouput pair stays intact.By allowing the sweeper to add such input-output pairs to the sweep transaction, we get BYOF (bring-your-own-fees) and HTLC aggregation for free.