@@ -298,7 +298,7 @@ type UtxoSweeper struct {
298298 // to sweep.
299299 inputs InputsMap
300300
301- currentOutputScript [] byte
301+ currentOutputScript fn. Option [lnwallet. AddrWithKey ]
302302
303303 relayFeeRate chainfee.SatPerKWeight
304304
@@ -796,12 +796,19 @@ func (s *UtxoSweeper) signalResult(pi *SweeperInput, result Result) {
796796// the tx. The output address is only marked as used if the publish succeeds.
797797func (s * UtxoSweeper ) sweep (set InputSet ) error {
798798 // Generate an output script if there isn't an unused script available.
799- if s .currentOutputScript == nil {
800- pkScript , err := s .cfg .GenSweepScript ().Unpack ()
799+ if s .currentOutputScript . IsNone () {
800+ addr , err := s .cfg .GenSweepScript ().Unpack ()
801801 if err != nil {
802802 return fmt .Errorf ("gen sweep script: %w" , err )
803803 }
804- s .currentOutputScript = pkScript .DeliveryAddress
804+ s .currentOutputScript = fn .Some (addr )
805+ }
806+
807+ sweepAddr , err := s .currentOutputScript .UnwrapOrErr (
808+ fmt .Errorf ("none sweep script" ),
809+ )
810+ if err != nil {
811+ return err
805812 }
806813
807814 // Create a fee bump request and ask the publisher to broadcast it. The
@@ -811,7 +818,7 @@ func (s *UtxoSweeper) sweep(set InputSet) error {
811818 Inputs : set .Inputs (),
812819 Budget : set .Budget (),
813820 DeadlineHeight : set .DeadlineHeight (),
814- DeliveryAddress : s . currentOutputScript ,
821+ DeliveryAddress : sweepAddr . DeliveryAddress ,
815822 MaxFeeRate : s .cfg .MaxFeeRate .FeePerKWeight (),
816823 StartingFeeRate : set .StartingFeeRate (),
817824 // TODO(yy): pass the strategy here.
@@ -1702,10 +1709,10 @@ func (s *UtxoSweeper) handleBumpEventTxPublished(r *BumpResult) error {
17021709 log .Debugf ("Published sweep tx %v, num_inputs=%v, height=%v" ,
17031710 tx .TxHash (), len (tx .TxIn ), s .currentHeight )
17041711
1705- // If there's no error, remove the output script. Otherwise
1706- // keep it so that it can be reused for the next transaction
1707- // and causes no address inflation.
1708- s .currentOutputScript = nil
1712+ // If there's no error, remove the output script. Otherwise keep it so
1713+ // that it can be reused for the next transaction and causes no address
1714+ // inflation.
1715+ s .currentOutputScript = fn . None [lnwallet. AddrWithKey ]()
17091716
17101717 return nil
17111718}
0 commit comments