From 7edb178e39068fbe18e0f097801f93088c97c70d Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 27 Jan 2020 09:50:53 +0000 Subject: [PATCH] app, simapp - implement PR5299 - https://github.com/cosmos/cosmos-sdk/pull/5299 --- app/app.go | 20 +++++++++++++++++++- simapp/app.go | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 110b55a3..4b6bf7fa 100644 --- a/app/app.go +++ b/app/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/params" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -56,6 +57,7 @@ var ( enterprise.AppModule{}, wrkchain.AppModule{}, beacon.AppModule{}, + evidence.AppModuleBasic{}, ) // account permissions maccPerms = map[string][]string{ @@ -74,6 +76,7 @@ func MakeCodec() *codec.Codec { ModuleBasics.RegisterCodec(cdc) sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) + codec.RegisterEvidences(cdc) return cdc } @@ -103,6 +106,7 @@ type mainchainApp struct { wrkChainKeeper wrkchain.Keeper enterpriseKeeper enterprise.Keeper beaconKeeper beacon.Keeper + evidenceKeeper evidence.Keeper // Module Manager mm *module.Manager @@ -124,7 +128,7 @@ func NewMainchainApp( keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, params.StoreKey, - wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey) + wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey, evidence.StoreKey,) tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey) @@ -151,6 +155,7 @@ func NewMainchainApp( app.subspaces[enterprise.ModuleName] = app.paramsKeeper.Subspace(enterprise.DefaultParamspace) app.subspaces[wrkchain.ModuleName] = app.paramsKeeper.Subspace(wrkchain.DefaultParamspace) app.subspaces[beacon.ModuleName] = app.paramsKeeper.Subspace(beacon.DefaultParamspace) + app.subspaces[evidence.ModuleName] = app.paramsKeeper.Subspace(evidence.DefaultParamspace) // The AccountKeeper handles address -> account lookups app.accountKeeper = auth.NewAccountKeeper( @@ -214,6 +219,17 @@ func NewMainchainApp( auth.FeeCollectorName, ) + // create evidence keeper with evidence router + evidenceKeeper := evidence.NewKeeper( + app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &stakingKeeper, app.slashingKeeper, + ) + evidenceRouter := evidence.NewRouter() + + // TODO: register evidence routes + evidenceKeeper.SetRouter(evidenceRouter) + + app.evidenceKeeper = *evidenceKeeper + // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.stakingKeeper = *stakingKeeper.SetHooks( @@ -258,6 +274,7 @@ func NewMainchainApp( enterprise.NewAppModule(app.enterpriseKeeper), wrkchain.NewAppModule(app.wrkChainKeeper), beacon.NewAppModule(app.beaconKeeper), + evidence.NewAppModule(app.evidenceKeeper), ) app.mm.SetOrderBeginBlockers(enterprise.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName) @@ -279,6 +296,7 @@ func NewMainchainApp( supply.ModuleName, crisis.ModuleName, genutil.ModuleName, + evidence.ModuleName, ) app.mm.RegisterInvariants(&app.crisisKeeper) diff --git a/simapp/app.go b/simapp/app.go index e6ccee4a..ff5b6d0f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -19,6 +19,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/params" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -57,6 +58,7 @@ var ( enterprise.AppModule{}, wrkchain.AppModule{}, beacon.AppModule{}, + evidence.AppModuleBasic{}, ) // module account permissions @@ -77,6 +79,7 @@ func MakeCodec() *codec.Codec { vesting.RegisterCodec(cdc) sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) + codec.RegisterEvidences(cdc) return cdc } @@ -109,6 +112,7 @@ type UndSimApp struct { WrkChainKeeper wrkchain.Keeper EnterpriseKeeper enterprise.Keeper BeaconKeeper beacon.Keeper + EvidenceKeeper evidence.Keeper // the module manager mm *module.Manager @@ -131,7 +135,7 @@ func NewUndSimApp( keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, - params.StoreKey, wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey) + params.StoreKey, wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey, evidence.StoreKey,) tKeys := sdk.NewTransientStoreKeys(params.TStoreKey) app := &UndSimApp{ @@ -155,6 +159,7 @@ func NewUndSimApp( app.subspaces[enterprise.ModuleName] = app.ParamsKeeper.Subspace(enterprise.DefaultParamspace) app.subspaces[wrkchain.ModuleName] = app.ParamsKeeper.Subspace(wrkchain.DefaultParamspace) app.subspaces[beacon.ModuleName] = app.ParamsKeeper.Subspace(beacon.DefaultParamspace) + app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace) // add keepers app.AccountKeeper = auth.NewAccountKeeper( @@ -215,6 +220,17 @@ func NewUndSimApp( auth.FeeCollectorName, ) + // create evidence keeper with evidence router + evidenceKeeper := evidence.NewKeeper( + app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &stakingKeeper, app.SlashingKeeper, + ) + evidenceRouter := evidence.NewRouter() + + // TODO: register evidence routes + evidenceKeeper.SetRouter(evidenceRouter) + + app.EvidenceKeeper = *evidenceKeeper + // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks app.StakingKeeper = *stakingKeeper.SetHooks( @@ -259,6 +275,7 @@ func NewUndSimApp( enterprise.NewAppModule(app.EnterpriseKeeper), wrkchain.NewAppModule(app.WrkChainKeeper), beacon.NewAppModule(app.BeaconKeeper), + evidence.NewAppModule(app.EvidenceKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -274,7 +291,7 @@ func NewUndSimApp( auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName, slashing.ModuleName, wrkchain.ModuleName, beacon.ModuleName, enterprise.ModuleName, mint.ModuleName, supply.ModuleName, - crisis.ModuleName, genutil.ModuleName, + crisis.ModuleName, genutil.ModuleName, evidence.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper)