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/axelarcork/keeper, x/cork/keeper: HandleRemoveManagedCellarsProposal should bail out immediately found=true to avoid needless/wasted iterations #299

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

Comments

@odeke-em
Copy link

odeke-em commented Mar 15, 2024

Summary of Bug

The loops here

for _, inputID := range p.CellarIds.Ids {
if existingID == common.HexToAddress(inputID) {
found = true
}
}
if !found {
outputCellarIDs.Ids = append(outputCellarIDs.Ids, existingID.String())
}

and

for _, proposedCellarID := range p.CellarIds.Ids {
proposedCellarAddress := common.HexToAddress(proposedCellarID)
found := false
for _, id := range cellarAddresses {
if id == proposedCellarAddress {
found = true
}

iterate looking for a specific target but once it has found it just keeps iterating and comparing over all all the cellar ids and at no point do we modify found=false in the loop. If we notice down below, we only append to the slice if !found hence we really should just end that loop immediately to avoid needless CPU cycles being wasted

Suggestion

 for _, inputID := range p.CellarIds.Ids { 
 	if existingID == common.HexToAddress(inputID) { 
 		found = true // We found the existing inputID
                 break
 	} 
 } 
  
 if !found { 
 	outputCellarIDs.Ids = append(outputCellarIDs.Ids, existingID.String()) 
 } 
@odeke-em odeke-em changed the title x/cork/keeper: HandleRemoveManagedCellarsProposal should bail out immediately found=true to avoid needless/wasted iterations x/axelarcork/keeper, x/cork/keeper: HandleRemoveManagedCellarsProposal should bail out immediately found=true to avoid needless/wasted iterations Mar 15, 2024
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