@@ -28,8 +28,14 @@ func (b *batch) ensurePresigned(ctx context.Context, newSweeps []*sweep,
28
28
"adding to an empty batch" )
29
29
}
30
30
31
+ minRelayFeeRate , err := b .wallet .MinRelayFee (ctx )
32
+ if err != nil {
33
+ return fmt .Errorf ("failed to get minRelayFee: %w" , err )
34
+ }
35
+
31
36
return ensurePresigned (
32
- ctx , newSweeps , b .cfg .presignedHelper , b .cfg .chainParams ,
37
+ ctx , newSweeps , b .cfg .presignedHelper , minRelayFeeRate ,
38
+ b .cfg .chainParams ,
33
39
)
34
40
}
35
41
@@ -43,6 +49,7 @@ type presignedTxChecker interface {
43
49
// inputs of this group only.
44
50
func ensurePresigned (ctx context.Context , newSweeps []* sweep ,
45
51
presignedTxChecker presignedTxChecker ,
52
+ minRelayFeeRate chainfee.SatPerKWeight ,
46
53
chainParams * chaincfg.Params ) error {
47
54
48
55
sweeps := make ([]sweep , len (newSweeps ))
@@ -74,7 +81,7 @@ func ensurePresigned(ctx context.Context, newSweeps []*sweep,
74
81
const feeRate = chainfee .FeePerKwFloor
75
82
76
83
tx , _ , _ , _ , err := constructUnsignedTx (
77
- sweeps , destAddr , currentHeight , feeRate ,
84
+ sweeps , destAddr , currentHeight , feeRate , minRelayFeeRate ,
78
85
)
79
86
if err != nil {
80
87
return fmt .Errorf ("failed to construct unsigned tx " +
@@ -218,6 +225,14 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
218
225
219
226
b .Infof ("nextBlockFeeRate is %v" , nextBlockFeeRate )
220
227
228
+ // Find the minRelayFeeRate.
229
+ minRelayFeeRate , err := b .wallet .MinRelayFee (ctx )
230
+ if err != nil {
231
+ return fmt .Errorf ("failed to get minRelayFeeRate: %w" , err )
232
+ }
233
+
234
+ b .Infof ("minRelayFeeRate is %v" , minRelayFeeRate )
235
+
221
236
// We need to restore previously added groups. We can do it by reading
222
237
// all the sweeps from DB (they must be ordered) and grouping by swap.
223
238
groups , err := b .getSweepsGroups (ctx )
@@ -258,7 +273,7 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
258
273
259
274
err = presign (
260
275
ctx , b .cfg .presignedHelper , destAddr , primarySweepID ,
261
- sweeps , nextBlockFeeRate ,
276
+ sweeps , nextBlockFeeRate , minRelayFeeRate ,
262
277
)
263
278
if err != nil {
264
279
return fmt .Errorf ("failed to presign a transaction " +
@@ -300,7 +315,8 @@ type presigner interface {
300
315
// 10x of the current next block feerate.
301
316
func presign (ctx context.Context , presigner presigner , destAddr btcutil.Address ,
302
317
primarySweepID wire.OutPoint , sweeps []sweep ,
303
- nextBlockFeeRate chainfee.SatPerKWeight ) error {
318
+ nextBlockFeeRate chainfee.SatPerKWeight ,
319
+ minRelayFeeRate chainfee.SatPerKWeight ) error {
304
320
305
321
if presigner == nil {
306
322
return fmt .Errorf ("presigner is not installed" )
@@ -354,7 +370,7 @@ func presign(ctx context.Context, presigner presigner, destAddr btcutil.Address,
354
370
for fr := start ; fr <= stop ; fr = (fr * factorPPM ) / 1_000_000 {
355
371
// Construct an unsigned transaction for this fee rate.
356
372
tx , _ , feeForWeight , fee , err := constructUnsignedTx (
357
- sweeps , destAddr , currentHeight , fr ,
373
+ sweeps , destAddr , currentHeight , fr , minRelayFeeRate ,
358
374
)
359
375
if err != nil {
360
376
return fmt .Errorf ("failed to construct unsigned tx " +
@@ -411,15 +427,15 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
411
427
}
412
428
413
429
// Determine the current minimum relay fee based on our chain backend.
414
- minRelayFee , err := b .wallet .MinRelayFee (ctx )
430
+ minRelayFeeRate , err := b .wallet .MinRelayFee (ctx )
415
431
if err != nil {
416
- return 0 , fmt .Errorf ("failed to get minRelayFee : %w" , err ),
432
+ return 0 , fmt .Errorf ("failed to get minRelayFeeRate : %w" , err ),
417
433
false
418
434
}
419
435
420
436
// Cache current height and desired feerate of the batch.
421
437
currentHeight := b .currentHeight
422
- feeRate := max (b .rbfCache .FeeRate , minRelayFee )
438
+ feeRate := max (b .rbfCache .FeeRate , minRelayFeeRate )
423
439
424
440
// Append this sweep to an array of sweeps. This is needed to keep the
425
441
// order of sweeps stored, as iterating the sweeps map does not
@@ -441,7 +457,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
441
457
442
458
// Construct unsigned batch transaction.
443
459
tx , weight , _ , fee , err := constructUnsignedTx (
444
- sweeps , address , currentHeight , feeRate ,
460
+ sweeps , address , currentHeight , feeRate , minRelayFeeRate ,
445
461
)
446
462
if err != nil {
447
463
return 0 , fmt .Errorf ("failed to construct tx: %w" , err ),
@@ -460,7 +476,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
460
476
// Get a pre-signed transaction.
461
477
const loadOnly = false
462
478
signedTx , err := b .cfg .presignedHelper .SignTx (
463
- ctx , b .primarySweepID , tx , batchAmt , minRelayFee , feeRate ,
479
+ ctx , b .primarySweepID , tx , batchAmt , minRelayFeeRate , feeRate ,
464
480
loadOnly ,
465
481
)
466
482
if err != nil {
@@ -470,7 +486,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
470
486
471
487
// Run sanity checks to make sure presignedHelper.SignTx complied with
472
488
// all the invariants.
473
- err = CheckSignedTx (tx , signedTx , batchAmt , minRelayFee )
489
+ err = CheckSignedTx (tx , signedTx , batchAmt , minRelayFeeRate )
474
490
if err != nil {
475
491
return 0 , fmt .Errorf ("signed tx doesn't correspond the " +
476
492
"unsigned tx: %w" , err ), false
0 commit comments