@@ -110,7 +110,6 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
110
110
err = cmdUtils .StoreBountyId (client , account )
111
111
if err != nil {
112
112
log .Error (err )
113
- break
114
113
}
115
114
continue
116
115
}
@@ -124,6 +123,7 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
124
123
idDisputeTxn , err := cmdUtils .CheckDisputeForIds (client , transactionOptions , epoch , uint8 (blockIndex ), proposedBlock .Ids , revealedCollectionIds )
125
124
if err != nil {
126
125
log .Error ("Error in disputing: " , err )
126
+ continue
127
127
}
128
128
if idDisputeTxn != nil {
129
129
idDisputeTxnHash := transactionUtils .Hash (idDisputeTxn )
@@ -136,7 +136,6 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
136
136
err = cmdUtils .StoreBountyId (client , account )
137
137
if err != nil {
138
138
log .Error (err )
139
- break
140
139
}
141
140
continue
142
141
}
@@ -153,6 +152,11 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
153
152
// ids [1, 2, 3, 4]
154
153
// Sorted revealed values would be the vote values for the wrong median, here 230
155
154
log .Debug ("HandleDispute: Mismatch index while iterating: " , mismatchIndex )
155
+ if mismatchIndex < 0 || mismatchIndex >= len (proposedBlock .Ids ) {
156
+ log .Error ("Mismatch index is out of bounds, cannot continue dispute for medians" )
157
+ continue
158
+ }
159
+
156
160
collectionIdOfWrongMedian := proposedBlock .Ids [mismatchIndex ]
157
161
log .Debug ("HandleDispute: Collection Id of wrong median: " , collectionIdOfWrongMedian )
158
162
@@ -190,65 +194,63 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
190
194
191
195
//This function returns the local median data
192
196
func (* UtilsStruct ) GetLocalMediansData (client * ethclient.Client , account types.Account , epoch uint32 , blockNumber * big.Int , rogueData types.Rogue ) (types.ProposeFileData , error ) {
193
- if (globalProposedDataStruct .MediansData == nil && ! rogueData .IsRogue ) || epoch != globalProposedDataStruct .Epoch {
197
+ if rogueData .IsRogue {
198
+ // As the staker has proposed with incorrect medians in rogue mode so those values needs to be compared with the correct calculated medians
199
+ log .Debug ("Staker proposed in rogue mode, now calculating medians correctly..." )
200
+ return calculateMedian (client , account , epoch , blockNumber )
201
+ }
202
+
203
+ // Fetching the data from file only if the node is not in rogue mode and
204
+ // the proposed data in memory is nil or epoch in propose data from memory doesn't match with current epoch
205
+ nilProposedData := globalProposedDataStruct .MediansData == nil || globalProposedDataStruct .RevealedDataMaps == nil || globalProposedDataStruct .RevealedCollectionIds == nil
206
+ if nilProposedData || epoch != globalProposedDataStruct .Epoch {
194
207
log .Debug ("Global propose data struct is not updated, getting the proposed data from file..." )
195
208
fileName , err := pathUtils .GetProposeDataFileName (account .Address )
196
209
if err != nil {
197
210
log .Error ("Error in getting file name to read median data: " , err )
198
- goto CalculateMedian
211
+ return calculateMedian ( client , account , epoch , blockNumber )
199
212
}
200
213
log .Debug ("GetLocalMediansData: Propose data file path: " , fileName )
201
214
proposedData , err := fileUtils .ReadFromProposeJsonFile (fileName )
202
215
if err != nil {
203
216
log .Errorf ("Error in getting propose data from file %s: %v" , fileName , err )
204
- goto CalculateMedian
217
+ return calculateMedian ( client , account , epoch , blockNumber )
205
218
}
206
219
log .Debugf ("GetLocalMediansData: Proposed data from file: %+v" , proposedData )
207
220
if proposedData .Epoch != epoch {
208
221
log .Errorf ("File %s doesn't contain latest median data" , fileName )
209
- goto CalculateMedian
222
+ return calculateMedian ( client , account , epoch , blockNumber )
210
223
}
211
- log .Debug ("Updating global proposed data struct..." )
212
- updateGlobalProposedDataStruct (proposedData )
213
- log .Debugf ("GetLocalMediansData: Global proposed data struct: %+v" , globalProposedDataStruct )
224
+ return proposedData , err
214
225
}
215
- CalculateMedian:
226
+
227
+ return globalProposedDataStruct , nil
228
+ }
229
+
230
+ func calculateMedian (client * ethclient.Client , account types.Account , epoch uint32 , blockNumber * big.Int ) (types.ProposeFileData , error ) {
216
231
stakerId , err := razorUtils .GetStakerId (client , account .Address )
217
232
if err != nil {
218
233
log .Error ("Error in getting stakerId: " , err )
219
234
return types.ProposeFileData {}, err
220
235
}
221
236
log .Debug ("GetLocalMediansData: Staker Id: " , stakerId )
222
- lastProposedEpoch , err := razorUtils .GetEpochLastProposed (client , stakerId )
237
+
238
+ log .Debug ("Calculating the medians data again..." )
239
+ log .Debugf ("GetLocalMediansData: Calling MakeBlock() with arguments blockNumber = %s, epoch = %d, rogueData = %+v" , blockNumber , epoch , types.Rogue {IsRogue : false })
240
+ medians , revealedCollectionIds , revealedDataMaps , err := cmdUtils .MakeBlock (client , blockNumber , epoch , types.Rogue {IsRogue : false })
223
241
if err != nil {
224
- log .Error ("Error in getting last proposed epoch : " , err )
242
+ log .Error ("Error in calculating block medians : " , err )
225
243
return types.ProposeFileData {}, err
226
244
}
227
- log .Debug ("GetLocalMediansData: Last proposed epoch: " , lastProposedEpoch )
228
-
229
- nilProposedData := globalProposedDataStruct .MediansData == nil || globalProposedDataStruct .RevealedDataMaps == nil || globalProposedDataStruct .RevealedCollectionIds == nil
230
- epochCheck := epoch != lastProposedEpoch
231
-
232
- if nilProposedData || rogueData .IsRogue || epochCheck {
233
- log .Debug ("Calculating the medians data again..." )
234
- log .Debugf ("GetLocalMediansData: Calling MakeBlock() with arguments blockNumber = %s, epoch = %d, rogueData = %+v" , blockNumber , epoch , types.Rogue {IsRogue : false })
235
- medians , revealedCollectionIds , revealedDataMaps , err := cmdUtils .MakeBlock (client , blockNumber , epoch , types.Rogue {IsRogue : false })
236
- if err != nil {
237
- log .Error ("Error in calculating block medians" )
238
- return types.ProposeFileData {}, err
239
- }
240
- log .Debug ("Updating global proposed data struct..." )
241
- updateGlobalProposedDataStruct (types.ProposeFileData {
242
- MediansData : medians ,
243
- RevealedCollectionIds : revealedCollectionIds ,
244
- RevealedDataMaps : revealedDataMaps ,
245
- Epoch : epoch ,
246
- })
247
- log .Debugf ("GetLocalMediansData: Global proposed data struct: %+v" , globalProposedDataStruct )
245
+ calculatedProposedData := types.ProposeFileData {
246
+ MediansData : medians ,
247
+ RevealedCollectionIds : revealedCollectionIds ,
248
+ RevealedDataMaps : revealedDataMaps ,
249
+ Epoch : epoch ,
248
250
}
249
251
250
- log .Debugf ("Locally calculated data, Medians: %s" , globalProposedDataStruct .MediansData )
251
- return globalProposedDataStruct , nil
252
+ log .Debugf ("Locally calculated data, Medians: %s" , calculatedProposedData .MediansData )
253
+ return calculatedProposedData , nil
252
254
}
253
255
254
256
//This function check for the dispute in different type of Id's
0 commit comments