@@ -36,13 +36,7 @@ func (b *batch) ensurePresigned(ctx context.Context, newSweeps []*sweep,
3636// presignedTxChecker has methods to check if the inputs are presigned.
3737type presignedTxChecker interface {
3838 destPkScripter
39-
40- // SignTx signs an unsigned transaction or returns a pre-signed tx.
41- // It is only called with loadOnly=true by ensurePresigned.
42- SignTx (ctx context.Context , primarySweepID wire.OutPoint ,
43- tx * wire.MsgTx , inputAmt btcutil.Amount ,
44- minRelayFee , feeRate chainfee.SatPerKWeight ,
45- loadOnly bool ) (* wire.MsgTx , error )
39+ presigner
4640}
4741
4842// ensurePresigned checks that there is a presigned transaction spending the
@@ -253,7 +247,7 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
253247
254248 // Cache the destination address.
255249 destAddr , err := getPresignedSweepsDestAddr (
256- ctx , b .cfg .presignedHelper , b . primarySweepID ,
250+ ctx , b .cfg .presignedHelper , primarySweepID ,
257251 b .cfg .chainParams ,
258252 )
259253 if err != nil {
@@ -289,11 +283,12 @@ func (b *batch) presign(ctx context.Context, newSweeps []*sweep) error {
289283
290284// presigner tries to presign a batch transaction.
291285type presigner interface {
292- // Presign tries to presign a batch transaction. If the method returns
293- // nil, it is guaranteed that future calls to SignTx on this set of
294- // sweeps return valid signed transactions.
295- Presign (ctx context.Context , primarySweepID wire.OutPoint ,
296- tx * wire.MsgTx , inputAmt btcutil.Amount ) error
286+ // SignTx signs an unsigned transaction or returns a pre-signed tx.
287+ // It is only called with loadOnly=true by ensurePresigned.
288+ SignTx (ctx context.Context , primarySweepID wire.OutPoint ,
289+ tx * wire.MsgTx , inputAmt btcutil.Amount ,
290+ minRelayFee , feeRate chainfee.SatPerKWeight ,
291+ loadOnly bool ) (* wire.MsgTx , error )
297292}
298293
299294// presign tries to presign batch sweep transactions of the sweeps. It signs
@@ -372,7 +367,14 @@ func presign(ctx context.Context, presigner presigner, destAddr btcutil.Address,
372367 }
373368
374369 // Try to presign this transaction.
375- err = presigner .Presign (ctx , primarySweepID , tx , batchAmt )
370+ const (
371+ loadOnly = false
372+ minRelayFee = chainfee .AbsoluteFeePerKwFloor
373+ )
374+ _ , err = presigner .SignTx (
375+ ctx , primarySweepID , tx , batchAmt , minRelayFee , fr ,
376+ loadOnly ,
377+ )
376378 if err != nil {
377379 return fmt .Errorf ("failed to presign unsigned tx %v " +
378380 "for feeRate %v: %w" , tx .TxHash (), fr , err )
@@ -407,9 +409,16 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
407409 }
408410 }
409411
412+ // Determine the current minimum relay fee based on our chain backend.
413+ minRelayFee , err := b .wallet .MinRelayFee (ctx )
414+ if err != nil {
415+ return 0 , fmt .Errorf ("failed to get minRelayFee: %w" , err ),
416+ false
417+ }
418+
410419 // Cache current height and desired feerate of the batch.
411420 currentHeight := b .currentHeight
412- feeRate := b .rbfCache .FeeRate
421+ feeRate := max ( b .rbfCache .FeeRate , minRelayFee )
413422
414423 // Append this sweep to an array of sweeps. This is needed to keep the
415424 // order of sweeps stored, as iterating the sweeps map does not
@@ -447,13 +456,6 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
447456 batchAmt += sweep .value
448457 }
449458
450- // Determine the current minimum relay fee based on our chain backend.
451- minRelayFee , err := b .wallet .MinRelayFee (ctx )
452- if err != nil {
453- return 0 , fmt .Errorf ("failed to get minRelayFee: %w" , err ),
454- false
455- }
456-
457459 // Get a pre-signed transaction.
458460 const loadOnly = false
459461 signedTx , err := b .cfg .presignedHelper .SignTx (
@@ -508,6 +510,9 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
508510 b .batchTxid = & txHash
509511 b .batchPkScript = tx .TxOut [0 ].PkScript
510512
513+ // Update cached FeeRate not to broadcast a tx with lower feeRate.
514+ b .rbfCache .FeeRate = max (b .rbfCache .FeeRate , signedFeeRate )
515+
511516 return fee , nil , true
512517}
513518
@@ -599,7 +604,7 @@ func CheckSignedTx(unsignedTx, signedTx *wire.MsgTx, inputAmt btcutil.Amount,
599604 unsignedOut := unsignedTx .TxOut [0 ]
600605 signedOut := signedTx .TxOut [0 ]
601606 if ! bytes .Equal (unsignedOut .PkScript , signedOut .PkScript ) {
602- return fmt .Errorf ("mismatch of output pkScript: %v , %v " ,
607+ return fmt .Errorf ("mismatch of output pkScript: %x , %x " ,
603608 unsignedOut .PkScript , signedOut .PkScript )
604609 }
605610
0 commit comments