@@ -17,7 +17,7 @@ import (
17
17
)
18
18
19
19
const (
20
- defaultSyncInterval = 10
20
+ defaultSyncInterval = 10 * time . Second
21
21
)
22
22
23
23
type SignerAddressL1 struct {
@@ -155,18 +155,46 @@ func (s *SystemContract) Start() {
155
155
case <- s .ctx .Done ():
156
156
return
157
157
case <- syncTicker .C :
158
- s . lock . Lock ()
159
- signers , err := s .fetchAllSigners (nil ) // nil -> latest state
158
+ // Fetch the latest signers from L1 outside of the lock
159
+ newSigners , err := s .fetchAllSigners (nil )
160
160
if err != nil {
161
- log .Error ("failed to get signer address from L1 System Contract" , "err" , err )
161
+ log .Error ("failed to fetch signer addresses from L1 System Contract" , "err" , err )
162
+ continue
163
+ }
164
+
165
+ // Optionally, compare with the currently stored signers first.
166
+ s .lock .RLock ()
167
+ currentSigners := s .signerAddressesL1
168
+ s .lock .RUnlock ()
169
+ if ! signersChanged (currentSigners , newSigners ) {
170
+ // No change—no need to reacquire the write lock.
171
+ continue
162
172
}
163
- s .signerAddressesL1 = signers
173
+
174
+ s .lock .Lock ()
175
+ s .signerAddressesL1 = newSigners
164
176
s .lock .Unlock ()
177
+ log .Info ("Refreshed signer addresses" , "count" , len (newSigners ))
165
178
}
166
179
}
167
180
}()
168
181
}
169
182
183
+ // signersChanged compares two slices of SignerAddressL1 and returns true if they differ.
184
+ // For simplicity, we compare lengths and each element in order.
185
+ func signersChanged (current , new []SignerAddressL1 ) bool {
186
+ if len (current ) != len (new ) {
187
+ return true
188
+ }
189
+ for i , cs := range current {
190
+ ns := new [i ]
191
+ if cs .StartBlock != ns .StartBlock || cs .Signer != ns .Signer {
192
+ return true
193
+ }
194
+ }
195
+ return false
196
+ }
197
+
170
198
// Close implements consensus.Engine.
171
199
func (s * SystemContract ) Close () error {
172
200
s .cancel ()
0 commit comments