@@ -58,18 +58,18 @@ func (k Keeper) ProcessTallies(ctx sdk.Context) error {
58
58
59
59
// Loop through the list to apply filter, execute tally, and post
60
60
// execution result.
61
- tallyResults := make ([] TallyResult , tallyLen )
62
- dataResults := make ([] batchingtypes.DataResult , tallyLen )
61
+ var tallyResult TallyResult
62
+ var dataResult batchingtypes.DataResult
63
63
64
- for i , id := range drIDs {
64
+ for _ , id := range drIDs {
65
65
dr , err := k .GetDataRequest (ctx , id )
66
66
if err != nil {
67
67
telemetry .SetGauge (1 , types .TelemetryKeyDRFlowHalt )
68
68
k .Logger (ctx ).Error ("[HALTS_DR_FLOW] failed to retrieve data request" , "err" , err )
69
69
return nil
70
70
}
71
71
72
- dataResults [ i ] = batchingtypes.DataResult {
72
+ dataResult = batchingtypes.DataResult {
73
73
DrId : dr .Id ,
74
74
//nolint:gosec // G115: Block height is never negative.
75
75
DrBlockHeight : uint64 (dr .PostedHeight ),
@@ -92,19 +92,19 @@ func (k Keeper) ProcessTallies(ctx sdk.Context) error {
92
92
gasMeter := types .NewGasMeter (dr .TallyGasLimit , dr .ExecGasLimit , tallyConfig .MaxTallyGasLimit , dr .PostedGasPrice , tallyConfig .GasCostBase )
93
93
94
94
if len (dr .Commits ) < int (dr .ReplicationFactor ) {
95
- dataResults [ i ] .Result = []byte (fmt .Sprintf ("need %d commits; received %d" , dr .ReplicationFactor , len (dr .Commits )))
96
- dataResults [ i ] .ExitCode = types .TallyExitCodeNotEnoughCommits
95
+ dataResult .Result = []byte (fmt .Sprintf ("need %d commits; received %d" , dr .ReplicationFactor , len (dr .Commits )))
96
+ dataResult .ExitCode = types .TallyExitCodeNotEnoughCommits
97
97
k .Logger (ctx ).Info ("data request's number of commits did not meet replication factor" , "request_id" , dr .Id )
98
98
99
99
MeterExecutorGasFallback (dr , tallyConfig .ExecutionGasCostFallback , gasMeter )
100
100
} else {
101
- _ , tallyResults [ i ] = k .FilterAndTally (ctx , dr , tallyConfig , gasMeter )
102
- dataResults [ i ] .Result = tallyResults [ i ] .Result
103
- dataResults [ i ] .ExitCode = tallyResults [ i ] .ExitCode
104
- dataResults [ i ] .Consensus = tallyResults [ i ] .Consensus
101
+ _ , tallyResult = k .FilterAndTally (ctx , dr , tallyConfig , gasMeter )
102
+ dataResult .Result = tallyResult .Result
103
+ dataResult .ExitCode = tallyResult .ExitCode
104
+ dataResult .Consensus = tallyResult .Consensus
105
105
106
106
k .Logger (ctx ).Info ("completed tally" , "request_id" , dr .Id )
107
- k .Logger (ctx ).Debug ("tally result" , "request_id" , dr .Id , "tally_result" , tallyResults [ i ] )
107
+ k .Logger (ctx ).Debug ("tally result" , "request_id" , dr .Id , "tally_result" , tallyResult )
108
108
}
109
109
110
110
distributions := k .GetGasMeterResults (ctx , gasMeter , dr .Id , dr .PostedHeight , tallyConfig .BurnRatio )
@@ -128,35 +128,33 @@ func (k Keeper) ProcessTallies(ctx sdk.Context) error {
128
128
return err
129
129
}
130
130
131
- dataResults [ i ] .GasUsed = gasMeter .TotalGasUsed ()
132
- dataResults [ i ] .Id , err = dataResults [ i ] .TryHash ()
131
+ dataResult .GasUsed = gasMeter .TotalGasUsed ()
132
+ dataResult .Id , err = dataResult .TryHash ()
133
133
if err != nil {
134
134
return err
135
135
}
136
- }
137
136
138
- // Store the data results for batching.
139
- for i := range dataResults {
140
- err := k .batchingKeeper .SetDataResultForBatching (ctx , dataResults [i ])
137
+ // Store the data results for batching.
138
+ err = k .batchingKeeper .SetDataResultForBatching (ctx , dataResult )
141
139
// If writing to the store fails we should stop the node to prevent acting on invalid state.
142
140
if err != nil {
143
141
k .Logger (ctx ).Error ("failed to store data result for batching" , "err" , err )
144
142
return err
145
143
}
146
144
147
- k .Logger (ctx ).Info ("tally flow completed" , "request_id" , dataResults [ i ] .DrId )
145
+ k .Logger (ctx ).Info ("tally flow completed" , "request_id" , dataResult .DrId )
148
146
ctx .EventManager ().EmitEvent (
149
147
sdk .NewEvent (
150
148
types .EventTypeTallyCompletion ,
151
- sdk .NewAttribute (types .AttributeDataResultID , dataResults [ i ] .Id ),
152
- sdk .NewAttribute (types .AttributeDataRequestID , dataResults [ i ] .DrId ),
153
- sdk .NewAttribute (types .AttributeTypeConsensus , strconv .FormatBool (dataResults [ i ] .Consensus )),
154
- sdk .NewAttribute (types .AttributeTallyVMStdOut , strings .Join (tallyResults [ i ] .StdOut , "\n " )),
155
- sdk .NewAttribute (types .AttributeTallyVMStdErr , strings .Join (tallyResults [ i ] .StdErr , "\n " )),
156
- sdk .NewAttribute (types .AttributeExecGasUsed , fmt .Sprintf ("%v" , tallyResults [ i ] .ExecGasUsed )),
157
- sdk .NewAttribute (types .AttributeTallyGasUsed , fmt .Sprintf ("%v" , tallyResults [ i ] .TallyGasUsed )),
158
- sdk .NewAttribute (types .AttributeTallyExitCode , fmt .Sprintf ("%02x" , dataResults [ i ] .ExitCode )),
159
- sdk .NewAttribute (types .AttributeProxyPubKeys , strings .Join (tallyResults [ i ] .ProxyPubKeys , "\n " )),
149
+ sdk .NewAttribute (types .AttributeDataResultID , dataResult .Id ),
150
+ sdk .NewAttribute (types .AttributeDataRequestID , dataResult .DrId ),
151
+ sdk .NewAttribute (types .AttributeTypeConsensus , strconv .FormatBool (dataResult .Consensus )),
152
+ sdk .NewAttribute (types .AttributeTallyVMStdOut , strings .Join (tallyResult .StdOut , "\n " )),
153
+ sdk .NewAttribute (types .AttributeTallyVMStdErr , strings .Join (tallyResult .StdErr , "\n " )),
154
+ sdk .NewAttribute (types .AttributeExecGasUsed , fmt .Sprintf ("%v" , tallyResult .ExecGasUsed )),
155
+ sdk .NewAttribute (types .AttributeTallyGasUsed , fmt .Sprintf ("%v" , tallyResult .TallyGasUsed )),
156
+ sdk .NewAttribute (types .AttributeTallyExitCode , fmt .Sprintf ("%02x" , dataResult .ExitCode )),
157
+ sdk .NewAttribute (types .AttributeProxyPubKeys , strings .Join (tallyResult .ProxyPubKeys , "\n " )),
160
158
),
161
159
)
162
160
}
0 commit comments