@@ -95,19 +95,6 @@ func (h *mockPresignedHelper) getTxFeerate(tx *wire.MsgTx,
9595 return chainfee .NewSatPerKWeight (fee , weight )
9696}
9797
98- // IsPresigned returns if the input was previously used in any call to the
99- // SetOutpointOnline method.
100- func (h * mockPresignedHelper ) IsPresigned (ctx context.Context ,
101- input wire.OutPoint ) (bool , error ) {
102-
103- h .mu .Lock ()
104- defer h .mu .Unlock ()
105-
106- _ , has := h .onlineOutpoints [input ]
107-
108- return has , nil
109- }
110-
11198// Presign tries to presign the transaction. It succeeds if all the inputs
11299// are online. In case of success it adds the transaction to presignedBatches.
113100func (h * mockPresignedHelper ) Presign (ctx context.Context ,
@@ -237,18 +224,21 @@ func (h *mockPresignedHelper) CleanupTransactions(ctx context.Context,
237224// sweepTimeout is swap timeout block height used in tests of presigned mode.
238225const sweepTimeout = 1000
239226
240- // dummySweepFetcherMock implements SweepFetcher by returning blank SweepInfo.
241- // It is used in TestPresigned, because it doesn't use any fields of SweepInfo.
242- type dummySweepFetcherMock struct {
243- }
244-
245227// FetchSweep returns blank SweepInfo.
246- func (f * dummySweepFetcherMock ) FetchSweep (_ context.Context ,
247- _ lntypes.Hash , _ wire.OutPoint ) (* SweepInfo , error ) {
228+ // This method implements SweepFetcher interface.
229+ func (h * mockPresignedHelper ) FetchSweep (_ context.Context ,
230+ _ lntypes.Hash , utxo wire.OutPoint ) (* SweepInfo , error ) {
231+
232+ h .mu .Lock ()
233+ defer h .mu .Unlock ()
234+
235+ _ , has := h .onlineOutpoints [utxo ]
248236
249237 return & SweepInfo {
250238 // Set Timeout to prevent warning messages about timeout=0.
251239 Timeout : sweepTimeout ,
240+
241+ IsPresigned : has ,
252242 }, nil
253243}
254244
@@ -274,7 +264,7 @@ func testPresigned_forgotten_presign(t *testing.T,
274264
275265 batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
276266 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
277- batcherStore , & dummySweepFetcherMock {} ,
267+ batcherStore , presignedHelper ,
278268 WithCustomFeeRate (customFeeRate ),
279269 WithPresignedHelper (presignedHelper ))
280270
@@ -350,7 +340,7 @@ func testPresigned_input1_offline_then_input2(t *testing.T,
350340
351341 batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
352342 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
353- batcherStore , & dummySweepFetcherMock {} ,
343+ batcherStore , presignedHelper ,
354344 WithCustomFeeRate (customFeeRate ),
355345 WithPresignedHelper (presignedHelper ))
356346 go func () {
@@ -532,7 +522,7 @@ func testPresigned_two_inputs_one_goes_offline(t *testing.T,
532522 batcher := NewBatcher (
533523 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
534524 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
535- batcherStore , & dummySweepFetcherMock {} ,
525+ batcherStore , presignedHelper ,
536526 WithCustomFeeRate (customFeeRate ),
537527 WithPresignedHelper (presignedHelper ),
538528 )
@@ -668,7 +658,7 @@ func testPresigned_first_publish_fails(t *testing.T,
668658 batcher := NewBatcher (
669659 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
670660 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
671- batcherStore , & dummySweepFetcherMock {} ,
661+ batcherStore , presignedHelper ,
672662 WithCustomFeeRate (customFeeRate ),
673663 WithPresignedHelper (presignedHelper ),
674664 )
@@ -791,7 +781,7 @@ func testPresigned_locktime(t *testing.T,
791781 batcher := NewBatcher (
792782 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
793783 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
794- batcherStore , & dummySweepFetcherMock {} ,
784+ batcherStore , presignedHelper ,
795785 WithCustomFeeRate (customFeeRate ),
796786 WithPresignedHelper (presignedHelper ),
797787 )
@@ -875,7 +865,7 @@ func testPresigned_presigned_group(t *testing.T,
875865 batcher := NewBatcher (
876866 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
877867 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
878- batcherStore , & dummySweepFetcherMock {} ,
868+ batcherStore , presignedHelper ,
879869 WithCustomFeeRate (customFeeRate ),
880870 WithPresignedHelper (presignedHelper ),
881871 )
@@ -1052,6 +1042,30 @@ func testPresigned_presigned_group(t *testing.T,
10521042 require .Equal (t , batchPkScript , tx .TxOut [0 ].PkScript )
10531043}
10541044
1045+ // wrappedStoreWithPresignedFlag wraps a SweepFetcher store adding IsPresigned
1046+ // flag to the returned sweeps, taking it from mockPresignedHelper.
1047+ type wrappedStoreWithPresignedFlag struct {
1048+ backend SweepFetcher
1049+ helper * mockPresignedHelper
1050+ }
1051+
1052+ // // FetchSweep returns details of the sweep.
1053+ func (s * wrappedStoreWithPresignedFlag ) FetchSweep (ctx context.Context ,
1054+ swap lntypes.Hash , utxo wire.OutPoint ) (* SweepInfo , error ) {
1055+
1056+ sweepInfo , err := s .backend .FetchSweep (ctx , swap , utxo )
1057+ if err != nil {
1058+ return nil , err
1059+ }
1060+
1061+ // Attach IsPresigned flag.
1062+ s .helper .mu .Lock ()
1063+ defer s .helper .mu .Unlock ()
1064+ _ , sweepInfo .IsPresigned = s .helper .onlineOutpoints [utxo ]
1065+
1066+ return sweepInfo , nil
1067+ }
1068+
10551069// testPresigned_presigned_and_regular_sweeps tests a combination of presigned
10561070// mode and regular mode for the following scenario: one regular input is added,
10571071// then a presigned input is added and it goes to another batch, because they
@@ -1088,10 +1102,15 @@ func testPresigned_presigned_and_regular_sweeps(t *testing.T, store testStore,
10881102 sweepStore , err := NewSweepFetcherFromSwapStore (store , lnd .ChainParams )
10891103 require .NoError (t , err )
10901104
1105+ sweepFetcher := & wrappedStoreWithPresignedFlag {
1106+ backend : sweepStore ,
1107+ helper : presignedHelper ,
1108+ }
1109+
10911110 batcher := NewBatcher (
10921111 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
10931112 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1094- batcherStore , sweepStore ,
1113+ batcherStore , sweepFetcher ,
10951114 WithCustomFeeRate (customFeeRate ),
10961115 WithPresignedHelper (presignedHelper ),
10971116 )
@@ -1359,7 +1378,7 @@ func testPresigned_purging(t *testing.T, numSwaps, numConfirmedSwaps int,
13591378 batcher := NewBatcher (
13601379 lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
13611380 testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1362- batcherStore , & dummySweepFetcherMock {} ,
1381+ batcherStore , presignedHelper ,
13631382 WithCustomFeeRate (customFeeRate ),
13641383 WithPresignedHelper (presignedHelper ),
13651384 )
0 commit comments