@@ -123,6 +123,8 @@ func (x *XDPoS_v2) verifyTC(chain consensus.ChainReader, timeoutCert *types.Time
123
123
124
124
var wg sync.WaitGroup
125
125
wg .Add (len (signatures ))
126
+
127
+ var mutex sync.Mutex
126
128
var haveError error
127
129
128
130
signedTimeoutObj := types .TimeoutSigHash (& types.TimeoutForSign {
@@ -134,15 +136,19 @@ func (x *XDPoS_v2) verifyTC(chain consensus.ChainReader, timeoutCert *types.Time
134
136
go func (sig types.Signature ) {
135
137
defer wg .Done ()
136
138
verified , _ , err := x .verifyMsgSignature (signedTimeoutObj , sig , snap .NextEpochMasterNodes )
137
- if err != nil {
138
- log .Error ("[verifyTC] Error while verfying TC message signatures" , "timeoutCert.Round" , timeoutCert .Round , "timeoutCert.GapNumber" , timeoutCert .GapNumber , "Signatures len" , len (signatures ), "Error" , err )
139
- haveError = fmt .Errorf ("error while verfying TC message signatures, %s" , err )
140
- return
141
- }
142
- if ! verified {
143
- log .Warn ("[verifyTC] Signature not verified doing TC verification" , "timeoutCert.Round" , timeoutCert .Round , "timeoutCert.GapNumber" , timeoutCert .GapNumber , "Signatures len" , len (signatures ))
144
- haveError = fmt .Errorf ("fail to verify TC due to signature mis-match" )
145
- return
139
+ if err != nil || ! verified {
140
+ log .Error ("[verifyTC] Error or verification failure" , "Signature" , sig , "Error" , err )
141
+ mutex .Lock () // Lock before accessing haveError
142
+ if haveError == nil {
143
+ if err != nil {
144
+ log .Error ("[verifyTC] Error while verfying TC message signatures" , "timeoutCert.Round" , timeoutCert .Round , "timeoutCert.GapNumber" , timeoutCert .GapNumber , "Signatures len" , len (signatures ), "Error" , err )
145
+ haveError = fmt .Errorf ("error while verifying TC message signatures, %s" , err )
146
+ } else {
147
+ log .Warn ("[verifyTC] Signature not verified doing TC verification" , "timeoutCert.Round" , timeoutCert .Round , "timeoutCert.GapNumber" , timeoutCert .GapNumber , "Signatures len" , len (signatures ))
148
+ haveError = fmt .Errorf ("fail to verify TC due to signature mis-match" )
149
+ }
150
+ }
151
+ mutex .Unlock () // Unlock after modifying haveError
146
152
}
147
153
}(signature )
148
154
}
0 commit comments