Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/cellarfees/keeper: remove unnecessary iterations predicated on an AND condition that could be checked immediately that an auction interval occured #300

Open
odeke-em opened this issue Mar 15, 2024 · 0 comments

Comments

@odeke-em
Copy link

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)
			}
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant