@@ -811,18 +811,26 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
811
811
type wrappedLogger struct {
812
812
btclog.Logger
813
813
814
+ mu sync.Mutex
815
+
814
816
debugMessages []string
815
817
infoMessages []string
816
818
}
817
819
818
820
// Debugf logs debug message.
819
821
func (l * wrappedLogger ) Debugf (format string , params ... interface {}) {
822
+ l .mu .Lock ()
823
+ defer l .mu .Unlock ()
824
+
820
825
l .debugMessages = append (l .debugMessages , format )
821
826
l .Logger .Debugf (format , params ... )
822
827
}
823
828
824
829
// Infof logs info message.
825
830
func (l * wrappedLogger ) Infof (format string , params ... interface {}) {
831
+ l .mu .Lock ()
832
+ defer l .mu .Unlock ()
833
+
826
834
l .infoMessages = append (l .infoMessages , format )
827
835
l .Logger .Infof (format , params ... )
828
836
}
@@ -950,6 +958,9 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
950
958
// Wait for batch publishing to be skipped, because initialDelay has not
951
959
// ended.
952
960
require .EventuallyWithT (t , func (c * assert.CollectT ) {
961
+ testLogger .mu .Lock ()
962
+ defer testLogger .mu .Unlock ()
963
+
953
964
assert .Contains (c , testLogger .debugMessages , stillWaitingMsg )
954
965
}, test .Timeout , eventuallyCheckFrequency )
955
966
@@ -1274,6 +1285,9 @@ func testDelays(t *testing.T, store testStore, batcherStore testBatcherStore) {
1274
1285
1275
1286
// Wait for sweep to be added to the batch.
1276
1287
require .EventuallyWithT (t , func (c * assert.CollectT ) {
1288
+ testLogger2 .mu .Lock ()
1289
+ defer testLogger2 .mu .Unlock ()
1290
+
1277
1291
assert .Contains (c , testLogger2 .infoMessages , "adding sweep %x" )
1278
1292
}, test .Timeout , eventuallyCheckFrequency )
1279
1293
@@ -2810,11 +2824,22 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
2810
2824
2811
2825
type sweepFetcherMock struct {
2812
2826
store map [lntypes.Hash ]* SweepInfo
2827
+ mu sync.Mutex
2828
+ }
2829
+
2830
+ func (f * sweepFetcherMock ) setSweep (hash lntypes.Hash , info * SweepInfo ) {
2831
+ f .mu .Lock ()
2832
+ defer f .mu .Unlock ()
2833
+
2834
+ f .store [hash ] = info
2813
2835
}
2814
2836
2815
2837
func (f * sweepFetcherMock ) FetchSweep (ctx context.Context , hash lntypes.Hash ) (
2816
2838
* SweepInfo , error ) {
2817
2839
2840
+ f .mu .Lock ()
2841
+ defer f .mu .Unlock ()
2842
+
2818
2843
return f .store [hash ], nil
2819
2844
}
2820
2845
@@ -3279,7 +3304,7 @@ func testWithMixedBatch(t *testing.T, store testStore,
3279
3304
if i == 0 {
3280
3305
sweepInfo .NonCoopHint = true
3281
3306
}
3282
- sweepFetcher .store [ swapHash ] = sweepInfo
3307
+ sweepFetcher .setSweep ( swapHash , sweepInfo )
3283
3308
3284
3309
// Create sweep request.
3285
3310
sweepReq := SweepRequest {
@@ -3433,7 +3458,7 @@ func testWithMixedBatchCustom(t *testing.T, store testStore,
3433
3458
)
3434
3459
require .NoError (t , err )
3435
3460
3436
- sweepFetcher .store [ swapHash ] = & SweepInfo {
3461
+ sweepFetcher .setSweep ( swapHash , & SweepInfo {
3437
3462
Preimage : preimages [i ],
3438
3463
NonCoopHint : nonCoopHints [i ],
3439
3464
@@ -3445,7 +3470,7 @@ func testWithMixedBatchCustom(t *testing.T, store testStore,
3445
3470
HTLC : * htlc ,
3446
3471
HTLCSuccessEstimator : htlc .AddSuccessToEstimator ,
3447
3472
DestAddr : destAddr ,
3448
- }
3473
+ })
3449
3474
3450
3475
// Create sweep request.
3451
3476
sweepReq := SweepRequest {
@@ -4035,13 +4060,18 @@ type loopdbBatcherStore struct {
4035
4060
BatcherStore
4036
4061
4037
4062
sweepsSet map [lntypes.Hash ]struct {}
4063
+
4064
+ mu sync.Mutex
4038
4065
}
4039
4066
4040
4067
// UpsertSweep inserts a sweep into the database, or updates an existing sweep
4041
4068
// if it already exists. This wrapper was added to update sweepsSet.
4042
4069
func (s * loopdbBatcherStore ) UpsertSweep (ctx context.Context ,
4043
4070
sweep * dbSweep ) error {
4044
4071
4072
+ s .mu .Lock ()
4073
+ defer s .mu .Unlock ()
4074
+
4045
4075
err := s .BatcherStore .UpsertSweep (ctx , sweep )
4046
4076
if err == nil {
4047
4077
s .sweepsSet [sweep .SwapHash ] = struct {}{}
@@ -4051,7 +4081,11 @@ func (s *loopdbBatcherStore) UpsertSweep(ctx context.Context,
4051
4081
4052
4082
// AssertSweepStored asserts that a sweep is stored.
4053
4083
func (s * loopdbBatcherStore ) AssertSweepStored (id lntypes.Hash ) bool {
4084
+ s .mu .Lock ()
4085
+ defer s .mu .Unlock ()
4086
+
4054
4087
_ , has := s .sweepsSet [id ]
4088
+
4055
4089
return has
4056
4090
}
4057
4091
0 commit comments