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(x/mint): unexport keeper methods #2417

Merged
merged 6 commits into from
Aug 16, 2022
Merged

refactor(x/mint): unexport keeper methods #2417

merged 6 commits into from
Aug 16, 2022

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Aug 15, 2022

Closes: #XXX

What is the purpose of the change

Currently, a lot of the keeper methods are exported when they are only used inside the keeper package or in tests.

For the purposes of information hiding, we should unexport as many methods as possible to avoid misuse from incorrect locations.

There are no changes other than unexporting some methods and none of the methods were removed.

Brief Changelog

  • unexport setLastReductionEpochNum
  • unexport getLastReductionEpochNum
  • unexport createDeveloperVestingModuleAccount
  • unexport mintCoins
  • create a helper in apptesting for minting tokens in tests
  • reshuffle order in mint keeper.go so that exported methods go first, then unexported

Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? yes
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? yes
  • How is the feature or change documented? not applicable

@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Aug 15, 2022
@p0mvn p0mvn marked this pull request as ready for review August 15, 2022 19:59
@p0mvn p0mvn requested a review from a team August 15, 2022 19:59
// - amount is nil or zero.
// - if ctx has block height greater than 0.
// - developer vesting module account is already created prior to calling this method.
func (k Keeper) CreateDeveloperVestingModuleAccount(ctx sdk.Context, amount sdk.Coin) error {
Copy link
Member Author

@p0mvn p0mvn Aug 15, 2022

Choose a reason for hiding this comment

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

Note to reviewers: some methods in this file were shuffled around so that exported methods go first, and, then, unexported follow

None of the methods were actually removed

@p0mvn p0mvn added the A:backport/v11.x backport patches to v11.x branch label Aug 15, 2022
Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

LGTM. Is there any specific methodology you go through to determine which keeper methods should stay unexported? I think it may be helpful to document this somewhere so we can easily determine in the future (and possibly automate warnings!)

x/mint/keeper/keeper.go Outdated Show resolved Hide resolved
x/mint/keeper/keeper.go Outdated Show resolved Hide resolved
x/mint/keeper/keeper.go Outdated Show resolved Hide resolved
x/mint/keeper/keeper.go Outdated Show resolved Hide resolved
@p0mvn
Copy link
Member Author

p0mvn commented Aug 15, 2022

LGTM. Is there any specific methodology you go through to determine which keeper methods should stay unexported? I think it may be helpful to document this somewhere so we can easily determine in the future (and possibly automate warnings!)

As a general rule, we should be hiding as many methods as possible without a specific use case outside of the internal logic. More on the principle.

For example, with x/mint no other module should be able to MintTokens or CreateDeveloperVestingModuleAccount outside of the internal mint keeper logic so it makes sense to hide them.

We should be encapsulating logic into stable interfaces and exposing them to the clients. In the context of x/mint keeper, the core of these stable interfaces is AfterEpochEnd hook + some other boilerplate methods that all keepers implement. Everything else is internal logic and should be encapsulated by the keeper.

p0mvn and others added 4 commits August 15, 2022 13:44
@p0mvn p0mvn merged commit 4176b28 into main Aug 16, 2022
@p0mvn p0mvn deleted the roman/mint-unexport branch August 16, 2022 16:34
mergify bot pushed a commit that referenced this pull request Aug 16, 2022
* refactor(x/mint): unexport keeper methods

* changelog

* Update x/mint/keeper/keeper.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/mint/keeper/keeper.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/mint/keeper/keeper.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/mint/keeper/keeper.go

Co-authored-by: Adam Tucker <[email protected]>

Co-authored-by: Adam Tucker <[email protected]>
(cherry picked from commit 4176b28)

# Conflicts:
#	CHANGELOG.md
#	app/apptesting/test_suite.go
#	x/mint/keeper/genesis.go
#	x/mint/keeper/hooks.go
#	x/mint/keeper/keeper.go
#	x/mint/keeper/keeper_test.go
p0mvn added a commit that referenced this pull request Aug 16, 2022
@github-actions github-actions bot mentioned this pull request May 1, 2024
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v11.x backport patches to v11.x branch C:app-wiring Changes to the app folder C:docs Improvements or additions to documentation C:x/mint C:x/pool-incentives
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants