@@ -59,7 +59,7 @@ func (b *Batcher) greedyAddSweep(ctx context.Context, sweep *sweep) error {
59
59
// Run the algorithm. Get batchId of possible batches, sorted from best
60
60
// to worst.
61
61
batchesIds , err := selectBatches (
62
- batches , sweepFeeDetails , newBatchFeeDetails , b . mixedBatch ,
62
+ batches , sweepFeeDetails , newBatchFeeDetails ,
63
63
)
64
64
if err != nil {
65
65
return fmt .Errorf ("batch selection algorithm failed for sweep " +
@@ -133,13 +133,10 @@ func estimateSweepFeeIncrement(s *sweep) (feeDetails, feeDetails, error) {
133
133
// Create feeDetails for sweep.
134
134
sweepFeeDetails := feeDetails {
135
135
FeeRate : s .minFeeRate ,
136
- NonCoopHint : s .nonCoopHint || s .coopFailed ,
137
136
IsExternalAddr : s .isExternalAddr ,
138
137
139
138
// Calculate sweep weight as a difference.
140
- MixedWeight : fd2 .MixedWeight - fd1 .MixedWeight ,
141
- CoopWeight : fd2 .CoopWeight - fd1 .CoopWeight ,
142
- NonCoopWeight : fd2 .NonCoopWeight - fd1 .NonCoopWeight ,
139
+ Weight : fd2 .Weight - fd1 .Weight ,
143
140
}
144
141
145
142
return sweepFeeDetails , fd1 , nil
@@ -158,14 +155,6 @@ func estimateBatchWeight(batch *batch) (feeDetails, error) {
158
155
batch .rbfCache .FeeRate )
159
156
}
160
157
161
- // Find if the batch has at least one non-cooperative sweep.
162
- hasNonCoop := false
163
- for _ , sweep := range batch .sweeps {
164
- if sweep .nonCoopHint || sweep .coopFailed {
165
- hasNonCoop = true
166
- }
167
- }
168
-
169
158
// Find some sweep of the batch. It is used if there is just one sweep.
170
159
var theSweep sweep
171
160
for _ , sweep := range batch .sweeps {
@@ -186,21 +175,11 @@ func estimateBatchWeight(batch *batch) (feeDetails, error) {
186
175
destAddr = (* btcutil .AddressTaproot )(nil )
187
176
}
188
177
189
- // Make three estimators: for mixed, coop and non-coop cases .
190
- var mixedWeight , coopWeight , nonCoopWeight input.TxWeightEstimator
178
+ // Make a weight estimator .
179
+ var weight input.TxWeightEstimator
191
180
192
181
// Add output weight to the estimator.
193
- err := sweeppkg .AddOutputEstimate (& mixedWeight , destAddr )
194
- if err != nil {
195
- return feeDetails {}, fmt .Errorf ("sweep.AddOutputEstimate: %w" ,
196
- err )
197
- }
198
- err = sweeppkg .AddOutputEstimate (& coopWeight , destAddr )
199
- if err != nil {
200
- return feeDetails {}, fmt .Errorf ("sweep.AddOutputEstimate: %w" ,
201
- err )
202
- }
203
- err = sweeppkg .AddOutputEstimate (& nonCoopWeight , destAddr )
182
+ err := sweeppkg .AddOutputEstimate (& weight , destAddr )
204
183
if err != nil {
205
184
return feeDetails {}, fmt .Errorf ("sweep.AddOutputEstimate: %w" ,
206
185
err )
@@ -209,34 +188,23 @@ func estimateBatchWeight(batch *batch) (feeDetails, error) {
209
188
// Add inputs.
210
189
for _ , sweep := range batch .sweeps {
211
190
if sweep .nonCoopHint || sweep .coopFailed {
212
- err = sweep .htlcSuccessEstimator (& mixedWeight )
191
+ err = sweep .htlcSuccessEstimator (& weight )
213
192
if err != nil {
214
193
return feeDetails {}, fmt .Errorf (
215
194
"htlcSuccessEstimator failed: %w" , err ,
216
195
)
217
196
}
218
197
} else {
219
- mixedWeight .AddTaprootKeySpendInput (
198
+ weight .AddTaprootKeySpendInput (
220
199
txscript .SigHashDefault ,
221
200
)
222
201
}
223
-
224
- coopWeight .AddTaprootKeySpendInput (txscript .SigHashDefault )
225
-
226
- err = sweep .htlcSuccessEstimator (& nonCoopWeight )
227
- if err != nil {
228
- return feeDetails {}, fmt .Errorf ("htlcSuccessEstimator " +
229
- "failed: %w" , err )
230
- }
231
202
}
232
203
233
204
return feeDetails {
234
205
BatchId : batch .id ,
235
206
FeeRate : batch .rbfCache .FeeRate ,
236
- MixedWeight : mixedWeight .Weight (),
237
- CoopWeight : coopWeight .Weight (),
238
- NonCoopWeight : nonCoopWeight .Weight (),
239
- NonCoopHint : hasNonCoop ,
207
+ Weight : weight .Weight (),
240
208
IsExternalAddr : theSweep .isExternalAddr ,
241
209
}, nil
242
210
}
@@ -250,26 +218,13 @@ const newBatchSignal = -1
250
218
type feeDetails struct {
251
219
BatchId int32
252
220
FeeRate chainfee.SatPerKWeight
253
- MixedWeight lntypes.WeightUnit
254
- CoopWeight lntypes.WeightUnit
255
- NonCoopWeight lntypes.WeightUnit
256
- NonCoopHint bool
221
+ Weight lntypes.WeightUnit
257
222
IsExternalAddr bool
258
223
}
259
224
260
225
// fee returns fee of onchain transaction representing this instance.
261
- func (e feeDetails ) fee (mixedBatch bool ) btcutil.Amount {
262
- var weight lntypes.WeightUnit
263
- switch {
264
- case mixedBatch :
265
- weight = e .MixedWeight
266
- case e .NonCoopHint :
267
- weight = e .NonCoopWeight
268
- default :
269
- weight = e .CoopWeight
270
- }
271
-
272
- return e .FeeRate .FeeForWeight (weight )
226
+ func (e feeDetails ) fee () btcutil.Amount {
227
+ return e .FeeRate .FeeForWeight (e .Weight )
273
228
}
274
229
275
230
// combine returns new feeDetails, combining properties.
@@ -282,20 +237,15 @@ func (e1 feeDetails) combine(e2 feeDetails) feeDetails {
282
237
283
238
return feeDetails {
284
239
FeeRate : feeRate ,
285
- MixedWeight : e1 .MixedWeight + e2 .MixedWeight ,
286
- CoopWeight : e1 .CoopWeight + e2 .CoopWeight ,
287
- NonCoopWeight : e1 .NonCoopWeight + e2 .NonCoopWeight ,
288
- NonCoopHint : e1 .NonCoopHint || e2 .NonCoopHint ,
240
+ Weight : e1 .Weight + e2 .Weight ,
289
241
IsExternalAddr : e1 .IsExternalAddr || e2 .IsExternalAddr ,
290
242
}
291
243
}
292
244
293
245
// selectBatches returns the list of id of batches sorted from best to worst.
294
246
// Creation a new batch is encoded as newBatchSignal. For each batch its fee
295
- // rate and a set of weights are provided: weight in case of a mixed batch,
296
- // weight in case of cooperative spending and weight in case non-cooperative
297
- // spending. Also, a hint is provided to signal what spending path will be used
298
- // by the batch.
247
+ // rate and a weight is provided. Also, a hint is provided to signal which
248
+ // spending path will be used by the batch.
299
249
//
300
250
// The same data is also provided for the sweep for which we are selecting a
301
251
// batch to add. In case of the sweep weights are weight deltas resulted from
@@ -308,10 +258,9 @@ func (e1 feeDetails) combine(e2 feeDetails) feeDetails {
308
258
//
309
259
// Each fee details has also IsExternalAddr flag. There is a rule that sweeps
310
260
// having flag IsExternalAddr must go in individual batches. Cooperative
311
- // spending is only available if all the sweeps support cooperative spending
312
- // path of in a mixed batch.
313
- func selectBatches (batches []feeDetails , sweep , oneSweepBatch feeDetails ,
314
- mixedBatch bool ) ([]int32 , error ) {
261
+ // spending may only be available for some sweeps supporting it, not for all.
262
+ func selectBatches (batches []feeDetails ,
263
+ sweep , oneSweepBatch feeDetails ) ([]int32 , error ) {
315
264
316
265
// If the sweep has IsExternalAddr flag, the sweep can't be added to
317
266
// a batch, so create new batch for it.
@@ -332,7 +281,7 @@ func selectBatches(batches []feeDetails, sweep, oneSweepBatch feeDetails,
332
281
// creation with this sweep only in it. The cost is its full fee.
333
282
alternatives = append (alternatives , alternative {
334
283
batchId : newBatchSignal ,
335
- cost : oneSweepBatch .fee (mixedBatch ),
284
+ cost : oneSweepBatch .fee (),
336
285
})
337
286
338
287
// Try to add the sweep to every batch, calculate the costs and
@@ -348,7 +297,7 @@ func selectBatches(batches []feeDetails, sweep, oneSweepBatch feeDetails,
348
297
combinedBatch := batch .combine (sweep )
349
298
350
299
// The cost is the fee increase.
351
- cost := combinedBatch .fee (mixedBatch ) - batch .fee (mixedBatch )
300
+ cost := combinedBatch .fee () - batch .fee ()
352
301
353
302
// The cost must be positive, because we added a sweep.
354
303
if cost <= 0 {
0 commit comments