Skip to content

Commit 02d61d7

Browse files
authored
[Server] Fix usage of forfeitsBoardingSigsChan (#489)
* fix checkForfeitsAndBoardingSigsSent channel * fix sleeping time to avoid infinite recursion in case roundInterval is less than 5 seconds
1 parent fe50d79 commit 02d61d7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

server/internal/core/application/covenantless.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,9 @@ func (s *covenantlessService) SignVtxos(ctx context.Context, forfeitTxs []string
764764

765765
go func() {
766766
s.currentRoundLock.Lock()
767-
s.checkForfeitsAndBoardingSigsSent(s.currentRound)
767+
round := s.currentRound
768768
s.currentRoundLock.Unlock()
769+
s.checkForfeitsAndBoardingSigsSent(round)
769770
}()
770771

771772
return nil
@@ -785,8 +786,9 @@ func (s *covenantlessService) SignRoundTx(ctx context.Context, signedRoundTx str
785786

786787
go func() {
787788
s.currentRoundLock.Lock()
788-
s.checkForfeitsAndBoardingSigsSent(s.currentRound)
789+
round := s.currentRound
789790
s.currentRoundLock.Unlock()
791+
s.checkForfeitsAndBoardingSigsSent(round)
790792
}()
791793

792794
return nil
@@ -813,7 +815,6 @@ func (s *covenantlessService) checkForfeitsAndBoardingSigsSent(currentRound *dom
813815
select {
814816
case s.forfeitsBoardingSigsChan <- struct{}{}:
815817
default:
816-
time.Sleep(time.Millisecond)
817818
}
818819
}
819820
}
@@ -1168,16 +1169,21 @@ func (s *covenantlessService) startRound() {
11681169
//nolint:all
11691170
round.StartRegistration()
11701171
s.currentRound = round
1172+
close(s.forfeitsBoardingSigsChan)
1173+
s.forfeitsBoardingSigsChan = make(chan struct{}, 1)
11711174

11721175
defer func() {
11731176
roundEndTime := time.Now().Add(time.Duration(s.roundInterval) * time.Second)
1174-
time.Sleep(time.Duration(s.roundInterval/6) * time.Second)
1177+
sleepingTime := s.roundInterval / 6
1178+
if sleepingTime < 1 {
1179+
sleepingTime = 1
1180+
}
1181+
time.Sleep(time.Duration(sleepingTime) * time.Second)
11751182
s.startFinalization(roundEndTime)
11761183
}()
11771184

11781185
log.Debugf("started registration stage for new round: %s", round.Id)
11791186
}
1180-
11811187
func (s *covenantlessService) startFinalization(roundEndTime time.Time) {
11821188
log.Debugf("started finalization stage for round: %s", s.currentRound.Id)
11831189
ctx := context.Background()
@@ -1447,7 +1453,9 @@ func (s *covenantlessService) finalizeRound(notes []note.Note, roundEndTime time
14471453
defer s.startRound()
14481454

14491455
ctx := context.Background()
1456+
s.currentRoundLock.Lock()
14501457
round := s.currentRound
1458+
s.currentRoundLock.Unlock()
14511459
if round.IsFailed() {
14521460
return
14531461
}

0 commit comments

Comments
 (0)