@@ -95,19 +95,6 @@ func (h *mockPresignedHelper) getTxFeerate(tx *wire.MsgTx,
95
95
return chainfee .NewSatPerKWeight (fee , weight )
96
96
}
97
97
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
-
111
98
// Presign tries to presign the transaction. It succeeds if all the inputs
112
99
// are online. In case of success it adds the transaction to presignedBatches.
113
100
func (h * mockPresignedHelper ) Presign (ctx context.Context ,
@@ -237,18 +224,21 @@ func (h *mockPresignedHelper) CleanupTransactions(ctx context.Context,
237
224
// sweepTimeout is swap timeout block height used in tests of presigned mode.
238
225
const sweepTimeout = 1000
239
226
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
-
245
227
// 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 ]
248
236
249
237
return & SweepInfo {
250
238
// Set Timeout to prevent warning messages about timeout=0.
251
239
Timeout : sweepTimeout ,
240
+
241
+ IsPresigned : has ,
252
242
}, nil
253
243
}
254
244
@@ -274,7 +264,7 @@ func testPresigned_forgotten_presign(t *testing.T,
274
264
275
265
batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
276
266
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
277
- batcherStore , & dummySweepFetcherMock {} ,
267
+ batcherStore , presignedHelper ,
278
268
WithCustomFeeRate (customFeeRate ),
279
269
WithPresignedHelper (presignedHelper ))
280
270
@@ -350,7 +340,7 @@ func testPresigned_input1_offline_then_input2(t *testing.T,
350
340
351
341
batcher := NewBatcher (lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
352
342
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
353
- batcherStore , & dummySweepFetcherMock {} ,
343
+ batcherStore , presignedHelper ,
354
344
WithCustomFeeRate (customFeeRate ),
355
345
WithPresignedHelper (presignedHelper ))
356
346
go func () {
@@ -532,7 +522,7 @@ func testPresigned_two_inputs_one_goes_offline(t *testing.T,
532
522
batcher := NewBatcher (
533
523
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
534
524
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
535
- batcherStore , & dummySweepFetcherMock {} ,
525
+ batcherStore , presignedHelper ,
536
526
WithCustomFeeRate (customFeeRate ),
537
527
WithPresignedHelper (presignedHelper ),
538
528
)
@@ -668,7 +658,7 @@ func testPresigned_first_publish_fails(t *testing.T,
668
658
batcher := NewBatcher (
669
659
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
670
660
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
671
- batcherStore , & dummySweepFetcherMock {} ,
661
+ batcherStore , presignedHelper ,
672
662
WithCustomFeeRate (customFeeRate ),
673
663
WithPresignedHelper (presignedHelper ),
674
664
)
@@ -791,7 +781,7 @@ func testPresigned_locktime(t *testing.T,
791
781
batcher := NewBatcher (
792
782
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
793
783
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
794
- batcherStore , & dummySweepFetcherMock {} ,
784
+ batcherStore , presignedHelper ,
795
785
WithCustomFeeRate (customFeeRate ),
796
786
WithPresignedHelper (presignedHelper ),
797
787
)
@@ -875,7 +865,7 @@ func testPresigned_presigned_group(t *testing.T,
875
865
batcher := NewBatcher (
876
866
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
877
867
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
878
- batcherStore , & dummySweepFetcherMock {} ,
868
+ batcherStore , presignedHelper ,
879
869
WithCustomFeeRate (customFeeRate ),
880
870
WithPresignedHelper (presignedHelper ),
881
871
)
@@ -1052,6 +1042,30 @@ func testPresigned_presigned_group(t *testing.T,
1052
1042
require .Equal (t , batchPkScript , tx .TxOut [0 ].PkScript )
1053
1043
}
1054
1044
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
+
1055
1069
// testPresigned_presigned_and_regular_sweeps tests a combination of presigned
1056
1070
// mode and regular mode for the following scenario: one regular input is added,
1057
1071
// 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,
1088
1102
sweepStore , err := NewSweepFetcherFromSwapStore (store , lnd .ChainParams )
1089
1103
require .NoError (t , err )
1090
1104
1105
+ sweepFetcher := & wrappedStoreWithPresignedFlag {
1106
+ backend : sweepStore ,
1107
+ helper : presignedHelper ,
1108
+ }
1109
+
1091
1110
batcher := NewBatcher (
1092
1111
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
1093
1112
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1094
- batcherStore , sweepStore ,
1113
+ batcherStore , sweepFetcher ,
1095
1114
WithCustomFeeRate (customFeeRate ),
1096
1115
WithPresignedHelper (presignedHelper ),
1097
1116
)
@@ -1359,7 +1378,7 @@ func testPresigned_purging(t *testing.T, numSwaps, numConfirmedSwaps int,
1359
1378
batcher := NewBatcher (
1360
1379
lnd .WalletKit , lnd .ChainNotifier , lnd .Signer ,
1361
1380
testMuSig2SignSweep , testVerifySchnorrSig , lnd .ChainParams ,
1362
- batcherStore , & dummySweepFetcherMock {} ,
1381
+ batcherStore , presignedHelper ,
1363
1382
WithCustomFeeRate (customFeeRate ),
1364
1383
WithPresignedHelper (presignedHelper ),
1365
1384
)
0 commit comments