@@ -52,8 +52,14 @@ func (s *treeSigningSessionsStore) Get(roundId string) (*ports.MusigSigningSessi
52
52
func (s * treeSigningSessionsStore ) Delete (roundId string ) {
53
53
s .lock .Lock ()
54
54
defer s .lock .Unlock ()
55
- close (s .nonceCollectedCh [roundId ])
56
- close (s .sigsCollectedCh [roundId ])
55
+
56
+ if ch , exists := s .nonceCollectedCh [roundId ]; exists {
57
+ close (ch )
58
+ }
59
+ if ch , exists := s .sigsCollectedCh [roundId ]; exists {
60
+ close (ch )
61
+ }
62
+
57
63
delete (s .nonceCollectedCh , roundId )
58
64
delete (s .sigsCollectedCh , roundId )
59
65
delete (s .sessions , roundId )
@@ -76,7 +82,12 @@ func (s *treeSigningSessionsStore) AddNonces(
76
82
s .sessions [roundId ].Nonces [pubkey ] = nonces
77
83
78
84
if len (s .sessions [roundId ].Nonces ) == s .sessions [roundId ].NbCosigners - 1 {
79
- s .nonceCollectedCh [roundId ] <- struct {}{}
85
+ if ch , exists := s .nonceCollectedCh [roundId ]; exists {
86
+ select {
87
+ case ch <- struct {}{}:
88
+ default :
89
+ }
90
+ }
80
91
}
81
92
82
93
return nil
@@ -99,16 +110,31 @@ func (s *treeSigningSessionsStore) AddSignatures(
99
110
s .sessions [roundId ].Signatures [pubkey ] = sigs
100
111
101
112
if len (s .sessions [roundId ].Signatures ) == s .sessions [roundId ].NbCosigners - 1 {
102
- s .sigsCollectedCh [roundId ] <- struct {}{}
113
+ if ch , exists := s .sigsCollectedCh [roundId ]; exists {
114
+ select {
115
+ case ch <- struct {}{}:
116
+ default :
117
+ }
118
+ }
103
119
}
104
120
105
121
return nil
106
122
}
107
123
108
124
func (s * treeSigningSessionsStore ) NoncesCollected (roundId string ) <- chan struct {} {
109
- return s .nonceCollectedCh [roundId ]
125
+ s .lock .RLock ()
126
+ defer s .lock .RUnlock ()
127
+ if ch , exists := s .nonceCollectedCh [roundId ]; exists {
128
+ return ch
129
+ }
130
+ return nil
110
131
}
111
132
112
133
func (s * treeSigningSessionsStore ) SignaturesCollected (roundId string ) <- chan struct {} {
113
- return s .sigsCollectedCh [roundId ]
134
+ s .lock .RLock ()
135
+ defer s .lock .RUnlock ()
136
+ if ch , exists := s .sigsCollectedCh [roundId ]; exists {
137
+ return ch
138
+ }
139
+ return nil
114
140
}
0 commit comments