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!: use KVStoreService in x/auth #15520

Merged
merged 23 commits into from
Mar 27, 2023
Merged

refactor!: use KVStoreService in x/auth #15520

merged 23 commits into from
Mar 27, 2023

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Mar 22, 2023

Description

  • Most changes come from switching from sdk.Context to context.Context (changed the keeper methods and we have expected keeper interfaces everywhere for auth).
  • Right now we still pass the StoreKey to the Keeper instead of the service because we need it for pagination and prefix iteration (prefix.NewStore and query.Paginate). Should we do something about that now?
  • Added an adapter so we can pass the KVStoreService's KVStore into query.Paginate and prefix.NewStore (not sure about where to put it)

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

store := ak.storeSvc.OpenKVStore(ctx)
has, err := store.Has(types.AddressStoreKey(addr))
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
store := ak.storeSvc.OpenKVStore(ctx)
bz, err := store.Get(types.AddressStoreKey(addr))
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
x/auth/keeper/keeper.go Show resolved Hide resolved
Comment on lines +162 to +164
func KVStoreAdapter(store store.KVStore) storetypes.KVStore {
return &kvStoreAdapter{store}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure where to put this adapter, accepting suggestions :D

Copy link
Member

Choose a reason for hiding this comment

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

why is this needed? the new interface returns errors can we use that or?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because there's the prefix store and the query.Paginate that take in the KVStore from /store/types instead of core. Once we migrate all modules we could remove this adapter and modify the other methods to take in the core KVStore.

Copy link
Member Author

Choose a reason for hiding this comment

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

So yes, because the new interface returns errors so it's not compatible

Copy link
Member

Choose a reason for hiding this comment

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

makes sense thank you

@@ -158,3 +158,4 @@ require (
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1
replace github.com/cosmos/cosmos-sdk => ../../
Copy link
Member Author

Choose a reason for hiding this comment

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

We can remove this once we tag

Copy link
Member

@julienrbrt julienrbrt Mar 24, 2023

Choose a reason for hiding this comment

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

We won't tag the SDK in a while, best to use a pseudo version of the SDK from this branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I realized later that we are not tagging x/auth separately

x/nft/go.mod Outdated Show resolved Hide resolved
@facundomedica facundomedica marked this pull request as ready for review March 24, 2023 15:39
@facundomedica facundomedica requested a review from a team as a code owner March 24, 2023 15:39
@github-prbot github-prbot requested review from a team, aaronc and tac0turtle and removed request for a team March 24, 2023 15:39
func (s kvStoreAdapter) Set(key []byte, value []byte) {
err := s.store.Set(key, value)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (s kvStoreAdapter) Iterator(start []byte, end []byte) dbm.Iterator {
it, err := s.store.Iterator(start, end)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (s kvStoreAdapter) Delete(key []byte) {
err := s.store.Delete(key)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (s kvStoreAdapter) Get(key []byte) []byte {
bz, err := s.store.Get(key)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (s kvStoreAdapter) Has(key []byte) bool {
has, err := s.store.Has(key)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -289,7 +289,7 @@ func NewSimApp(
bApp.SetParamStore(&app.ConsensusParamsKeeper)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, keys[authtypes.StoreKey], authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
Copy link
Member

@julienrbrt julienrbrt Mar 24, 2023

Choose a reason for hiding this comment

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

Same comment as before about UPGRADING.md + changelog.
I think now the category can be generalized under simapp. Moreover, we should add that if chains are generating mocks for their own testing, they will need to re-generate them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Github is taking a while to update stuff here, but I've added a changelog entry and modified the upgrading doc.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! left 2 comments.

UPGRADING.md Outdated Show resolved Hide resolved
facundomedica and others added 2 commits March 27, 2023 15:03
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Comment on lines +162 to +164
func KVStoreAdapter(store store.KVStore) storetypes.KVStore {
return &kvStoreAdapter{store}
}
Copy link
Member

Choose a reason for hiding this comment

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

makes sense thank you

@facundomedica facundomedica enabled auto-merge (squash) March 27, 2023 18:47
@facundomedica facundomedica merged commit d29e8eb into main Mar 27, 2023
@facundomedica facundomedica deleted the facu/auth-storesvc branch March 27, 2023 18:57
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants