@@ -4152,14 +4152,15 @@ func (h *mockPresignedHelper) DestPkScript(ctx context.Context,
41524152// the exact transaction passed and adds it to presignedBatches. Otherwise it
41534153// looks for a transaction in presignedBatches satisfying the criteria.
41544154func (h * mockPresignedHelper ) SignTx (ctx context.Context , tx * wire.MsgTx ,
4155- inputAmt btcutil.Amount ,
4156- minRelayFee , feeRate chainfee. SatPerKWeight ) (* wire.MsgTx , error ) {
4155+ inputAmt btcutil.Amount , minRelayFee , feeRate chainfee. SatPerKWeight ,
4156+ presignedOnly bool ) (* wire.MsgTx , error ) {
41574157
41584158 h .mu .Lock ()
41594159 defer h .mu .Unlock ()
41604160
4161- // If all the inputs are online, sign this exact transaction.
4162- if offline := h .offlineInputs (tx ); len (offline ) == 0 {
4161+ // If all the inputs are online and presignedOnly is not set, sign
4162+ // this exact transaction.
4163+ if offline := h .offlineInputs (tx ); len (offline ) == 0 && ! presignedOnly {
41634164 tx = tx .Copy ()
41644165 h .sign (tx )
41654166
@@ -4298,9 +4299,9 @@ func testPresigned_input1_offline_then_input2(t *testing.T,
42984299 WithCustomFeeRate (customFeeRate ),
42994300 WithPresignedHelper (presignedHelper ))
43004301
4302+ batcherErrChan := make (chan error )
43014303 go func () {
4302- err := batcher .Run (ctx )
4303- checkBatcherError (t , err )
4304+ batcherErrChan <- batcher .Run (ctx )
43044305 }()
43054306
43064307 setFeeRate (feeRateLow )
@@ -4318,6 +4319,25 @@ func testPresigned_input1_offline_then_input2(t *testing.T,
43184319 Notifier : & dummyNotifier ,
43194320 }
43204321
4322+ // Make sure that the batcher crashes if AddSweep is called before
4323+ // PresignSweep even if the input is online.
4324+ presignedHelper .SetOutpointOnline (op1 , true )
4325+ require .NoError (t , batcher .AddSweep (& sweepReq1 ))
4326+ err = <- batcherErrChan
4327+ require .Error (t , err )
4328+ require .ErrorContains (t , err , "PresignSweep was not called" )
4329+
4330+ // Start the batcher again.
4331+ batcher = NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
4332+ testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
4333+ batcherStore , & dummySweepFetcherMock {},
4334+ WithCustomFeeRate (customFeeRate ),
4335+ WithPresignedHelper (presignedHelper ))
4336+ go func () {
4337+ err := batcher .Run (ctx )
4338+ checkBatcherError (t , err )
4339+ }()
4340+
43214341 // This should fail, because the input is offline.
43224342 presignedHelper .SetOutpointOnline (op1 , false )
43234343 err = batcher .PresignSweep (ctx , op1 , 1_000_000 , sweepTimeout , destAddr )
@@ -4429,9 +4449,10 @@ func testPresigned_input1_offline_then_input2(t *testing.T,
44294449
44304450 // Make sure we still have presigned transactions for the second batch.
44314451 presignedHelper .SetOutpointOnline (op2 , false )
4452+ const presignedOnly = true
44324453 _ , err = presignedHelper .SignTx (
44334454 ctx , batch2 , 2_000_000 , chainfee .FeePerKwFloor ,
4434- chainfee .FeePerKwFloor ,
4455+ chainfee .FeePerKwFloor , presignedOnly ,
44354456 )
44364457 require .NoError (t , err )
44374458}
0 commit comments