8000 x/cellarfees/keeper: remove unnecessary iterations predicated on an AND condition that could be checked immediately that an auction interval occured · Issue #300 · PeggyJV/sommelier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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

Description

@odeke-em

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)
			}
		}
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0