From 1c652b17219c7ecdae1e794475ce8edef04a8c91 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Wed, 6 Nov 2019 14:08:02 -0700 Subject: [PATCH] Merge PR #5240: x/evidence module implementation --- app.go | 114 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 32 deletions(-) diff --git a/app.go b/app.go index 53e671a1242d..e310e174906b 100644 --- a/app.go +++ b/app.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/crisis" distr "github.com/cosmos/cosmos-sdk/x/distribution" + "github.com/cosmos/cosmos-sdk/x/evidence" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/mint" @@ -54,6 +55,7 @@ var ( params.AppModuleBasic{}, crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, + evidence.AppModuleBasic{}, ) // module account permissions @@ -90,6 +92,9 @@ type SimApp struct { keys map[string]*sdk.KVStoreKey tkeys map[string]*sdk.TransientStoreKey + // subspaces + subspaces map[string]params.Subspace + // keepers AccountKeeper auth.AccountKeeper BankKeeper bank.Keeper @@ -101,6 +106,7 @@ type SimApp struct { GovKeeper gov.Keeper CrisisKeeper crisis.Keeper ParamsKeeper params.Keeper + EvidenceKeeper evidence.Keeper // the module manager mm *module.Manager @@ -121,9 +127,10 @@ func NewSimApp( bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetAppVersion(version.Version) - keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey, - supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, - gov.StoreKey, params.StoreKey) + keys := sdk.NewKVStoreKeys( + bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey, + distr.StoreKey, slashing.StoreKey, gov.StoreKey, params.StoreKey, evidence.StoreKey, + ) tkeys := sdk.NewTransientStoreKeys(params.TStoreKey) app := &SimApp{ @@ -132,39 +139,68 @@ func NewSimApp( invCheckPeriod: invCheckPeriod, keys: keys, tkeys: tkeys, + subspaces: make(map[string]params.Subspace), } // init params keeper and subspaces app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey], params.DefaultCodespace) - authSubspace := app.ParamsKeeper.Subspace(auth.DefaultParamspace) - bankSubspace := app.ParamsKeeper.Subspace(bank.DefaultParamspace) - stakingSubspace := app.ParamsKeeper.Subspace(staking.DefaultParamspace) - mintSubspace := app.ParamsKeeper.Subspace(mint.DefaultParamspace) - distrSubspace := app.ParamsKeeper.Subspace(distr.DefaultParamspace) - slashingSubspace := app.ParamsKeeper.Subspace(slashing.DefaultParamspace) - govSubspace := app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()) - crisisSubspace := app.ParamsKeeper.Subspace(crisis.DefaultParamspace) + app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) + app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) + app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) + app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace) + app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace) + app.subspaces[slashing.ModuleName] = app.ParamsKeeper.Subspace(slashing.DefaultParamspace) + app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable()) + app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) + app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace) // add keepers - app.AccountKeeper = auth.NewAccountKeeper(app.cdc, keys[auth.StoreKey], authSubspace, auth.ProtoBaseAccount) - app.BankKeeper = bank.NewBaseKeeper(app.AccountKeeper, bankSubspace, bank.DefaultCodespace, app.ModuleAccountAddrs()) - app.SupplyKeeper = supply.NewKeeper(app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms) - stakingKeeper := staking.NewKeeper(app.cdc, keys[staking.StoreKey], - app.SupplyKeeper, stakingSubspace, staking.DefaultCodespace) - app.MintKeeper = mint.NewKeeper(app.cdc, keys[mint.StoreKey], mintSubspace, &stakingKeeper, app.SupplyKeeper, auth.FeeCollectorName) - app.DistrKeeper = distr.NewKeeper(app.cdc, keys[distr.StoreKey], distrSubspace, &stakingKeeper, - app.SupplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs()) - app.SlashingKeeper = slashing.NewKeeper(app.cdc, keys[slashing.StoreKey], &stakingKeeper, - slashingSubspace, slashing.DefaultCodespace) - app.CrisisKeeper = crisis.NewKeeper(crisisSubspace, invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName) + app.AccountKeeper = auth.NewAccountKeeper( + app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, + ) + app.BankKeeper = bank.NewBaseKeeper( + app.AccountKeeper, app.subspaces[bank.ModuleName], bank.DefaultCodespace, + app.ModuleAccountAddrs(), + ) + app.SupplyKeeper = supply.NewKeeper( + app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms, + ) + stakingKeeper := staking.NewKeeper( + app.cdc, keys[staking.StoreKey], app.SupplyKeeper, app.subspaces[staking.ModuleName], + staking.DefaultCodespace) + app.MintKeeper = mint.NewKeeper( + app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, + app.SupplyKeeper, auth.FeeCollectorName, + ) + app.DistrKeeper = distr.NewKeeper( + app.cdc, keys[distr.StoreKey], app.subspaces[distr.ModuleName], &stakingKeeper, + app.SupplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs(), + ) + app.SlashingKeeper = slashing.NewKeeper( + app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], slashing.DefaultCodespace, + ) + app.CrisisKeeper = crisis.NewKeeper( + app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, + ) + + // create evidence keeper with router + evidenceKeeper := evidence.NewKeeper( + app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], evidence.DefaultCodespace, + ) + evidenceRouter := evidence.NewRouter() + // TODO: Register evidence routes. + evidenceKeeper.SetRouter(evidenceRouter) + app.EvidenceKeeper = *evidenceKeeper // register the proposal types govRouter := gov.NewRouter() govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler). AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)) - app.GovKeeper = gov.NewKeeper(app.cdc, keys[gov.StoreKey], govSubspace, - app.SupplyKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter) + app.GovKeeper = gov.NewKeeper( + app.cdc, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.SupplyKeeper, + &stakingKeeper, gov.DefaultCodespace, govRouter, + ) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks @@ -185,22 +221,21 @@ func NewSimApp( distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper), slashing.NewAppModule(app.SlashingKeeper, app.StakingKeeper), staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper), + evidence.NewAppModule(app.EvidenceKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName) - app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName) // NOTE: The genutils moodule must occur after staking so that pools are // properly initialized with tokens from genesis accounts. app.mm.SetOrderInitGenesis( - auth.ModuleName, distr.ModuleName, staking.ModuleName, - bank.ModuleName, slashing.ModuleName, gov.ModuleName, - mint.ModuleName, supply.ModuleName, crisis.ModuleName, - genutil.ModuleName, + auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName, + slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName, + crisis.ModuleName, genutil.ModuleName, evidence.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -239,6 +274,7 @@ func NewSimApp( cmn.Exit(err.Error()) } } + return app } @@ -274,21 +310,35 @@ func (app *SimApp) ModuleAccountAddrs() map[string]bool { return modAccAddrs } -// Codec returns simapp's codec +// Codec returns SimApp's codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. func (app *SimApp) Codec() *codec.Codec { return app.cdc } -// GetKey returns the KVStoreKey for the provided store key +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. func (app *SimApp) GetKey(storeKey string) *sdk.KVStoreKey { return app.keys[storeKey] } -// GetTKey returns the TransientStoreKey for the provided store key +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. func (app *SimApp) GetTKey(storeKey string) *sdk.TransientStoreKey { return app.tkeys[storeKey] } +// GetSubspace returns a param subspace for a given module name. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SimApp) GetSubspace(moduleName string) params.Subspace { + return app.subspaces[moduleName] +} + // GetMaccPerms returns a copy of the module account permissions func GetMaccPerms() map[string][]string { dupMaccPerms := make(map[string][]string)