@@ -35,68 +35,66 @@ func (wrapper EpochsHooksWrapper) AfterEpochEnd(
35
35
// TODO:There should be a retry mechanism or compensation mechanism to handle cases of failure
36
36
if len (taskResList ) != 0 {
37
37
groupedTasks := wrapper .keeper .GroupTasksByIDAndAddress (taskResList )
38
- for _ , value := range groupedTasks {
38
+ for key , value := range groupedTasks {
39
+ taskAddr , taskID , err := parseGroupKey (key )
40
+ if err != nil {
41
+ ctx .Logger ().Error ("Failed to parse group key" , "key" , key , "error" , err )
42
+ continue
43
+ }
44
+ avsInfo := wrapper .keeper .GetAVSInfoByTaskAddress (ctx , taskAddr )
45
+ if avsInfo .AvsAddress == "" {
46
+ ctx .Logger ().Error ("Failed to update task result statistics, no AVS address found for task address!" , "task address" , taskAddr , "task id" , taskID )
47
+ continue
48
+ }
49
+ avsAddr := avsInfo .AvsAddress
50
+ taskInfo , err := wrapper .keeper .GetTaskInfo (ctx , strconv .FormatUint (taskID , 10 ), taskAddr )
51
+ if err != nil {
52
+ // Log the error and continue to the next task, and this should be an 'impossible' case, since we retrieved the taskID and taskAddr from the taskResList
53
+ ctx .Logger ().Error ("Failed to update task result statistics, GetTaskInfo call failed!" , "task address" , taskAddr , "task id" , taskID , "error" , err )
54
+ continue
55
+ }
56
+ taskPowerTotal , err := wrapper .keeper .operatorKeeper .GetAVSUSDValue (ctx , avsAddr )
57
+ if err != nil || taskPowerTotal .IsZero () {
58
+ // Log the error and continue to the next task, and this is also an 'impossible' case, since a valid task must have a non-zero total power
59
+ ctx .Logger ().Error ("Failed to update task result statistics, GetAVSUSDValue call failed!" , "avs address" , avsAddr , "error" , err )
60
+ continue
61
+ }
62
+
39
63
var signedOperatorList []string
40
- var taskID uint64
41
- var taskAddr string
42
- var avsAddr string
43
64
var operatorPowers []* types.OperatorActivePowerInfo
44
65
operatorPowerTotal := sdkmath .LegacyZeroDec ()
45
66
for _ , res := range value {
46
67
// Find signed operators
47
68
if res .BlsSignature != nil && res .TaskResponseHash != "" || res .TaskResponse != nil {
48
69
signedOperatorList = append (signedOperatorList , res .OperatorAddress )
49
- if avsAddr == "" {
50
- avsInfo := wrapper .keeper .GetAVSInfoByTaskAddress (ctx , res .TaskContractAddress )
51
- avsAddr = avsInfo .AvsAddress
52
- }
53
- if taskID == 0 {
54
- taskID = res .TaskId
55
- }
56
- if taskAddr == "" {
57
- taskAddr = res .TaskContractAddress
58
- }
59
70
power , err := wrapper .keeper .operatorKeeper .GetOperatorOptedUSDValue (ctx , avsAddr , res .OperatorAddress )
71
+ activePower := sdkmath .LegacyZeroDec ()
60
72
if err != nil || power .ActiveUSDValue .IsNegative () {
61
- ctx .Logger ().Error ("Failed to update task result statistics,GetOperatorOptedUSDValue call failed!" , "task result" , taskAddr , "error" , err )
62
- // Handle the error gracefully, continue to the next
63
- // continue
73
+ // Log the error and and use 0 as the active power for this operator
74
+ ctx .Logger ().Error ("Failed to get optedUSDValue for operator, skip this one" , "operator" , res .OperatorAddress , "avsAddr" , avsAddr , "error" , err )
75
+ } else {
76
+ activePower = power .ActiveUSDValue
64
77
}
65
-
66
78
operatorSelfPower := & types.OperatorActivePowerInfo {
67
79
OperatorAddress : res .OperatorAddress ,
68
- SelfActivePower : power . ActiveUSDValue ,
80
+ SelfActivePower : activePower ,
69
81
}
70
82
operatorPowers = append (operatorPowers , operatorSelfPower )
71
- operatorPowerTotal = operatorPowerTotal .Add (power . ActiveUSDValue )
83
+ operatorPowerTotal = operatorPowerTotal .Add (activePower )
72
84
}
73
85
}
74
- taskInfo , err := wrapper .keeper .GetTaskInfo (ctx , strconv .FormatUint (taskID , 10 ), taskAddr )
75
- if err != nil {
76
- ctx .Logger ().Error ("Failed to update task result statistics,GetTaskInfo call failed!" , "task result" , taskAddr , "error" , err )
77
- // Handle the error gracefully, continue to the next
78
- // continue
79
- }
86
+
80
87
diff := types .Difference (taskInfo .OptInOperators , signedOperatorList )
81
88
taskInfo .SignedOperators = signedOperatorList
82
89
// If a signature is submitted only once, it is counted as NoSignedOperators
83
90
taskInfo .NoSignedOperators = diff
84
91
taskInfo .OperatorActivePower = & types.OperatorActivePowerList {OperatorPowerList : operatorPowers }
85
- // Calculate actual threshold
86
- taskPowerTotal , err := wrapper .keeper .operatorKeeper .GetAVSUSDValue (ctx , avsAddr )
87
92
88
- if err != nil || taskPowerTotal .IsZero () || operatorPowerTotal .IsZero () {
89
- ctx .Logger ().Error ("Failed to update task result statistics,GetAVSUSDValue call failed!" , "task result" , taskAddr , "error" , err )
90
- // Handle the error gracefully, continue to the next
91
- // continue
92
- }
93
93
taskInfo .TaskTotalPower = taskPowerTotal
94
94
// Update the taskInfo in the state
95
95
err = wrapper .keeper .SetTaskInfo (ctx , taskInfo )
96
96
if err != nil {
97
97
ctx .Logger ().Error ("Failed to update task result statistics,SetTaskInfo call failed!" , "task result" , taskAddr , "error" , err )
98
- // Handle the error gracefully, continue to the next
99
- // continue
100
98
}
101
99
}
102
100
}
0 commit comments