-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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/auth): app wiring setup #12019
Changes from 33 commits
1abe96f
35ad13d
d03c7cb
78e455b
38896cf
5bb0256
69b1d5f
d7ff0b0
d9beb5c
137d76e
e08a858
ef84d47
39c01a5
5b0c58f
1b94c8f
725d7b9
7a17078
e7befbd
999a9ed
943ffc9
6809623
286f862
c801f25
b99d9f1
a8de03b
1838ee2
df4982a
96b7e6a
90759ac
b8d2c27
0398eb0
33e42a5
cf2a7f2
7dadcf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto3"; | ||
|
||
package cosmos.auth.module.v1; | ||
|
||
import "cosmos/app/v1alpha1/module.proto"; | ||
|
||
// Module is the config object for the auth module. | ||
message Module { | ||
option (cosmos.app.v1alpha1.module) = { | ||
go_import: "github.com/cosmos/cosmos-sdk/x/auth" | ||
}; | ||
|
||
// bech32_prefix is the bech32 account prefix for the app. | ||
string bech32_prefix = 1; | ||
|
||
// module_account_permissions are module account permissions. | ||
repeated ModuleAccountPermission module_account_permissions = 2; | ||
} | ||
|
||
// ModuleAccountPermission represents permissions for a module account. | ||
message ModuleAccountPermission { | ||
// account is the name of the module. | ||
string account = 1; | ||
|
||
// permissions are the permissions this module has. Currently recognized | ||
// values are minter, burner and staking. | ||
repeated string permissions = 2; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,9 +186,6 @@ type SimApp struct { | |
|
||
// simulation manager | ||
sm *module.SimulationManager | ||
|
||
// module configurator | ||
configurator module.Configurator | ||
} | ||
|
||
func init() { | ||
|
@@ -213,6 +210,7 @@ func NewSimApp( | |
) *SimApp { | ||
var appBuilder *runtime.AppBuilder | ||
var paramsKeeper paramskeeper.Keeper | ||
var accountKeeper authkeeper.AccountKeeper | ||
var appCodec codec.Codec | ||
var legacyAmino *codec.LegacyAmino | ||
var interfaceRegistry codectypes.InterfaceRegistry | ||
|
@@ -222,6 +220,7 @@ func NewSimApp( | |
&appCodec, | ||
&legacyAmino, | ||
&interfaceRegistry, | ||
&accountKeeper, | ||
) | ||
if err != nil { | ||
panic(err) | ||
|
@@ -230,7 +229,7 @@ func NewSimApp( | |
runtimeApp := appBuilder.Build(logger, db, traceStore, baseAppOptions...) | ||
|
||
keys := sdk.NewKVStoreKeys( | ||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bit of an issue here surfaced in tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... this could be an issue when migrating existing stores. One option is to give the module the name acc in the app config. In general I think the existing practice of hard coding these names is wrong, but we need to cope with how things are currently done too... we'll need to think about this a bit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two options I can think of:
Sort of leaning towards 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I favor (2) as well (key overrides) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implementation of (2) pushed for review in 90759ac |
||
banktypes.StoreKey, stakingtypes.StoreKey, | ||
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, | ||
govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, | ||
evidencetypes.StoreKey, capabilitytypes.StoreKey, | ||
|
@@ -259,15 +258,14 @@ func NewSimApp( | |
app.ParamsKeeper = paramsKeeper | ||
initParamsKeeper(paramsKeeper) | ||
|
||
app.AccountKeeper = accountKeeper | ||
|
||
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) | ||
// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating | ||
// their scoped modules in `NewApp` with `ScopeToModule` | ||
app.CapabilityKeeper.Seal() | ||
|
||
// add keepers | ||
app.AccountKeeper = authkeeper.NewAccountKeeper( | ||
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, | ||
) | ||
app.BankKeeper = bankkeeper.NewBaseKeeper( | ||
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), | ||
) | ||
|
@@ -355,7 +353,6 @@ func NewSimApp( | |
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, | ||
encodingConfig.TxConfig, | ||
), | ||
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), | ||
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), | ||
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), | ||
capability.NewAppModule(appCodec, *app.CapabilityKeeper), | ||
|
@@ -395,8 +392,6 @@ func NewSimApp( | |
|
||
app.ModuleManager.RegisterInvariants(&app.CrisisKeeper) | ||
app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) | ||
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) | ||
app.ModuleManager.RegisterServices(app.configurator) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already called once in runtime/app so removing this call. |
||
|
||
// add test gRPC service for testing gRPC queries in isolation | ||
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) | ||
|
@@ -617,7 +612,6 @@ func GetMaccPerms() map[string][]string { | |
|
||
// initParamsKeeper init params keeper and its subspaces | ||
func initParamsKeeper(paramsKeeper paramskeeper.Keeper) { | ||
paramsKeeper.Subspace(authtypes.ModuleName) | ||
paramsKeeper.Subspace(banktypes.ModuleName) | ||
paramsKeeper.Subspace(stakingtypes.ModuleName) | ||
paramsKeeper.Subspace(minttypes.ModuleName) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,17 @@ import ( | |
"fmt" | ||
"math/rand" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
|
||
"github.com/spf13/cobra" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
|
||
"cosmossdk.io/core/appmodule" | ||
modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" | ||
"github.com/cosmos/cosmos-sdk/runtime" | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
|
@@ -59,7 +65,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod | |
} | ||
|
||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the auth module. | ||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { | ||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { | ||
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { | ||
panic(err) | ||
} | ||
|
@@ -185,3 +191,33 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { | |
func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { | ||
return nil | ||
} | ||
|
||
// | ||
// New App Wiring Setup | ||
// | ||
|
||
func init() { | ||
appmodule.Register(&modulev1.Module{}, | ||
appmodule.Provide(provideModuleBasic, provideModule), | ||
) | ||
} | ||
|
||
func provideModuleBasic() runtime.AppModuleBasicWrapper { | ||
return runtime.WrapAppModuleBasic(AppModuleBasic{}) | ||
} | ||
|
||
func provideModule( | ||
config *modulev1.Module, | ||
key *store.KVStoreKey, | ||
cdc codec.Codec, | ||
subspace paramtypes.Subspace) (keeper.AccountKeeper, runtime.AppModuleWrapper) { | ||
|
||
maccPerms := map[string][]string{} | ||
for _, permission := range config.ModuleAccountPermissions { | ||
maccPerms[permission.Account] = permission.Permissions | ||
} | ||
|
||
k := keeper.NewAccountKeeper(cdc, key, subspace, types.ProtoBaseAccount, maccPerms, config.Bech32Prefix) | ||
m := NewAppModule(cdc, k, simulation.RandomGenesisAccounts) | ||
Comment on lines
+220
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return k, runtime.WrapAppModule(m) | ||
} |
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.
This is no longer needed and not provided by x/auth