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

deps: upgrade capability to sdk v0.50 and remove ibc-go dependency #4068

Merged
merged 8 commits into from
Jul 13, 2023

Conversation

damiannolan
Copy link
Member

Description

This PR upgrades the capability module to sdk v0.50 eden release.
It removes the dependency on ibc-go testing/simapp and refactors the tests of interest to not depend on a simulation app.
Instead it uses a test a context and in-memory db in order to accomplish the same level of testing provided by simapp.

Note, I have tried to clean up and add inline code comments to capability_test.go to make it easier to understand.

closes: #4055


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 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/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Copy link
Member Author

@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.

Added some context for review. More testcases could be cleaned up but I left as is to reduce diffs. The main one of concern was TestInitializeMemstore which I've cleaned up

Comment on lines +13 to +14
// InitGenesis must be called in order to set the intial index to 1.
capability.InitGenesis(suite.ctx, *suite.keeper, *types.DefaultGenesis())
Copy link
Member Author

Choose a reason for hiding this comment

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

InitGenesis has to be called directly here in order to set the initial capability index to 1.

This used to be happening handled implicitly when testing with a simapp. This caught me off guard for a while as after removing simapp this test would fail below when trying to lookup the first capability after genesis is reinitialised.

The reasoning for this is that without setting the initial index to 1 - cap1 created on line 19 would be at index 0, and ExportGenesis starts the loop index here at 1. So after exporting and then reinitialising the gen state we'd lose first capabiliity.

suite.keeper = keeper
suite.cdc = cdc
suite.module = capability.NewAppModule(cdc, *keeper, false)
encodingCfg := moduletestutil.MakeTestEncodingConfig(capability.AppModuleBasic{})
Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty nice way to create a test encoding config 👍

Comment on lines +53 to 64
func (suite *CapabilityTestSuite) NewTestContext() sdk.Context {
db := dbm.NewMemDB()
cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
cms.MountStoreWithDB(suite.storeKey, storetypes.StoreTypeIAVL, db)
cms.MountStoreWithDB(suite.memStoreKey, storetypes.StoreTypeMemory, db)
cms.MountStoreWithDB(suite.mockMemStoreKey, storetypes.StoreTypeMemory, db)

err := cms.LoadLatestVersion()
suite.Require().NoError(err)

return sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger())
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been adapted from here.

I'm unsure why the test helpers in the sdk do not support adding mem store keys, or even mounting multiple keys (I guess nobody has run into an issue with the current code yet).

I was going to make a PR to the sdk to add some extra support for this, but I felt it was cleaner and quicker to adapt it and maintain it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

}

// The following test case mocks a specific bug discovered in https://github.com/cosmos/cosmos-sdk/issues/9800
// and ensures that the current code successfully fixes the issue.
// This test emulates statesync by firstly populating persisted state by creating a new scoped keeper and capability.
// In-memory storage is then discarded by creating a new capability keeper and app module using a mock memstore key.
// BeginBlock is then called to populate the new in-memory store using the persisted state.
func (suite *CapabilityTestSuite) TestInitializeMemStore() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I spent a good bit of time trying to parse this testcase. So I've added a bunch of in-line comments as well as extra info to the godoc above. This was initially added by @AdityaSripal in cosmos/cosmos-sdk#9835 but has since seen a whole bunch of devs chopping into the code.

Hopefully its now clear what its doing and is easier to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for this!

Comment on lines +94 to -69
prevGas := ctx.GasMeter().GasConsumed()
prevBlockGas := ctx.BlockGasMeter().GasConsumed()
prevGas := ctx.BlockGasMeter().GasConsumed()
Copy link
Member Author

Choose a reason for hiding this comment

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

prevGas here was incorrect, it was being set to the same value as prevBlockGas

@crodriguezvega
Copy link
Contributor

Thank you so much for handling the upgrade of the capability module, @damiannolan. This PR will supersede #3978, right? So that one can be closed?

@damiannolan
Copy link
Member Author

Thank you so much for handling the upgrade of the capability module, @damiannolan. This PR will supersede #3978, right? So that one can be closed?

Yep, indeed we can close #3978

@damiannolan damiannolan added the capability Issues for capability modules label Jul 12, 2023
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM nice investigation ❤️

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Damn, excellent work! This is a pretty epic pr if I have ever seen one 🔥

}

// The following test case mocks a specific bug discovered in https://github.com/cosmos/cosmos-sdk/issues/9800
// and ensures that the current code successfully fixes the issue.
// This test emulates statesync by firstly populating persisted state by creating a new scoped keeper and capability.
// In-memory storage is then discarded by creating a new capability keeper and app module using a mock memstore key.
// BeginBlock is then called to populate the new in-memory store using the persisted state.
func (suite *CapabilityTestSuite) TestInitializeMemStore() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for this!

modules/capability/capability_test.go Outdated Show resolved Hide resolved
@damiannolan damiannolan merged commit 49cdfc5 into main Jul 13, 2023
@damiannolan damiannolan deleted the damian/capability-upgrade branch July 13, 2023 18:13
@damiannolan
Copy link
Member Author

damiannolan commented Jul 13, 2023

cc @faddat 👀

should be able to pick this up in #3883 using a replace directive with a local pin if you sync the latest from main, will also tag this soon and then we can move to that!

edit: tagged @ modules/capability/v1.0.0-rc2 https://github.com/cosmos/ibc-go/tree/modules/capability/v1.0.0-rc2

mergify bot pushed a commit that referenced this pull request Jul 14, 2023
…4068)

* adding testing/simapp dir for testing purposes

* upgrade to sdk v0.50.0-alpha.1 and rm dep on ibc-go simapp

* refactor and improve capability tests to use test helpers in favour of simapp

* rm simapp and go mod tidy

* update godoc

* assert the transfer capability does not exist until memstore is reinitialised

(cherry picked from commit 49cdfc5)

# Conflicts:
#	modules/capability/capability_test.go
#	modules/capability/genesis_test.go
#	modules/capability/go.mod
#	modules/capability/go.sum
#	modules/capability/module.go
#	modules/capability/simulation/decoder_test.go
damiannolan added a commit that referenced this pull request Jul 14, 2023
…ackport #4068) (#4083)

* deps: upgrade capability to sdk v0.50 and remove ibc-go dependency (#4068)

* adding testing/simapp dir for testing purposes

* upgrade to sdk v0.50.0-alpha.1 and rm dep on ibc-go simapp

* refactor and improve capability tests to use test helpers in favour of simapp

* rm simapp and go mod tidy

* update godoc

* assert the transfer capability does not exist until memstore is reinitialised

(cherry picked from commit 49cdfc5)

# Conflicts:
#	modules/capability/capability_test.go
#	modules/capability/genesis_test.go
#	modules/capability/go.mod
#	modules/capability/go.sum
#	modules/capability/module.go
#	modules/capability/simulation/decoder_test.go

* addressing merge conflicts

* pin goleveldb using replace

* updating to go 1.20 in capability workflows

* just use the workflow from main.. please work

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
capability Issues for capability modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove dependency on ibc-go from capability module
4 participants