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

Fix faulty iterator callsite callback return booleans #447

Merged
merged 5 commits into from
Nov 8, 2022

Conversation

danwt
Copy link
Contributor

@danwt danwt commented Nov 8, 2022

We had some errors in the way we were using iterators.

This PR fixes 5 bugs. I could have easily made a mistake and missed others, as it's a bit error prone.

( Fixes #433 )

Note: based on concerns to minimize diffs I flipped the bools to fix the issues. Really we need a larger change to match the SDK pattern. Please see here #440 for discussion of a larger solution where we'd change our iterators to match the SDK style.

This could have been avoided with better guidelines about var naming IMO.

Copy link
Contributor

@sainoe sainoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix @danwt!

Copy link
Contributor

@mpoke mpoke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @danwt.

@@ -140,7 +140,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt
ValidatorConsensusAddress: addr,
}
outstandingDowntimes = append(outstandingDowntimes, od)
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments describing the intended outcome, e.g., continue iterating. It will make it easier to change afterwards to the SDK pattern.

@@ -43,7 +43,7 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu
ChainId: chainID,
ClientId: clientID,
})
return false
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until a better fix, change the return field from stop to continue, i.e.,

func (k Keeper) IterateConsumerChains(ctx sdk.Context, cb func(ctx sdk.Context, chainID, clientID string) (continue bool)) {

@@ -354,7 +354,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) {
return false
})
// continue to iterate through all consumers
return true
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: IterateChannelToChain change stop to continue

@danwt danwt merged commit d9a002f into main Nov 8, 2022
@danwt danwt deleted the danwt/fix-faulty-iterators branch November 8, 2022 13:52
@danwt
Copy link
Contributor Author

danwt commented Nov 8, 2022

I merged to get the fix in as changing the stop words to continue is going to touch several places and go against the small diff spirit. pastebin

New issue

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

Successfully merging this pull request may close these issues.

Fix early returning iterator
3 participants