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

feat(x/bank): app wiring migration #12032

Merged
merged 11 commits into from
Jun 1, 2022
Merged

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented May 24, 2022

Description

Migrates x/bank module into the app wiring framework.


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)

@kocubinski kocubinski changed the title Kocubinski/app wiring bank feat(x/bank): app wiring migration May 24, 2022
@kocubinski kocubinski force-pushed the kocubinski/app-wiring-bank branch 2 times, most recently from 565ae53 to 2e06e78 Compare May 31, 2022 14:48
// ModuleAccountAddrs provides a list of blocked module accounts from configuration in app.yaml
//
// Ported from SimApp
func ModuleAccountAddrs() map[string]bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaces SimApp.ModuleAccountAddrs for test function usages.

@kocubinski kocubinski marked this pull request as ready for review May 31, 2022 17:05
@kocubinski kocubinski requested a review from a team as a code owner May 31, 2022 17:05
func ModuleAccountAddrs() map[string]bool {
cfg := LoadAppConfig()
var blockedAddresses bank.BlockedAddresses
err := depinject.Inject(cfg, &blockedAddresses)
Copy link
Member Author

Choose a reason for hiding this comment

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

@aaronc Any thoughts on this integration of depinject into tests?

Copy link
Member

Choose a reason for hiding this comment

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

see my comments below. basically I think we want to get these from the bank keeper

Copy link
Contributor

Choose a reason for hiding this comment

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

How will an app dev provide/override these?

Copy link
Member Author

Choose a reason for hiding this comment

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

How will an app dev provide/override these?

# uncomment to provide a block list different from the modules mentioned in auth.module_account_permissions
# blocked_module_accounts:
# - fee_collector
# - distribution
# - mint
# - bonded_tokens_pool
# - not_bonded_tokens_pool
# - gov
# - nft

x/bank/module.go Outdated Show resolved Hide resolved
simapp/test_helpers.go Outdated Show resolved Hide resolved
x/bank/module.go Outdated

type BlockedAddresses map[string]bool

func provideBlockedAddresses(config *authmodulev1.Module) BlockedAddresses {
Copy link
Member

Choose a reason for hiding this comment

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

getting this from the auth module config is maybe reasonable. originally I had the blocked addresses specified in the bank module config but this is more safe. it would feel a bit more correct to have a method on the AccountKeeper to get these so we don't depend on a specific version of the auth module

I'm also not comfortable with providing these directly into the container like this.

A better way I think would be:

  • add AccountKeeper.GetModulePermissions()
  • add BankKeeper.GetBlockedAddresses()

@alexanderbez any opinion here?

Copy link
Contributor

Choose a reason for hiding this comment

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

AccountKeeper.GetModulePermissions() seems reasonable to me -- but they need to be configurable. Is that the case? Can a dev set these in the app configuration?

Copy link
Member

@aaronc aaronc May 31, 2022

Choose a reason for hiding this comment

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

These permissions are set in the auth module config:

module_account_permissions:
- account: fee_collector
- account: distribution
- account: mint
permissions: [ minter ]
- account: bonded_tokens_pool
permissions: [ burner, staking ]
- account: not_bonded_tokens_pool
permissions: [ burner, staking ]
- account: gov
permissions: [ burner ]
- account: nft

Copy link
Member

Choose a reason for hiding this comment

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

I think defaulting to AccountKeeper.GetModulePermissions() for blocked addresses makes sense, but let's also have a blocked addresses option in the bank config to override this if needed.

func ModuleAccountAddrs() map[string]bool {
cfg := LoadAppConfig()
var blockedAddresses bank.BlockedAddresses
err := depinject.Inject(cfg, &blockedAddresses)
Copy link
Member

Choose a reason for hiding this comment

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

see my comments below. basically I think we want to get these from the bank keeper

@tac0turtle
Copy link
Member

ref #12083

@kocubinski kocubinski force-pushed the kocubinski/app-wiring-bank branch 2 times, most recently from 8e4b75a to da280d6 Compare June 1, 2022 15:54
simapp/app.yaml Outdated
config:
"@type": cosmos.bank.module.v1.Module
# uncomment to provide a block list different from the modules mentioned in auth.module_account_permissions
# blocked_module_accounts:
Copy link
Member

Choose a reason for hiding this comment

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

above we have

 module_account_permissions:
        - account: fee_collector
        - account: distribution

does this mean they can receive funds?

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 default (existing) behavior is to disallow funds transfer to any of the module accounts in module_account_permissions including those you mentioned.

Copy link
Member Author

@kocubinski kocubinski Jun 1, 2022

Choose a reason for hiding this comment

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

The block that is commented out here is new functionality, providing a way to override bank behavior to differ from auth configuration. Previously they were both being injected from code in SimApp.

Copy link
Member

Choose a reason for hiding this comment

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

We should remove the commented out block. We shouldn't encourage anyone to override this for now I think. Or is there any module account which can receive sends?

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking was that it might be good to demonstrate the full functionality of app.yaml in comments, kind of like the lein sample.project.clj but perhaps this is better as a documentation task, not the live SimApp config.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we actually want to discourage this type of customization IMHO. This particular design issue has caused bugs. Honestly I can't wait to redesign it but for now we just need to limit damage

go_import: "github.com/cosmos/cosmos-sdk/x/bank"
};

// blocked_module_accounts configures exceptional module accounts which should be blocked from receiving funds
Copy link
Member

Choose a reason for hiding this comment

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

We need to document what the default is and that this overrides the default

x/bank/module.go Outdated
depinject.In

Config *modulev1.Module
AccountKeeper types.AccountKeeper `key:"cosmos.auth.module.v1.AccountKeeper"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AccountKeeper types.AccountKeeper `key:"cosmos.auth.module.v1.AccountKeeper"`
AccountKeeper types.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"`

maybe we can skip module in the name?

@@ -148,6 +151,11 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 {
return accNumber
}

// GetModulePermissions fetches per-module account permissions
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// GetModulePermissions fetches per-module account permissions
// GetModulePermissions fetches per-module account permissions.

Comment on lines 516 to 518
cfg := appconfig.LoadYAML(AppConfigYaml)
var bk bankkeeper.Keeper
err := depinject.Inject(cfg, &bk)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cfg := appconfig.LoadYAML(AppConfigYaml)
var bk bankkeeper.Keeper
err := depinject.Inject(cfg, &bk)
var bk bankkeeper.Keeper
err := depinject.Inject(AppConfig, &bk)

No need to re-read the yaml. I think this is the pattern we should encourage

simapp/app.go Outdated

var appConfig = appconfig.LoadYAML(appConfigYaml)
var appConfig = appconfig.LoadYAML(AppConfigYaml)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var appConfig = appconfig.LoadYAML(AppConfigYaml)
var AppConfig = appconfig.LoadYAML(appConfigYaml)

simapp/app.go Outdated
@@ -198,9 +198,9 @@ func init() {
}

//go:embed app.yaml
var appConfigYaml []byte
var AppConfigYaml []byte
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var AppConfigYaml []byte
var appConfigYaml []byte

feels more logical to export AppConfig and not the yaml

@kocubinski kocubinski requested a review from aaronc June 1, 2022 19:45
};

// blocked_module_accounts configures exceptional module accounts which should be blocked from receiving funds
repeated string blocked_module_accounts = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
repeated string blocked_module_accounts = 1;
repeated string blocked_module_accounts_override = 1;

};

// blocked_module_accounts configures exceptional module accounts which should be blocked from receiving funds.
// If left empty defaults to the list of account names supplied in the auth module configuration as
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If left empty defaults to the list of account names supplied in the auth module configuration as
// If left empty it defaults to the list of account names supplied in the auth module configuration as

@aaronc aaronc requested a review from facundomedica June 1, 2022 19:51
@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #12032 (526f390) into main (f71d464) will increase coverage by 0.33%.
The diff coverage is 68.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12032      +/-   ##
==========================================
+ Coverage   66.03%   66.36%   +0.33%     
==========================================
  Files         671      685      +14     
  Lines       70956    71983    +1027     
==========================================
+ Hits        46859    47775     +916     
- Misses      21435    21517      +82     
- Partials     2662     2691      +29     
Impacted Files Coverage Δ
depinject/inject.go 76.00% <ø> (ø)
simapp/test_helpers.go 26.34% <0.00%> (-0.46%) ⬇️
x/bank/keeper/send.go 82.14% <0.00%> (-0.85%) ⬇️
x/bank/module.go 63.91% <76.92%> (+5.58%) ⬆️
simapp/app.go 82.64% <100.00%> (-0.38%) ⬇️
x/auth/keeper/keeper.go 70.27% <100.00%> (+0.54%) ⬆️
x/auth/module.go 63.29% <100.00%> (ø)
depinject/location.go 73.58% <0.00%> (ø)
depinject/container.go 89.08% <0.00%> (ø)
... and 11 more

@kocubinski kocubinski merged commit 8c281ee into main Jun 1, 2022
@kocubinski kocubinski deleted the kocubinski/app-wiring-bank branch June 1, 2022 21:21
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* Initial work on bank module app wiring

* Fix import in bank module

* integrating bank module into simapp DI

* Integrate usages of ModuleAccountAddrs into DI container, remove from SimApp

* Remove dependency on authkeeper from bank module

* Integrate with keyed resolvers feature of depinject

* Refactoring to remove direct dependency from bank -> auth

* Clean up app.yaml usage in test

* Clean up comments, keys, and testing fns.

* Remove commented example in bank module config

* Regenerate code from proto files

* Fix usage of BlockedModuleAccountsOverride
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.

5 participants