-
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: migrate x/capability to app wiring #12058
Changes from all commits
cfee9c8
96cfc00
117673f
7b560b1
5002e6a
5d81575
f1094f5
229be85
ad191ea
3e6a4d5
87a461d
6f1ee5c
d63dbfd
15a83b0
efb0394
6606c18
8da73e5
27146e6
e9c81a9
7ac22c1
14b798d
0ecb89f
aa33d9c
5bde56e
30c207c
90fc1ef
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
package cosmos.capability.module.v1; | ||
|
||
import "cosmos/app/v1alpha1/module.proto"; | ||
|
||
// Module is the config object of the capability module. | ||
message Module { | ||
option (cosmos.app.v1alpha1.module) = { | ||
go_import: "github.com/cosmos/cosmos-sdk/x/capability" | ||
}; | ||
|
||
// seal_keeper defines if keeper.Seal() will run on BeginBlock() to prevent further modules from creating a scoped | ||
// keeper. For more details check x/capability/keeper.go. | ||
bool seal_keeper = 1; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -208,102 +208,81 @@ func NewSimApp( | |||||||||||
homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, | ||||||||||||
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), | ||||||||||||
) *SimApp { | ||||||||||||
app := &SimApp{ | ||||||||||||
invCheckPeriod: invCheckPeriod, | ||||||||||||
} | ||||||||||||
|
||||||||||||
var appBuilder *runtime.AppBuilder | ||||||||||||
var paramsKeeper paramskeeper.Keeper | ||||||||||||
var accountKeeper authkeeper.AccountKeeper | ||||||||||||
var bankKeeper bankkeeper.Keeper | ||||||||||||
var appCodec codec.Codec | ||||||||||||
var legacyAmino *codec.LegacyAmino | ||||||||||||
var interfaceRegistry codectypes.InterfaceRegistry | ||||||||||||
|
||||||||||||
err := depinject.Inject(AppConfig, | ||||||||||||
&appBuilder, | ||||||||||||
¶msKeeper, | ||||||||||||
&appCodec, | ||||||||||||
&legacyAmino, | ||||||||||||
&interfaceRegistry, | ||||||||||||
&accountKeeper, | ||||||||||||
&bankKeeper, | ||||||||||||
&app.ParamsKeeper, | ||||||||||||
&app.CapabilityKeeper, | ||||||||||||
&app.appCodec, | ||||||||||||
&app.legacyAmino, | ||||||||||||
&app.interfaceRegistry, | ||||||||||||
&app.AccountKeeper, | ||||||||||||
&app.BankKeeper, | ||||||||||||
) | ||||||||||||
if err != nil { | ||||||||||||
panic(err) | ||||||||||||
} | ||||||||||||
|
||||||||||||
runtimeApp := appBuilder.Build(logger, db, traceStore, baseAppOptions...) | ||||||||||||
app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) | ||||||||||||
|
||||||||||||
keys := sdk.NewKVStoreKeys( | ||||||||||||
stakingtypes.StoreKey, | ||||||||||||
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, | ||||||||||||
govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, | ||||||||||||
evidencetypes.StoreKey, capabilitytypes.StoreKey, | ||||||||||||
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, | ||||||||||||
app.keys = sdk.NewKVStoreKeys( | ||||||||||||
stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, | ||||||||||||
slashingtypes.StoreKey, govtypes.StoreKey, upgradetypes.StoreKey, | ||||||||||||
feegrant.StoreKey, evidencetypes.StoreKey, authzkeeper.StoreKey, | ||||||||||||
nftkeeper.StoreKey, group.StoreKey, | ||||||||||||
) | ||||||||||||
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should | ||||||||||||
// not include this key. | ||||||||||||
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey") | ||||||||||||
app.memKeys = sdk.NewMemoryStoreKeys("testingkey") | ||||||||||||
|
||||||||||||
// configure state listening capabilities using AppOptions | ||||||||||||
// we are doing nothing with the returned streamingServices and waitGroup in this case | ||||||||||||
if _, _, err := streaming.LoadStreamingServices(runtimeApp.BaseApp, appOpts, appCodec, keys); err != nil { | ||||||||||||
if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, app.keys); err != nil { | ||||||||||||
tmos.Exit(err.Error()) | ||||||||||||
} | ||||||||||||
|
||||||||||||
app := &SimApp{ | ||||||||||||
App: runtimeApp, | ||||||||||||
legacyAmino: legacyAmino, | ||||||||||||
appCodec: appCodec, | ||||||||||||
interfaceRegistry: interfaceRegistry, | ||||||||||||
invCheckPeriod: invCheckPeriod, | ||||||||||||
keys: keys, | ||||||||||||
memKeys: memKeys, | ||||||||||||
} | ||||||||||||
|
||||||||||||
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() | ||||||||||||
initParamsKeeper(app.ParamsKeeper) | ||||||||||||
|
||||||||||||
// add keepers | ||||||||||||
app.BankKeeper = bankKeeper | ||||||||||||
|
||||||||||||
stakingKeeper := stakingkeeper.NewKeeper( | ||||||||||||
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), | ||||||||||||
app.appCodec, app.keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), | ||||||||||||
) | ||||||||||||
app.MintKeeper = mintkeeper.NewKeeper( | ||||||||||||
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, | ||||||||||||
app.appCodec, app.keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, | ||||||||||||
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, | ||||||||||||
) | ||||||||||||
app.DistrKeeper = distrkeeper.NewKeeper( | ||||||||||||
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, | ||||||||||||
app.appCodec, app.keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, | ||||||||||||
&stakingKeeper, authtypes.FeeCollectorName, | ||||||||||||
) | ||||||||||||
app.SlashingKeeper = slashingkeeper.NewKeeper( | ||||||||||||
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), | ||||||||||||
app.appCodec, app.keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), | ||||||||||||
) | ||||||||||||
app.CrisisKeeper = crisiskeeper.NewKeeper( | ||||||||||||
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, | ||||||||||||
) | ||||||||||||
|
||||||||||||
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) | ||||||||||||
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(app.appCodec, app.keys[feegrant.StoreKey], app.AccountKeeper) | ||||||||||||
|
||||||||||||
// register the staking hooks | ||||||||||||
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks | ||||||||||||
app.StakingKeeper = *stakingKeeper.SetHooks( | ||||||||||||
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), | ||||||||||||
) | ||||||||||||
|
||||||||||||
app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper) | ||||||||||||
app.AuthzKeeper = authzkeeper.NewKeeper(app.keys[authzkeeper.StoreKey], app.appCodec, app.MsgServiceRouter(), app.AccountKeeper) | ||||||||||||
|
||||||||||||
groupConfig := group.DefaultConfig() | ||||||||||||
/* | ||||||||||||
Example of setting group params: | ||||||||||||
groupConfig.MaxMetadataLen = 1000 | ||||||||||||
*/ | ||||||||||||
app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, groupConfig) | ||||||||||||
app.GroupKeeper = groupkeeper.NewKeeper(app.keys[group.StoreKey], app.appCodec, app.MsgServiceRouter(), app.AccountKeeper, groupConfig) | ||||||||||||
|
||||||||||||
// register the proposal types | ||||||||||||
govRouter := govv1beta1.NewRouter() | ||||||||||||
|
@@ -317,7 +296,7 @@ func NewSimApp( | |||||||||||
govConfig.MaxMetadataLen = 10000 | ||||||||||||
*/ | ||||||||||||
govKeeper := govkeeper.NewKeeper( | ||||||||||||
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, | ||||||||||||
app.appCodec, app.keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, | ||||||||||||
&stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig, | ||||||||||||
) | ||||||||||||
|
||||||||||||
|
@@ -327,13 +306,13 @@ func NewSimApp( | |||||||||||
), | ||||||||||||
) | ||||||||||||
// set the governance module account as the authority for conducting upgrades | ||||||||||||
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) | ||||||||||||
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, app.keys[upgradetypes.StoreKey], app.appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) | ||||||||||||
|
||||||||||||
app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) | ||||||||||||
app.NFTKeeper = nftkeeper.NewKeeper(app.keys[nftkeeper.StoreKey], app.appCodec, app.AccountKeeper, app.BankKeeper) | ||||||||||||
|
||||||||||||
// create evidence keeper with router | ||||||||||||
evidenceKeeper := evidencekeeper.NewKeeper( | ||||||||||||
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, | ||||||||||||
app.appCodec, app.keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, | ||||||||||||
) | ||||||||||||
// If evidence needs to be handled for the app, set routes in router here and seal | ||||||||||||
app.EvidenceKeeper = *evidenceKeeper | ||||||||||||
|
@@ -352,19 +331,18 @@ func NewSimApp( | |||||||||||
encodingConfig.TxConfig, | ||||||||||||
), | ||||||||||||
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), | ||||||||||||
capability.NewAppModule(appCodec, *app.CapabilityKeeper), | ||||||||||||
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), | ||||||||||||
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), | ||||||||||||
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), | ||||||||||||
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
feegrantmodule.NewAppModule(app.appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), | ||||||||||||
gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), | ||||||||||||
slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
upgrade.NewAppModule(app.UpgradeKeeper), | ||||||||||||
evidence.NewAppModule(app.EvidenceKeeper), | ||||||||||||
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
groupmodule.NewAppModule(app.appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
nftmodule.NewAppModule(app.appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
) | ||||||||||||
if err != nil { | ||||||||||||
panic(err) | ||||||||||||
|
@@ -402,27 +380,26 @@ func NewSimApp( | |||||||||||
// NOTE: this is not required apps that don't use the simulator for fuzz testing | ||||||||||||
// transactions | ||||||||||||
app.sm = module.NewSimulationManager( | ||||||||||||
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), | ||||||||||||
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), | ||||||||||||
capability.NewAppModule(appCodec, *app.CapabilityKeeper), | ||||||||||||
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), | ||||||||||||
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), | ||||||||||||
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), | ||||||||||||
bank.NewAppModule(app.appCodec, app.BankKeeper, app.AccountKeeper), | ||||||||||||
feegrantmodule.NewAppModule(app.appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), | ||||||||||||
gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper, nil), | ||||||||||||
staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), | ||||||||||||
distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), | ||||||||||||
params.NewAppModule(app.ParamsKeeper), | ||||||||||||
evidence.NewAppModule(app.EvidenceKeeper), | ||||||||||||
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
groupmodule.NewAppModule(app.appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
nftmodule.NewAppModule(app.appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), | ||||||||||||
) | ||||||||||||
|
||||||||||||
app.sm.RegisterStoreDecoders() | ||||||||||||
|
||||||||||||
// initialize stores | ||||||||||||
app.MountKVStores(keys) | ||||||||||||
app.MountMemoryStores(memKeys) | ||||||||||||
app.MountKVStores(app.keys) | ||||||||||||
app.MountMemoryStores(app.memKeys) | ||||||||||||
|
||||||||||||
// initialize BaseApp | ||||||||||||
app.SetTxDecoder(encodingConfig.TxConfig.TxDecoder()) | ||||||||||||
|
@@ -547,7 +524,18 @@ func (app *SimApp) GetTKey(storeKey string) *storetypes.TransientStoreKey { | |||||||||||
// | ||||||||||||
// NOTE: This is solely used for testing purposes. | ||||||||||||
func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { | ||||||||||||
return app.memKeys[storeKey] | ||||||||||||
msk := app.memKeys[storeKey] | ||||||||||||
if msk != nil { | ||||||||||||
return msk | ||||||||||||
} | ||||||||||||
|
||||||||||||
sk := app.UnsafeFindStoreKey(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. When would a mem key be found in the list of real store keys? 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.
Lines 115 to 119 in 8eaff8f
|
||||||||||||
memStoreKey, ok := sk.(*storetypes.MemoryStoreKey) | ||||||||||||
if !ok { | ||||||||||||
return nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
return memStoreKey | ||||||||||||
} | ||||||||||||
|
||||||||||||
// GetSubspace returns a param subspace for a given module name. | ||||||||||||
|
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.
Not sure if adding this to baseapp is the way to go
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.
What's the context 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.
runtime/builder uses baseApps'
MountStores
. Without this addition we get this errorUnrecognized store key type :*types.MemoryStoreKey
.I think that if we filter out any
MemoryStoreKey
s before calling this everything works just fine... I don't know enough about these things to know exactly what's up 😅cosmos-sdk/runtime/builder.go
Lines 27 to 41 in 8eaff8f
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.
nvm tried again removing it and it doesn't work
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'm not really sure about this code. I'd have to delegate to @aaronc 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.
I think this addition is correct. IMHO the fact that the multi-store doesn't know how to map store keys -> store types is a really strange and error prone. So this patch is sort of needed, but really the multi-store design should be cleaned up a bit