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

Use KVStoreService instead of StoreKey #1028

Merged
merged 13 commits into from
Nov 25, 2024
Merged

Conversation

masihyeganeh
Copy link
Contributor

@masihyeganeh masihyeganeh commented Nov 19, 2024

Description

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@masihyeganeh masihyeganeh requested a review from a team as a code owner November 19, 2024 12:42
@masihyeganeh masihyeganeh requested review from dzmitryhil, miladz68 and ysv and removed request for a team November 19, 2024 12:42
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 56.12053% with 233 lines in your changes missing coverage. Please review.

Project coverage is 60.50%. Comparing base (1f99518) to head (13b4043).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
x/asset/ft/keeper/keeper.go 57.14% 30 Missing and 15 partials ⚠️
x/asset/nft/keeper/keeper.go 70.96% 18 Missing and 9 partials ⚠️
x/feemodel/keeper/keeper.go 59.52% 10 Missing and 7 partials ⚠️
x/feemodel/module.go 27.27% 10 Missing and 6 partials ⚠️
x/asset/ft/keeper/token_upgradev1.go 16.66% 10 Missing and 5 partials ⚠️
x/dex/keeper/keeper.go 61.53% 10 Missing and 5 partials ⚠️
x/asset/ft/keeper/grpc_query.go 36.84% 8 Missing and 4 partials ⚠️
x/asset/ft/keeper/keeper_dex.go 58.62% 8 Missing and 4 partials ⚠️
x/asset/ft/genesis.go 18.18% 4 Missing and 5 partials ⚠️
x/wbank/keeper/keeper.go 47.05% 6 Missing and 3 partials ⚠️
... and 16 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1028      +/-   ##
==========================================
- Coverage   61.29%   60.50%   -0.79%     
==========================================
  Files         159      159              
  Lines       18318    18528     +210     
==========================================
- Hits        11228    11211      -17     
- Misses       6074     6223     +149     
- Partials     1016     1094      +78     
Flag Coverage Δ
coreum 57.10% <56.12%> (-0.75%) ⬇️
coreum-integration-tests-modules 46.28% <34.83%> (-0.78%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@masihyeganeh masihyeganeh changed the title Masih/kv store service Use KVStoreService instead of StoreKey Nov 20, 2024
Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewed 24 of 25 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dzmitryhil, @miladz68, and @ysv)

@masihyeganeh masihyeganeh force-pushed the masih/kv-store-service branch from 5ef0460 to ec9e523 Compare November 20, 2024 13:10
Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dzmitryhil, @miladz68, and @ysv)

Copy link
Contributor

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @masihyeganeh, @miladz68, and @ysv)


x/delay/keeper/keeper.go line 100 at r3 (raw file):

	store := k.storeService.OpenKVStore(ctx)
	if val, _ := store.Has(key); val {

You shouldn't ignore the error! Either return it or panic.


x/delay/keeper/keeper.go line 132 at r3 (raw file):

	store := k.storeService.OpenKVStore(ctx)
	if val, _ := store.Has(key); val {

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 54 at r3 (raw file):

func (k Keeper) GetParams(ctx sdk.Context) types.Params {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(types.ParamsKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 204 at r3 (raw file):

	}

	bz, _ := k.storeService.OpenKVStore(ctx).Get(classKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 499 at r3 (raw file):

	}

	isBurnt, _ := k.storeService.OpenKVStore(ctx).Get(key)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 671 at r3 (raw file):

	}

	val, _ := store.Get(key)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 706 at r3 (raw file):

	}

	val, _ := k.storeService.OpenKVStore(ctx).Get(key)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 888 at r3 (raw file):

	}

	val, _ := k.storeService.OpenKVStore(ctx).Get(classKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/nft/keeper/keeper.go line 902 at r3 (raw file):

	}

	val, _ := k.storeService.OpenKVStore(ctx).Get(key)

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/keeper.go line 76 at r3 (raw file):

// GetParams gets the parameters of the module.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
	store := k.storeService.OpenKVStore(ctx)

In some cases you use

store := ctx.KVStore(k.storeKey)
store.Set()...

But in some

k.storeService.OpenKVStore(ctx).Set

Let's use one stile (2nd better IMO) for the case when we need it once in the func.


x/asset/ft/keeper/keeper.go line 77 at r3 (raw file):

func (k Keeper) GetParams(ctx sdk.Context) types.Params {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(types.ParamsKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/keeper.go line 998 at r3 (raw file):

	store := k.storeService.OpenKVStore(ctx)
	compositeKey := types.CreateSymbolKey(issuer, symbol)
	rawBytes, _ := store.Get(compositeKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/keeper.go line 1158 at r3 (raw file):

func (k Keeper) isGloballyFrozen(ctx sdk.Context, denom string) bool {
	store := k.storeService.OpenKVStore(ctx)
	isGloballyFrozen, _ := store.Get(types.CreateGlobalFreezeKey(denom))

You shouldn't ignore the error! Either return it or panic.


x/dex/keeper/keeper_store.go line 98 at r3 (raw file):

	val proto.Message,
) error {
	bz, _ := k.storeService.OpenKVStore(ctx).Get(key)

You shouldn't ignore the error! Either return it or panic.


x/customparams/keeper/keeper.go line 36 at r3 (raw file):

func (k Keeper) GetStakingParams(ctx sdk.Context) types.StakingParams {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(types.StakingParamsKey)

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/keeper_dex.go line 120 at r3 (raw file):

// GetDEXSettings gets the DEX settings of a specified denom.
func (k Keeper) GetDEXSettings(ctx sdk.Context, denom string) (types.DEXSettings, error) {
	bz, _ := k.storeService.OpenKVStore(ctx).Get(types.CreateDEXSettingsKey(denom))

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/keeper_dex.go line 569 at r3 (raw file):

	}

	err = k.SetDEXSettings(ctx, denom, newSettings)

How about in-line error handling?


x/asset/ft/keeper/token_upgrade.go line 54 at r3 (raw file):

	store := k.storeService.OpenKVStore(ctx)
	key := types.CreatePendingTokenUpgradeKey(denom)
	if val, _ := store.Has(key); val {

You shouldn't ignore the error! Either return it or panic.


x/asset/ft/keeper/token_upgrade.go line 70 at r3 (raw file):

// GetTokenUpgradeStatuses returns the token upgrade statuses of a specified denom.
func (k Keeper) GetTokenUpgradeStatuses(ctx sdk.Context, denom string) types.TokenUpgradeStatuses {
	bz, _ := k.storeService.OpenKVStore(ctx).Get(types.CreateTokenUpgradeStatusesKey(denom))

You shouldn't ignore the error! Either return it or panic.


x/feemodel/keeper/keeper.go line 43 at r3 (raw file):

	gasUsed := sdkmath.NewInt(0)
	bz, _ := tStore.Get(gasTrackingKey)

You shouldn't ignore the error! Either return it or panic.


x/feemodel/keeper/keeper.go line 77 at r3 (raw file):

func (k Keeper) GetParams(ctx sdk.Context) types.Params {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(paramsKey)

You shouldn't ignore the error! Either return it or panic.


x/feemodel/keeper/keeper.go line 126 at r3 (raw file):

func (k Keeper) GetLongEMAGas(ctx sdk.Context) int64 {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(longEMAGasKey)

You shouldn't ignore the error! Either return it or panic.


x/feemodel/keeper/keeper.go line 155 at r3 (raw file):

func (k Keeper) GetMinGasPrice(ctx sdk.Context) sdk.DecCoin {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(gasPriceKey)

You shouldn't ignore the error! Either return it or panic.


x/dex/keeper/keeper.go line 194 at r3 (raw file):

func (k Keeper) GetParams(ctx sdk.Context) types.Params {
	store := k.storeService.OpenKVStore(ctx)
	bz, _ := store.Get(types.ParamsKey)

You shouldn't ignore the error! Either return it or panic.


x/dex/keeper/keeper.go line 734 at r3 (raw file):

		}
	}
	err = k.removeOrderData(ctx, record.OrderSequence)

Good place for in-line error handling


x/dex/keeper/keeper.go line 938 at r3 (raw file):

		return nil, nil, err
	}
	s := k.storeService.OpenKVStore(ctx)

You call it differenly in different places, check it please.


x/dex/keeper/keeper.go line 1227 at r3 (raw file):

		}
		// save empty slice
		err = k.storeService.OpenKVStore(ctx).Set(key, make([]byte, 0))

Good place for in-line handling.

Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @dzmitryhil, @miladz68, and @ysv)


x/asset/ft/keeper/keeper.go line 76 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

In some cases you use

store := ctx.KVStore(k.storeKey)
store.Set()...

But in some

k.storeService.OpenKVStore(ctx).Set

Let's use one stile (2nd better IMO) for the case when we need it once in the func.

It is mostly used like the first style when store is needed in more than one line or if it is wrapped in a couple of function calls and using the second one makes it less readable. But I'll try to unify them everywhere in code


x/asset/ft/keeper/keeper.go line 77 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

The error happens only if the key is nil which in our case it will never be, so it's safe to not handle it
Source: cosmossdk.io/core/store/store.go

And I didn't want to add a new return value to functions everywhere for the case that doesn't happen. Let's discuss it in the meeting to decide if we should handle it or not


x/asset/ft/keeper/keeper_dex.go line 569 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

How about in-line error handling?

Done.


x/dex/keeper/keeper.go line 734 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

Good place for in-line error handling

Done.


x/dex/keeper/keeper.go line 938 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You call it differenly in different places, check it please.

Done.


x/dex/keeper/keeper.go line 1227 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

Good place for in-line handling.

Done.

Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewed 8 of 8 files at r4, all commit messages.
Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @dzmitryhil, @miladz68, and @ysv)

@masihyeganeh masihyeganeh force-pushed the masih/kv-store-service branch from c5c1dff to d84fbb4 Compare November 22, 2024 08:24
Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewable status: 9 of 52 files reviewed, 27 unresolved discussions (waiting on @dzmitryhil, @miladz68, and @ysv)


x/asset/ft/keeper/keeper.go line 998 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/ft/keeper/keeper.go line 1158 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/ft/keeper/keeper_dex.go line 120 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/ft/keeper/token_upgrade.go line 54 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/ft/keeper/token_upgrade.go line 70 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 54 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 204 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 499 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 671 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 706 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 888 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/asset/nft/keeper/keeper.go line 902 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/customparams/keeper/keeper.go line 36 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/delay/keeper/keeper.go line 100 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/delay/keeper/keeper.go line 132 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/dex/keeper/keeper.go line 194 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/dex/keeper/keeper_store.go line 98 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/feemodel/keeper/keeper.go line 43 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/feemodel/keeper/keeper.go line 77 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/feemodel/keeper/keeper.go line 126 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.


x/feemodel/keeper/keeper.go line 155 at r3 (raw file):

Previously, dzmitryhil (Dzmitry Hil) wrote…

You shouldn't ignore the error! Either return it or panic.

Done.

Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewed 43 of 43 files at r5, all commit messages.
Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @dzmitryhil, @miladz68, and @ysv)

Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 25 files at r1, 1 of 3 files at r2, 2 of 8 files at r4, 43 of 43 files at r5, all commit messages.
Reviewable status: all files reviewed, 28 unresolved discussions (waiting on @dzmitryhil, @masihyeganeh, and @ysv)


x/asset/nft/keeper/keeper.go line 692 at r5 (raw file):

	}

	val, _ = store.Get(key)

same as Dima mentioned above.

Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Dismissed @miladz68 from a discussion.
Reviewable status: 46 of 57 files reviewed, 27 unresolved discussions (waiting on @dzmitryhil, @miladz68, and @ysv)


x/asset/nft/keeper/keeper.go line 692 at r5 (raw file):

Previously, miladz68 (milad) wrote…

same as Dima mentioned above.

Done.

Copy link
Contributor Author

@masihyeganeh masihyeganeh left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 11 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @dzmitryhil and @ysv)

Copy link
Contributor

@miladz68 miladz68 left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 11 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 27 unresolved discussions (waiting on @dzmitryhil and @ysv)

Copy link
Contributor

@dzmitryhil dzmitryhil left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ysv)

@masihyeganeh masihyeganeh merged commit cc533a6 into master Nov 25, 2024
10 of 11 checks passed
@masihyeganeh masihyeganeh deleted the masih/kv-store-service branch November 25, 2024 15:39
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