@@ -28,8 +28,14 @@ func (b *batch) ensurePresigned(ctx context.Context, newSweeps []*sweep,
2828 "adding to an empty batch" )
2929 }
3030
31+ minRelayFeeRate , err := b .wallet .MinRelayFee (ctx )
32+ if err != nil {
33+ return fmt .Errorf ("failed to get minRelayFee: %w" , err )
34+ }
35+
3136 return ensurePresigned (
32- ctx , newSweeps , b .cfg .presignedHelper , b .cfg .chainParams ,
37+ ctx , newSweeps , b .cfg .presignedHelper , minRelayFeeRate ,
38+ b .cfg .chainParams ,
3339 )
3440}
3541
@@ -43,6 +49,7 @@ type presignedTxChecker interface {
4349// inputs of this group only.
4450func ensurePresigned (ctx context.Context , newSweeps []* sweep ,
4551 presignedTxChecker presignedTxChecker ,
52+ minRelayFeeRate chainfee.SatPerKWeight ,
4653 chainParams * chaincfg.Params ) error {
4754
4855 sweeps := make ([]sweep , len (newSweeps ))
@@ -74,7 +81,7 @@ func ensurePresigned(ctx context.Context, newSweeps []*sweep,
7481 const feeRate = chainfee .FeePerKwFloor
7582
7683 tx , _ , _ , _ , err := constructUnsignedTx (
77- sweeps , destAddr , currentHeight , feeRate ,
84+ sweeps , destAddr , currentHeight , feeRate , minRelayFeeRate ,
7885 )
7986 if err != nil {
8087 return fmt .Errorf ("failed to construct unsigned tx " +
@@ -218,6 +225,14 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
218225
219226 b .Infof ("nextBlockFeeRate is %v" , nextBlockFeeRate )
220227
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+
221236 // We need to restore previously added groups. We can do it by reading
222237 // all the sweeps from DB (they must be ordered) and grouping by swap.
223238 groups , err := b .getSweepsGroups (ctx )
@@ -258,7 +273,7 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
258273
259274 err = presign (
260275 ctx , b .cfg .presignedHelper , destAddr , primarySweepID ,
261- sweeps , nextBlockFeeRate ,
276+ sweeps , nextBlockFeeRate , minRelayFeeRate ,
262277 )
263278 if err != nil {
264279 return fmt .Errorf ("failed to presign a transaction " +
@@ -300,7 +315,8 @@ type presigner interface {
300315// 10x of the current next block feerate.
301316func presign (ctx context.Context , presigner presigner , destAddr btcutil.Address ,
302317 primarySweepID wire.OutPoint , sweeps []sweep ,
303- nextBlockFeeRate chainfee.SatPerKWeight ) error {
318+ nextBlockFeeRate chainfee.SatPerKWeight ,
319+ minRelayFeeRate chainfee.SatPerKWeight ) error {
304320
305321 if presigner == nil {
306322 return fmt .Errorf ("presigner is not installed" )
@@ -354,7 +370,7 @@ func presign(ctx context.Context, presigner presigner, destAddr btcutil.Address,
354370 for fr := start ; fr <= stop ; fr = (fr * factorPPM ) / 1_000_000 {
355371 // Construct an unsigned transaction for this fee rate.
356372 tx , _ , feeForWeight , fee , err := constructUnsignedTx (
357- sweeps , destAddr , currentHeight , fr ,
373+ sweeps , destAddr , currentHeight , fr , minRelayFeeRate ,
358374 )
359375 if err != nil {
360376 return fmt .Errorf ("failed to construct unsigned tx " +
@@ -411,15 +427,15 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
411427 }
412428
413429 // 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 )
415431 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 ),
417433 false
418434 }
419435
420436 // Cache current height and desired feerate of the batch.
421437 currentHeight := b .currentHeight
422- feeRate := max (b .rbfCache .FeeRate , minRelayFee )
438+ feeRate := max (b .rbfCache .FeeRate , minRelayFeeRate )
423439
424440 // Append this sweep to an array of sweeps. This is needed to keep the
425441 // 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,
441457
442458 // Construct unsigned batch transaction.
443459 tx , weight , _ , fee , err := constructUnsignedTx (
444- sweeps , address , currentHeight , feeRate ,
460+ sweeps , address , currentHeight , feeRate , minRelayFeeRate ,
445461 )
446462 if err != nil {
447463 return 0 , fmt .Errorf ("failed to construct tx: %w" , err ),
@@ -460,7 +476,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
460476 // Get a pre-signed transaction.
461477 const loadOnly = false
462478 signedTx , err := b .cfg .presignedHelper .SignTx (
463- ctx , b .primarySweepID , tx , batchAmt , minRelayFee , feeRate ,
479+ ctx , b .primarySweepID , tx , batchAmt , minRelayFeeRate , feeRate ,
464480 loadOnly ,
465481 )
466482 if err != nil {
@@ -470,7 +486,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
470486
471487 // Run sanity checks to make sure presignedHelper.SignTx complied with
472488 // all the invariants.
473- err = CheckSignedTx (tx , signedTx , batchAmt , minRelayFee )
489+ err = CheckSignedTx (tx , signedTx , batchAmt , minRelayFeeRate )
474490 if err != nil {
475491 return 0 , fmt .Errorf ("signed tx doesn't correspond the " +
476492 "unsigned tx: %w" , err ), false
0 commit comments