@@ -139,10 +139,6 @@ func (k Keeper) DeleteConsumerRewardsAllocationByDenom(ctx sdk.Context, consumer
139
139
140
140
// AllocateConsumerRewards allocates the given rewards to provider consumer chain with the given consumer id
141
141
func (k Keeper ) AllocateConsumerRewards (ctx sdk.Context , consumerId string , alloc types.ConsumerRewardsAllocation ) (types.ConsumerRewardsAllocation , error ) {
142
- if alloc .Rewards .IsZero () {
143
- return types.ConsumerRewardsAllocation {}, nil
144
- }
145
-
146
142
chainId , err := k .GetConsumerChainId (ctx , consumerId )
147
143
if err != nil {
148
144
k .Logger (ctx ).Error (
@@ -271,7 +267,6 @@ func (k Keeper) AllocateConsumerRewards(ctx sdk.Context, consumerId string, allo
271
267
// AllocateTokens performs rewards distribution to the community pool and validators
272
268
// based on the Partial Set Security distribution specification.
273
269
func (k Keeper ) AllocateTokens (ctx sdk.Context ) {
274
-
275
270
// Iterate over all launched consumer chains.
276
271
// To avoid large iterations over all the consumer IDs, iterate only over
277
272
// chains with an IBC client created.
@@ -302,7 +297,12 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
302
297
)
303
298
continue
304
299
}
305
- remainingRewardDec , err := k .AllocateConsumerRewards (cachedCtx , consumerId , consumerRewards )
300
+ if consumerRewards .Rewards .IsZero () {
301
+ // note that GetConsumerRewardsAllocationByDenom returns an empty ConsumerRewardsAllocation
302
+ // when there is no (consumerId, denom) key for consumer rewards allocations
303
+ continue
304
+ }
305
+ remainingRewardAllocation , err := k .AllocateConsumerRewards (cachedCtx , consumerId , consumerRewards )
306
306
if err != nil {
307
307
k .Logger (ctx ).Error (
308
308
"fail to allocate rewards for consumer chain" ,
@@ -312,14 +312,20 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
312
312
continue
313
313
}
314
314
315
- err = k .SetConsumerRewardsAllocationByDenom (cachedCtx , consumerId , denom , remainingRewardDec )
316
- if err != nil {
317
- k .Logger (ctx ).Error (
318
- "fail to set rewards for consumer chain" ,
319
- "consumer id" , consumerId ,
320
- "error" , err .Error (),
321
- )
322
- continue
315
+ if remainingRewardAllocation .Rewards .IsZero () {
316
+ // if there is no remaining consumer rewards allocation, then just delete the (consumerId, denom) key
317
+ k .DeleteConsumerRewardsAllocationByDenom (cachedCtx , consumerId , denom )
318
+ } else {
319
+ // otherwise, update the consumer rewards allocation
320
+ err = k .SetConsumerRewardsAllocationByDenom (cachedCtx , consumerId , denom , remainingRewardAllocation )
321
+ if err != nil {
322
+ k .Logger (ctx ).Error (
323
+ "fail to set rewards for consumer chain" ,
324
+ "consumer id" , consumerId ,
325
+ "error" , err .Error (),
326
+ )
327
+ continue
328
+ }
323
329
}
324
330
325
331
writeCache ()
0 commit comments