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

refactor: migrate from sdk.Context to Context.Context (2/n) #7081

Merged
merged 16 commits into from
Aug 27, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Aug 7, 2024

Description

second pr of migrating the repository to use context in public apis

ref: #5917

Example commit messages:

fix: skip emission of unpopulated memo field in ics20
deps: updating sdk to v0.46.4
chore: removed unused variables
e2e: adding e2e upgrade test for ibc-go/v6
docs: ics27 v6 documentation updates
feat: add semantic version utilities for e2e tests
feat(api)!: this is an api breaking feature
fix(statemachine)!: this is a statemachine breaking fix
-->


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@tac0turtle tac0turtle changed the title p2 refactor: migrate from sdk.Context to Context.Context (2/n) Aug 7, 2024
Base automatically changed from marko/context-p1 to main August 26, 2024 15:01
@tac0turtle
Copy link
Member Author

opening for preliminary review as i make sure tests are passing

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Nice one, diffs look good. Left a few nits, myself and @DimitrisJim can address them.

Looks like there is a couple of failing tests in ICA which we'll have to look into before merging

Comment on lines 149 to 155
bz, err := store.Get(key)
if len(bz) == 0 {
return "", false
}
if err != nil {
panic(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

error handling and panic before len(bz) check?

Copy link
Member Author

Choose a reason for hiding this comment

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

moved it as the logic was wrong above


return string(store.Get(key)), true
return string(bz), true // todo: why the cast?
Copy link
Member

Choose a reason for hiding this comment

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

value is stored as []byte(channelID) where channelID is string

Comment on lines 233 to 239
bz, err := store.Get(key)
if len(bz) == 0 {
return "", false
}
if err != nil {
panic(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto


return string(store.Get(key)), true
return string(bz), true // todo: why the cast?
Copy link
Member

Choose a reason for hiding this comment

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

address value is stored as string... similar reasoning to the ics29 question you had on counterparty address, could store address bytes but string is more human readable

Comment on lines 166 to 179
has, err := store.Has(key)
if err != nil {
panic(err)
}
if !has {
return "", false
}

return string(store.Get(key)), true
bz, err := store.Get(key)
if err != nil {
panic(err)
}

return string(bz), true
Copy link
Member

Choose a reason for hiding this comment

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

I think we can optimise this for gas consumption similarly to one or two funcs on the other PR. cc @DimitrisJim

Comment on lines +239 to +245
bz, err := store.Get(key)
if len(bz) == 0 {
return "", false
}
if err != nil {
panic(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

modules/core/02-client/keeper/migrations.go Outdated Show resolved Hide resolved
Comment on lines +297 to +304
channelID := channeltypes.FormatChannelIdentifier(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextChannelSequence(suite.chainA.GetContext()))
path.EndpointA.ChannelID = channelID

tc.malleate() // malleate mutates test data

chanCap, err = suite.chainA.App.GetScopedIBCKeeper().NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
suite.Require().NoError(err)

Copy link
Member

Choose a reason for hiding this comment

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

I find it weird that I had to do this to fix failing tests here given the diffs, I can try to provide more info later, need more reasoning on it

Copy link
Member

@damiannolan damiannolan Aug 27, 2024

Choose a reason for hiding this comment

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

Let me try to explain this a little further.

The channel capability is generated in 04-channel (core IBC) and passed to application callback handlers (e.g. like this one under test - ica OnChanOpenInit).
This test calls keeper.OnChanOpenInit directly, rather than delivering a msg e2e, testing core integration points with the app - thus, the capability is generated directly in the test code here and passed to app callback.

From what I can see, this test as it existed, was creating a new capability with an empty channel ID. This is because the path.EndpointA.ChannelID field is not actually fulfilled here until after the INIT step of the handshake.

In the diffs, I get the next channel sequence nonce (monotonically increasing) and format a new channel ID with it. Then use that to create the new capability before invoking the app callbacks directly on the keeper.
It's moved under the call to tc.malleate() as some test cases create a channel and set it to closed, in order to test regaining control of an interchain account on a closed channel, i.e. without moving it we fix some tests, and cause failures in others surfaced from capability already being claimed for a particular channelID.

Hope that makes sense!

I'm still curious why this has only popped up now, and previously passed 👀

Copy link
Member

Choose a reason for hiding this comment

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

The changes which caused the test failures to be raised in this PR are from GetActiveChannelID which previously allowed storing an empty string and have it being treated as a "found" or "truthy" value.

e.g. in testcase failure: different ordering from previous channel, there is a call to SetActiveChannelID in the malleate() func. It's actually setting an empty channel id as the active channel id on main, while store.Has() treats it as true.

Copy link

sonarcloud bot commented Aug 27, 2024

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @tac0turtle, and @DimitrisJim for fixing the other test!

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

big thanks once again! Also thanks on quick failure debugging @damiannolan!

@DimitrisJim DimitrisJim added this pull request to the merge queue Aug 27, 2024
Merged via the queue into main with commit 30371fa Aug 27, 2024
69 checks passed
@DimitrisJim DimitrisJim deleted the marko/context-p2 branch August 27, 2024 15:54
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.

3 participants