-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
565ae53
to
2e06e78
Compare
// ModuleAccountAddrs provides a list of blocked module accounts from configuration in app.yaml | ||
// | ||
// Ported from SimApp | ||
func ModuleAccountAddrs() map[string]bool { |
There was a problem hiding this comment.
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.
eb85234
to
57b0eae
Compare
simapp/test_helpers.go
Outdated
func ModuleAccountAddrs() map[string]bool { | ||
cfg := LoadAppConfig() | ||
var blockedAddresses bank.BlockedAddresses | ||
err := depinject.Inject(cfg, &blockedAddresses) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Lines 53 to 61 in 2f198b1
# 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
|
||
type BlockedAddresses map[string]bool | ||
|
||
func provideBlockedAddresses(config *authmodulev1.Module) BlockedAddresses { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
Lines 33 to 44 in 33c4bac
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 |
There was a problem hiding this comment.
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.
simapp/test_helpers.go
Outdated
func ModuleAccountAddrs() map[string]bool { | ||
cfg := LoadAppConfig() | ||
var blockedAddresses bank.BlockedAddresses | ||
err := depinject.Inject(cfg, &blockedAddresses) |
There was a problem hiding this comment.
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
ref #12083 |
8e4b75a
to
da280d6
Compare
5409d22
to
2f198b1
Compare
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
x/auth/keeper/keeper.go
Outdated
@@ -148,6 +151,11 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { | |||
return accNumber | |||
} | |||
|
|||
// GetModulePermissions fetches per-module account permissions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetModulePermissions fetches per-module account permissions | |
// GetModulePermissions fetches per-module account permissions. |
simapp/test_helpers.go
Outdated
cfg := appconfig.LoadYAML(AppConfigYaml) | ||
var bk bankkeeper.Keeper | ||
err := depinject.Inject(cfg, &bk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var AppConfigYaml []byte | |
var appConfigYaml []byte |
feels more logical to export AppConfig
and not the yaml
* Integrate with keyed resolvers feature of depinject
6232d98
to
02a266a
Compare
}; | ||
|
||
// blocked_module_accounts configures exceptional module accounts which should be blocked from receiving funds | ||
repeated string blocked_module_accounts = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
Codecov Report
@@ 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
|
* 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
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change