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

chore: rewrite capability to not use sdk.Context #7089

Merged
merged 22 commits into from
Aug 30, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Aug 8, 2024

Description

remove sdk.Context from capability and user kvstore service

when upgrading to 52 we will be able to drop comet as a dep here


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.

Base automatically changed from marko/context-p2 to main August 27, 2024 15:54
memStore.Set(types.KeyMemInitialized, []byte{1})
memStore := k.memService.OpenMemoryStore(noGasCtx)
if err := memStore.Set(types.KeyMemInitialized, []byte{1}); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

capability := types.NewCapability(index)
for _, owner := range owners.Owners {
// Set the forward mapping between the module and capability tuple and the
// capability name in the memKVStore
memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name))
if err := memStore.Set(types.FwdCapabilityKey(owner.Module, capability), []byte(owner.Name)); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

// Set the reverse mapping between the module and capability name and the
// index in the in-memory store. Since marshalling and unmarshalling into a store
// will change memory address of capability, we simply store index as value here
// and retrieve the in-memory pointer to the capability from our map
memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index))
if err := memStore.Set(types.RevCapabilityKey(owner.Module, owner.Name), sdk.Uint64ToBigEndian(index)); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
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.

tried to look into test failures for cap but could nail it down quite yet, will do so again later today

seems like e2e needs some additional tweaks judging from failures 👀

// cache context before trying to distribute fees
cacheCtx, writeFn := ctx.CacheContext()
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove when Upgrading to 52
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering we wont be doing that environment workaround we talked about in call, can open a new issue for bumping to 0.52 and link in similar way. can take care of this.

Copy link
Member Author

@tac0turtle tac0turtle Aug 29, 2024

Choose a reason for hiding this comment

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

#7223 lmk if this is okay

Copy link
Contributor

Choose a reason for hiding this comment

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

beautiful!

modules/capability/capability_test.go Show resolved Hide resolved
modules/core/02-client/keeper/migrations.go Outdated Show resolved Hide resolved
@@ -15,7 +15,7 @@ require (
cosmossdk.io/math v1.3.0
cosmossdk.io/x/upgrade v0.1.4
github.com/cometbft/cometbft v0.38.11
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/cosmos-sdk v0.50.10-0.20240808075341-156231be8aef
Copy link
Contributor

Choose a reason for hiding this comment

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

is this required for the change?

Copy link
Member Author

Choose a reason for hiding this comment

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

yea need a function, we will tag again to get it, to help unblock this

Copy link
Member

Choose a reason for hiding this comment

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

what function was needed that wasn't included in v50.9?

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.

think this lgtm, left comments for the todos which I'll commit now. much thanks again!

modules/apps/29-fee/keeper/escrow.go Outdated Show resolved Hide resolved
modules/apps/29-fee/keeper/events.go Outdated Show resolved Hide resolved
modules/apps/29-fee/keeper/events.go Outdated Show resolved Hide resolved
modules/apps/29-fee/keeper/events.go Outdated Show resolved Hide resolved
modules/core/04-channel/keeper/packet.go Outdated Show resolved Hide resolved
testing/mock/ibc_module.go Outdated Show resolved Hide resolved
testing/mock/ibc_module.go Outdated Show resolved Hide resolved
testing/mock/ibc_module.go Outdated Show resolved Hide resolved
modules/capability/keeper/keeper.go Outdated Show resolved Hide resolved
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.

Thanks again!

Just a note, we will be removing capabilities for v10. #7107

I think its good to just get these changes into main right now tho. We can merge main back into the capability release branch and tag something when needed

@damiannolan damiannolan added this pull request to the merge queue Aug 30, 2024
Copy link

sonarcloud bot commented Aug 30, 2024

memStore := k.memService.OpenMemoryStore(ctx)
isInitialized, err := memStore.Has(types.KeyMemInitialized)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Merged via the queue into main with commit 73369b1 Aug 30, 2024
75 of 77 checks passed
@damiannolan damiannolan deleted the marko/context-capability branch August 30, 2024 10:08
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