Summary of Bug
If we look at this code
|
modulus := ctx.BlockHeader().Height % int64(cellarfeesParams.AuctionInterval) |
|
|
|
for _, counter := range counters.Counters { |
|
|
|
if counter.Count >= cellarfeesParams.FeeAccrualAuctionThreshold && modulus == 0 { |
|
started := k.beginAuction(ctx, counter.Denom) |
|
if started { |
|
counters.ResetCounter(counter.Denom) |
|
} |
|
} |
we see that in the condition to reset the counters, modulus MUST BE == 0!
This means that if modulus != 0
regardless of how many times that we iterate, we can't be performing a counter reset and this means that that loop is needlessly burning CPU cycles whenever it isn't an auction interval
Suggestion
Simply firstly check that the auction interval occured and even better rename to a much better variable so
atAuctionInterval := (ctx.BlockHeader().Height % int64(cellarfeesParams.AuctionInterval)) == 0
if atAuctionInterval {
for _, counter := range counters.Counters {
if counter.Count < cellarfeesParams.FeeAccrualAuctionThreshold {
continue
}
if k.beginAuction(ctx, counter.Denom) {
counters.ResetCounter(counter.Denom)
}
}
}