diff --git a/app/consumer-democracy/app.go b/app/consumer-democracy/app.go index 9d62521041..ae437e1ac1 100644 --- a/app/consumer-democracy/app.go +++ b/app/consumer-democracy/app.go @@ -8,6 +8,8 @@ import ( "os" "path/filepath" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -417,6 +419,7 @@ func New( &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, + app.StakingKeeper, app.SlashingKeeper, app.BankKeeper, app.AccountKeeper, @@ -436,7 +439,7 @@ func New( // register slashing module StakingHooks to the consumer keeper app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks()) - consumerModule := consumer.NewAppModule(app.ConsumerKeeper) + consumerModule := consumer.NewAppModule(app.ConsumerKeeper, app.StakingKeeper) app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, @@ -483,7 +486,7 @@ func New( mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper), ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName), - ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper), upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), params.NewAppModule(app.ParamsKeeper), @@ -506,6 +509,8 @@ func New( distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, + consumertypes.ModuleName, // Note: consumer beginblocker before staking module + stakingtypes.ModuleName, stakingtypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -517,11 +522,11 @@ func New( vestingtypes.ModuleName, ibctransfertypes.ModuleName, ibchost.ModuleName, - consumertypes.ModuleName, ) app.MM.SetOrderEndBlockers( crisistypes.ModuleName, govtypes.ModuleName, + consumertypes.ModuleName, // Note: consumer endblocker before staking module stakingtypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, @@ -537,7 +542,6 @@ func New( vestingtypes.ModuleName, ibctransfertypes.ModuleName, ibchost.ModuleName, - consumertypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -550,6 +554,7 @@ func New( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, + consumertypes.ModuleName, // Note: consumer initiation before staking module distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, @@ -564,7 +569,6 @@ func New( vestingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, - consumertypes.ModuleName, ) app.MM.RegisterInvariants(&app.CrisisKeeper) @@ -584,7 +588,7 @@ func New( feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), ccvgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, IsProposalWhitelisted), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), - ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper), ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), params.NewAppModule(app.ParamsKeeper), @@ -625,6 +629,7 @@ func New( app.UpgradeKeeper.SetUpgradeHandler( upgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams()) fromVM := make(map[string]uint64) @@ -633,6 +638,23 @@ func New( fromVM[moduleName] = eachModule.ConsensusVersion() } + // TODO: should have a way to read from current node home + userHomeDir, err := os.UserHomeDir() + if err != nil { + stdlog.Println("Failed to get home dir %2", err) + } + nodeHome := userHomeDir + "/.sovereign/config/genesis.json" + appState, _, err := genutiltypes.GenesisStateFromGenFile(nodeHome) + if err != nil { + return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err) + } + + var consumerGenesis = consumertypes.GenesisState{} + appCodec.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis) + + consumerGenesis.PreCCV = true + app.ConsumerKeeper.InitGenesis(ctx, &consumerGenesis) + ctx.Logger().Info("start to run module migrations...") return app.MM.RunMigrations(ctx, app.configurator, fromVM) @@ -645,7 +667,9 @@ func New( } if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := store.StoreUpgrades{} + storeUpgrades := store.StoreUpgrades{ + Added: []string{consumertypes.ModuleName}, + } // configure store loader that checks if version == upgradeHeight and applies store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) diff --git a/app/consumer/app.go b/app/consumer/app.go index 00cfe5b27d..1f00fa0c11 100644 --- a/app/consumer/app.go +++ b/app/consumer/app.go @@ -334,6 +334,7 @@ func New( &app.IBCKeeper.PortKeeper, app.IBCKeeper.ConnectionKeeper, app.IBCKeeper.ClientKeeper, + nil, app.SlashingKeeper, app.BankKeeper, app.AccountKeeper, @@ -344,7 +345,7 @@ func New( // register slashing module Slashing hooks to the consumer keeper app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks()) - consumerModule := ibcconsumer.NewAppModule(app.ConsumerKeeper) + consumerModule := ibcconsumer.NewAppModule(app.ConsumerKeeper, nil) app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, diff --git a/app/sovereign/app.go b/app/sovereign/app.go new file mode 100644 index 0000000000..66e8503009 --- /dev/null +++ b/app/sovereign/app.go @@ -0,0 +1,808 @@ +package app + +import ( + "io" + "os" + "path/filepath" + + porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" + "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/server/api" + "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/capability" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-go/v4/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v4/modules/core" + ibcclient "github.com/cosmos/ibc-go/v4/modules/core/02-client" + ibcclientclient "github.com/cosmos/ibc-go/v4/modules/core/02-client/client" + ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" + ibcporttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" + ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" + ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" + "github.com/spf13/cast" + "github.com/tendermint/spm/cosmoscmd" + abci "github.com/tendermint/tendermint/abci/types" + tmjson "github.com/tendermint/tendermint/libs/json" + "github.com/tendermint/tendermint/libs/log" + tmos "github.com/tendermint/tendermint/libs/os" + dbm "github.com/tendermint/tm-db" + + // add mint + mint "github.com/cosmos/cosmos-sdk/x/mint" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + + ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts" + icacontroller "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types" +) + +const ( + AccountAddressPrefix = "cosmos" + AppName = "interchain-security-sovereign" + Version = "3.0.0" +) + +// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals + +func getGovProposalHandlers() []govclient.ProposalHandler { + var govProposalHandlers []govclient.ProposalHandler + // this line is used by starport scaffolding # stargate/app/govProposalHandlers + + govProposalHandlers = append(govProposalHandlers, + paramsclient.ProposalHandler, + distrclient.ProposalHandler, + upgradeclient.ProposalHandler, + upgradeclient.CancelProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + // this line is used by starport scaffolding # stargate/app/govProposalHandler + ) + + return govProposalHandlers +} + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string + + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic(getGovProposalHandlers()...), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + ibc.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + ica.AppModuleBasic{}, + mint.AppModuleBasic{}, + ) + + // module account permissions + maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + // mint module needs burn access to remove excess validator tokens (it overallocates, then burns) + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + icatypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + // this line is used by starport scaffolding # stargate/app/maccPerms + } +) + +var ( + _ servertypes.Application = (*SovereignApp)(nil) +) + +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) +} + +// SovereignApp extends an ABCI application, but with most of its parameters exported. +// They are exported for convenience in creating helper functions, as object +// capabilities aren't needed for testing. +type SovereignApp struct { + *baseapp.BaseApp + + cdc *codec.LegacyAmino + appCodec codec.Codec + interfaceRegistry types.InterfaceRegistry + + invCheckPeriod uint + + // keys to access the substores + keys map[string]*sdk.KVStoreKey + tkeys map[string]*sdk.TransientStoreKey + memKeys map[string]*sdk.MemoryStoreKey + + // keepers + AccountKeeper authkeeper.AccountKeeper + AuthzKeeper authzkeeper.Keeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + // MonitoringKeeper monitoringpkeeper.Keeper + ICAControllerKeeper icacontrollerkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + // ScopedMonitoringKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper + + ScopedStakeibcKeeper capabilitykeeper.ScopedKeeper + + ScopedRecordsKeeper capabilitykeeper.ScopedKeeper + ScopedIcacallbacksKeeper capabilitykeeper.ScopedKeeper + // this line is used by starport scaffolding # stargate/app/keeperDeclaration + + mm *module.Manager + sm *module.SimulationManager + configurator module.Configurator +} + +// RUN GOSEC +// New returns a reference to an initialized blockchain app +func New( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + loadLatest bool, + skipUpgradeHeights map[int64]bool, + homePath string, + invCheckPeriod uint, + encodingConfig cosmoscmd.EncodingConfig, + appOpts servertypes.AppOptions, + baseAppOptions ...func(*baseapp.BaseApp), +) cosmoscmd.App { + appCodec := encodingConfig.Marshaler + cdc := encodingConfig.Amino + interfaceRegistry := encodingConfig.InterfaceRegistry + + bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) + bApp.SetCommitMultiStoreTracer(traceStore) + bApp.SetVersion(Version) + bApp.SetInterfaceRegistry(interfaceRegistry) + + keys := sdk.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, // monitoringptypes.StoreKey, + icacontrollertypes.StoreKey, icahosttypes.StoreKey, + authzkeeper.StoreKey, + // this line is used by starport scaffolding # stargate/app/storeKey + ) + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) + memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + + app := &SovereignApp{ + BaseApp: bApp, + cdc: cdc, + appCodec: appCodec, + interfaceRegistry: interfaceRegistry, + invCheckPeriod: invCheckPeriod, + keys: keys, + tkeys: tkeys, + memKeys: memKeys, + } + + app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) + + // set the BaseApp's parameter store + bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable())) + + // add capability keeper and ScopeToModule for ibc module + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + + // grant capabilities for the ibc and ibc-transfer modules + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) + scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + // this line is used by starport scaffolding # stargate/app/scopedKeeper + + // add keepers + app.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, + ) + + app.AuthzKeeper = authzkeeper.NewKeeper( + keys[authzkeeper.StoreKey], + appCodec, + app.BaseApp.MsgServiceRouter(), + ) + + app.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), + ) + stakingKeeper := stakingkeeper.NewKeeper( + appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), + ) + + app.DistrKeeper = distrkeeper.NewKeeper( + appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper, + &stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(), + ) + + app.MintKeeper = mintkeeper.NewKeeper( + appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, + app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, + ) + + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, 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.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp) + + // 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()), + ) + + // ... other modules keepers + + // Create IBC Keeper + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, + ) + + // Create Transfer Keepers + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, + ) + transferModule := transfer.NewAppModule(app.TransferKeeper) + transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) + + // Create evidence Keeper for to register the IBC light client misbehaviour evidence route + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, 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 + + // TODO(TEST-20): look for all lines that include 'monitoring' in this file! there are a few places this + // is commented out + // scopedMonitoringKeeper := app.CapabilityKeeper.ScopeToModule(monitoringptypes.ModuleName) + // app.MonitoringKeeper = *monitoringpkeeper.NewKeeper( + // appCodec, + // keys[monitoringptypes.StoreKey], + // keys[monitoringptypes.MemStoreKey], + // app.GetSubspace(monitoringptypes.ModuleName), + // app.StakingKeeper, + // app.IBCKeeper.ClientKeeper, + // app.IBCKeeper.ConnectionKeeper, + // app.IBCKeeper.ChannelKeeper, + // &app.IBCKeeper.PortKeeper, + // scopedMonitoringKeeper, + // ) + // monitoringModule := monitoringp.NewAppModule(appCodec, app.MonitoringKeeper) + + // Note: must be above app.StakeibcKeeper + app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( + appCodec, keys[icacontrollertypes.StoreKey], app.GetSubspace(icacontrollertypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + scopedICAControllerKeeper, app.MsgServiceRouter(), + ) + + // Register Gov (must be registerd after stakeibc) + govRouter := govtypes.NewRouter() + govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). + AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). + AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)) + + app.GovKeeper = govkeeper.NewKeeper( + appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, + &stakingKeeper, govRouter, + ) + + // this line is used by starport scaffolding # stargate/app/keeperDefinition + + // create IBC middleware stacks by combining middleware with base application + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), + ) + icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper) + + // Create the middleware stacks + + // Stack one contains + // - IBC + // - ICA + // - icacallbacks + // - stakeibc + // - base app + var icamiddlewareStack porttypes.IBCModule + icamiddlewareStack = icacontroller.NewIBCMiddleware(icamiddlewareStack, app.ICAControllerKeeper) + icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) + + // Create static IBC router, add transfer route, then set and seal it + ibcRouter := ibcporttypes.NewRouter() + ibcRouter. + AddRoute(ibctransfertypes.ModuleName, transferIBCModule). + AddRoute(icacontrollertypes.SubModuleName, icamiddlewareStack). + AddRoute(icahosttypes.SubModuleName, icaHostIBCModule) + // this line is used by starport scaffolding # ibc/app/router + app.IBCKeeper.SetRouter(ibcRouter) + + /**** Module Options ****/ + + // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment + // we prefer to be more strict in what arguments the modules expect. + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + + app.mm = module.NewManager( + genutil.NewAppModule( + app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, + encodingConfig.TxConfig, + ), + auth.NewAppModule(appCodec, app.AccountKeeper, nil), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), + capability.NewAppModule(appCodec, *app.CapabilityKeeper), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), + 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), + upgrade.NewAppModule(app.UpgradeKeeper), + evidence.NewAppModule(app.EvidenceKeeper), + ibc.NewAppModule(app.IBCKeeper), + params.NewAppModule(app.ParamsKeeper), + transferModule, + // monitoringModule, + icaModule, + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + // this line is used by starport scaffolding # stargate/app/appModule + ) + + // 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. + // NOTE: staking module is required if HistoricalEntries param > 0 + app.mm.SetOrderBeginBlockers( + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + vestingtypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + govtypes.ModuleName, + crisistypes.ModuleName, + genutiltypes.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + // monitoringptypes.ModuleName, + icatypes.ModuleName, + authz.ModuleName, + // this line is used by starport scaffolding # stargate/app/beginBlockers + ) + + app.mm.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + vestingtypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + // monitoringptypes.ModuleName, + icatypes.ModuleName, + authz.ModuleName, + // this line is used by starport scaffolding # stargate/app/endBlockers + ) + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + app.mm.SetOrderInitGenesis( + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + vestingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + crisistypes.ModuleName, + ibchost.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + ibctransfertypes.ModuleName, + feegrant.ModuleName, + // monitoringptypes.ModuleName, + icatypes.ModuleName, + authz.ModuleName, + // this line is used by starport scaffolding # stargate/app/initGenesis + ) + + app.mm.RegisterInvariants(&app.CrisisKeeper) + app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + app.mm.RegisterServices(app.configurator) + app.setupUpgradeHandlers() + + // create the simulation manager and define the order of the modules for deterministic simulations + // 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), + // 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), + // params.NewAppModule(app.ParamsKeeper), + // evidence.NewAppModule(app.EvidenceKeeper), + // ibc.NewAppModule(app.IBCKeeper), + // transferModule, + // // monitoringModule, + // stakeibcModule, + // epochsModule, + // interchainQueryModule, + // recordsModule, + // icacallbacksModule, + // this line is used by starport scaffolding # stargate/app/appModule + // ) + // app.sm.RegisterStoreDecoders() + + // initialize stores + app.MountKVStores(keys) + app.MountTransientStores(tkeys) + app.MountMemoryStores(memKeys) + + // initialize BaseApp + app.SetInitChainer(app.InitChainer) + app.SetBeginBlocker(app.BeginBlocker) + + anteHandler, err := ante.NewAnteHandler( + ante.HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + ) + if err != nil { + panic(err) + } + + app.SetAnteHandler(anteHandler) + app.SetEndBlocker(app.EndBlocker) + + if loadLatest { + if err := app.LoadLatestVersion(); err != nil { + tmos.Exit(err.Error()) + } + } + + app.ScopedIBCKeeper = scopedIBCKeeper + app.ScopedTransferKeeper = scopedTransferKeeper + // app.ScopedMonitoringKeeper = scopedMonitoringKeeper + app.ScopedICAControllerKeeper = scopedICAControllerKeeper + app.ScopedICAHostKeeper = scopedICAHostKeeper + // this line is used by starport scaffolding # stargate/app/beforeInitReturn + + return app +} + +// Name returns the name of the App +func (app *SovereignApp) Name() string { return app.BaseApp.Name() } + +// GetBaseApp returns the base app of the application +func (app *SovereignApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp } + +// GetStakingKeeper implements the TestingApp interface. +func (app *SovereignApp) GetStakingKeeper() stakingkeeper.Keeper { + return app.StakingKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *SovereignApp) GetTransferKeeper() *ibctransferkeeper.Keeper { + return &app.TransferKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *SovereignApp) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *SovereignApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *SovereignApp) GetTxConfig() client.TxConfig { + cfg := MakeEncodingConfig() + return cfg.TxConfig +} + +// BeginBlocker application updates every begin block +func (app *SovereignApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { + return app.mm.BeginBlock(ctx, req) +} + +// EndBlocker application updates every end block +func (app *SovereignApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { + return app.mm.EndBlock(ctx, req) +} + +// InitChainer application update at chain initialization +func (app *SovereignApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + var genesisState GenesisState + if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) + return app.mm.InitGenesis(ctx, app.appCodec, genesisState) +} + +// LoadHeight loads a particular height +func (app *SovereignApp) LoadHeight(height int64) error { + return app.LoadVersion(height) +} + +// ModuleAccountAddrs returns all the app's module account addresses. +func (app *SovereignApp) ModuleAccountAddrs() map[string]bool { + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + + return modAccAddrs +} + +// LegacyAmino returns SimApp's amino 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 *SovereignApp) LegacyAmino() *codec.LegacyAmino { + return app.cdc +} + +// AppCodec returns an app 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 *SovereignApp) AppCodec() codec.Codec { + return app.appCodec +} + +// InterfaceRegistry returns an InterfaceRegistry +func (app *SovereignApp) InterfaceRegistry() types.InterfaceRegistry { + return app.interfaceRegistry +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SovereignApp) GetKey(storeKey string) *sdk.KVStoreKey { + return app.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SovereignApp) GetTKey(storeKey string) *sdk.TransientStoreKey { + return app.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (app *SovereignApp) GetMemKey(storeKey string) *sdk.MemoryStoreKey { + return app.memKeys[storeKey] +} + +// GetSubspace returns a param subspace for a given module name. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SovereignApp) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// RegisterAPIRoutes registers all application module routes with the provided +// API server. +func (app *SovereignApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { + clientCtx := apiSvr.ClientCtx + rpc.RegisterRoutes(clientCtx, apiSvr.Router) + // Register legacy tx routes. + authrest.RegisterTxRoutes(clientCtx, apiSvr.Router) + // Register new tx routes from grpc-gateway. + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + // Register new tendermint queries routes from grpc-gateway. + tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register legacy and grpc-gateway routes for all modules. + ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router) + ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) +} + +// RegisterTxService implements the Application.RegisterTxService method. +func (app *SovereignApp) RegisterTxService(clientCtx client.Context) { + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) +} + +// RegisterTendermintService implements the Application.RegisterTendermintService method. +func (app *SovereignApp) RegisterTendermintService(clientCtx client.Context) { + tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry) +} + +// GetMaccPerms returns a copy of the module account permissions +func GetMaccPerms() map[string][]string { + dupMaccPerms := make(map[string][]string) + for k, v := range maccPerms { + dupMaccPerms[k] = v + } + return dupMaccPerms +} + +// initParamsKeeper init params keeper and its subspaces +func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + // paramsKeeper.Subspace(monitoringptypes.ModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) + // this line is used by starport scaffolding # stargate/app/paramSubspace + + return paramsKeeper +} + +// SimulationManager implements the SimulationApp interface +func (app *SovereignApp) SimulationManager() *module.SimulationManager { + return app.sm +} diff --git a/app/sovereign/encoding.go b/app/sovereign/encoding.go new file mode 100644 index 0000000000..60535a84cf --- /dev/null +++ b/app/sovereign/encoding.go @@ -0,0 +1,38 @@ +package app + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/x/auth/tx" +) + +// This data structure (EncodingConfig) is heavily inspired by Quicksilver. https://github.com/ingenuity-build/quicksilver/blob/main/app/encoding.go +type EncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + Marshaler codec.Codec + TxConfig client.TxConfig + Amino *codec.LegacyAmino +} + +// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration. +func MakeEncodingConfig() EncodingConfig { + amino := codec.NewLegacyAmino() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := codec.NewProtoCodec(interfaceRegistry) + txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) + + encodingConfig := EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxConfig: txCfg, + Amino: amino, + } + + std.RegisterLegacyAminoCodec(encodingConfig.Amino) + std.RegisterInterfaces(encodingConfig.InterfaceRegistry) + ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) + ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) + return encodingConfig +} diff --git a/app/sovereign/export.go b/app/sovereign/export.go new file mode 100644 index 0000000000..3c5a7e14d7 --- /dev/null +++ b/app/sovereign/export.go @@ -0,0 +1,201 @@ +package app + +import ( + "encoding/json" + "log" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// ExportAppStateAndValidators exports the state of the application for a genesis +// file. +func (app *SovereignApp) ExportAppStateAndValidators( + forZeroHeight bool, jailAllowedAddrs []string, +) (servertypes.ExportedApp, error) { + // as if they could withdraw from the start of the next block + ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + + // We export at last height + 1, because that's the height at which + // Tendermint will start InitChain. + height := app.LastBlockHeight() + 1 + if forZeroHeight { + height = 0 + app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) + } + + genState := app.mm.ExportGenesis(ctx, app.appCodec) + appState, err := json.MarshalIndent(genState, "", " ") + if err != nil { + return servertypes.ExportedApp{}, err + } + + validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + if err != nil { + return servertypes.ExportedApp{}, err + } + return servertypes.ExportedApp{ + AppState: appState, + Validators: validators, + Height: height, + ConsensusParams: app.BaseApp.GetConsensusParams(ctx), + }, nil +} + +// prepare for fresh start at zero height +// NOTE zero height genesis is a temporary feature which will be deprecated +// +// in favour of export at a block height +func (app *SovereignApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { + applyAllowedAddrs := false + + // check if there is a allowed address list + if len(jailAllowedAddrs) > 0 { + applyAllowedAddrs = true + } + + allowedAddrsMap := make(map[string]bool) + + for _, addr := range jailAllowedAddrs { + _, err := sdk.ValAddressFromBech32(addr) + if err != nil { + log.Fatal(err) + } + allowedAddrsMap[addr] = true + } + + /* Just to be safe, assert the invariants on current state. */ + app.CrisisKeeper.AssertInvariants(ctx) + + /* Handle fee distribution state. */ + + // withdraw all validator commission + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + if err != nil { + panic(err) + } + + return false + }) + + // withdraw all delegator rewards + dels := app.StakingKeeper.GetAllDelegations(ctx) + for _, delegation := range dels { + valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) + if err != nil { + panic(err) + } + + delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) + if err != nil { + panic(err) + } + _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) + } + + // clear validator slash events + app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) + + // clear validator historical rewards + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + + // set context height to zero + height := ctx.BlockHeight() + ctx = ctx.WithBlockHeight(0) + + // reinitialize all validators + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + // donate any unwithdrawn outstanding reward fraction tokens to the community pool + scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) + feePool := app.DistrKeeper.GetFeePool(ctx) + feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) + app.DistrKeeper.SetFeePool(ctx, feePool) + + app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + return false + }) + + // reinitialize all delegations + for _, del := range dels { + valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) + if err != nil { + panic(err) + } + delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress) + if err != nil { + panic(err) + } + app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr) + app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) + } + + // reset context height + ctx = ctx.WithBlockHeight(height) + + /* Handle staking state. */ + + // iterate through redelegations, reset creation height + app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + for i := range red.Entries { + red.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetRedelegation(ctx, red) + return false + }) + + // iterate through unbonding delegations, reset creation height + app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + for i := range ubd.Entries { + ubd.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + return false + }) + + // Iterate through validators by power descending, reset bond heights, and + // update bond intra-tx counters. + store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) + iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + counter := int16(0) + + for ; iter.Valid(); iter.Next() { + addr := sdk.ValAddress(iter.Key()[1:]) + validator, found := app.StakingKeeper.GetValidator(ctx, addr) + if !found { + panic("expected validator, not found") + } + + validator.UnbondingHeight = 0 + if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { + validator.Jailed = true + } + + app.StakingKeeper.SetValidator(ctx, validator) + counter++ + } + + iter.Close() + + _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + log.Fatal(err) + } + + /* Handle slashing state. */ + + // reset start height on signing infos + app.SlashingKeeper.IterateValidatorSigningInfos( + ctx, + func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { + info.StartHeight = 0 + app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) + return false + }, + ) +} diff --git a/app/sovereign/genesis.go b/app/sovereign/genesis.go new file mode 100644 index 0000000000..340cd801a8 --- /dev/null +++ b/app/sovereign/genesis.go @@ -0,0 +1,20 @@ +package app + +import ( + "encoding/json" +) + +// The genesis state of the blockchain is represented here as a map of raw json +// messages key'd by a identifier string. +// The identifier is used to determine which module genesis information belongs +// to so it may be appropriately routed during init chain. +// Within this application default genesis information is retrieved from +// the ModuleBasicManager which populates json from each BasicModule +// object provided to it during init. +type GenesisState map[string]json.RawMessage + +// NewDefaultGenesisState generates the default state for the application. +func NewDefaultGenesisState() GenesisState { + encCfg := MakeEncodingConfig() + return ModuleBasics.DefaultGenesis(encCfg.Marshaler) +} diff --git a/app/sovereign/upgrades.go b/app/sovereign/upgrades.go new file mode 100644 index 0000000000..734c2b3b2f --- /dev/null +++ b/app/sovereign/upgrades.go @@ -0,0 +1,31 @@ +package app + +import ( + "fmt" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +func (app *SovereignApp) setupUpgradeHandlers() { + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err)) + } + + if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + return + } + + var storeUpgrades *storetypes.StoreUpgrades + + switch upgradeInfo.Name { + // no store upgrades + case "v3": + storeUpgrades = &storetypes.StoreUpgrades{} + } + + if storeUpgrades != nil { + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) + } +} diff --git a/app/sovereign/upgrades/v3/upgrades.go b/app/sovereign/upgrades/v3/upgrades.go new file mode 100644 index 0000000000..39cfa318f1 --- /dev/null +++ b/app/sovereign/upgrades/v3/upgrades.go @@ -0,0 +1,23 @@ +package v3 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// Note: ensure these values are properly set before running upgrade +var ( + UpgradeName = "v3" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v3 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + newVm, err := mm.RunMigrations(ctx, configurator, vm) + return newVm, err + } +} diff --git a/cmd/interchain-security-sd/main.go b/cmd/interchain-security-sd/main.go new file mode 100644 index 0000000000..4dc2748ad0 --- /dev/null +++ b/cmd/interchain-security-sd/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + + "github.com/cosmos/cosmos-sdk/server" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + app "github.com/cosmos/interchain-security/app/sovereign" + "github.com/tendermint/spm/cosmoscmd" +) + +func main() { + rootCmd, _ := cosmoscmd.NewRootCmd( + app.AppName, + app.AccountAddressPrefix, + app.DefaultNodeHome, + app.AppName, + app.ModuleBasics, + app.New, + // this line is used by starport scaffolding # root/arguments + ) + + if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { + switch e := err.(type) { + case server.ErrorCode: + os.Exit(e.Code) + + default: + os.Exit(1) + } + } +} diff --git a/proto/interchain_security/ccv/consumer/v1/genesis.proto b/proto/interchain_security/ccv/consumer/v1/genesis.proto index 6adbc79f54..043556fee3 100644 --- a/proto/interchain_security/ccv/consumer/v1/genesis.proto +++ b/proto/interchain_security/ccv/consumer/v1/genesis.proto @@ -40,6 +40,7 @@ message GenesisState { // LastTransmissionBlockHeight nil on new chain, filled in on restart. interchain_security.ccv.consumer.v1.LastTransmissionBlockHeight last_transmission_block_height = 12 [ (gogoproto.nullable) = false ]; + bool preCCV = 13; // flag indicating whether the consumer CCV module starts in pre-CCV state } // HeightValsetUpdateID defines the genesis information for the mapping diff --git a/tests/sovereign_consumer_upgrade_local/README.md b/tests/sovereign_consumer_upgrade_local/README.md new file mode 100644 index 0000000000..05a841f80b --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/README.md @@ -0,0 +1,48 @@ +## How to run consumer chain + +### Pre-install + +Binaries: + +- interchain-security-pd - [Interchain security](https://github.com/cosmos/interchain-security) version: v0.2.1 +- consumerd +- hermes(version: v0.15.0) + +### Commands + +Copy `start_consumer.sh`, `start_provider.sh` from one of the directories and execute following commands. + +```sh +rm -rf /Users/admin/.provider1 +rm -rf /Users/admin/.provider +rm -rf /Users/admin/.consumer1 +rm -rf /Users/admin/.consumer +rm -rf /Users/admin/.sovereign +sh run.sh +``` + +### Genesis modification script for consumer chain + +```sh +# Add ccv section +if ! ./$PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$CONSUMER_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$CONSUMER_HOME"/config/genesis.json "$CONSUMER_HOME"/consumer_section.json > "$CONSUMER_HOME"/genesis_consumer.json && \ + mv "$CONSUMER_HOME"/genesis_consumer.json "$CONSUMER_HOME"/config/genesis.json +``` + +### Process of execution of soft upgrade from sovereign chain to consumer chain + +1. Start provider chain and register consumer chain +2. Build normal sovereign chain daemon +3. Start single validator sovereign chain +4. Provider chain validator with sovereign chain +5. Raise Upgrade proposal on sovereign chain and vote +6. Build consumer chain daemon with upgrade handler for ccv module and relevant modules +7. Once chain halt, restart 2 nodes to move from sovereign chain to consumer chain +8. Ensure blocks are being produced without the first node used for sovereign chain +9. Execute delegation on provider chain and ensure consumer chain validators' voting power changes diff --git a/tests/sovereign_consumer_upgrade_local/build_binaries.sh b/tests/sovereign_consumer_upgrade_local/build_binaries.sh new file mode 100644 index 0000000000..f20cc28b4a --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/build_binaries.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +go install ../../cmd/interchain-security-sd +go install ../../cmd/interchain-security-pd +go install ../../cmd/interchain-security-cdd +go install ../../cmd/interchain-security-cd diff --git a/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_consumer.sh b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_consumer.sh new file mode 100644 index 0000000000..3ca098f3d3 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_consumer.sh @@ -0,0 +1,359 @@ +#!/bin/bash +set -eux + +SOVEREIGN_HOME="$HOME/.sovereign" +CONSUMER_HOME="$HOME/.consumer" +CONSUMER_HOME1="$HOME/.consumer1" +PROVIDER_CHAIN_ID="provider" +CONSUMER_CHAIN_ID="consumer" +MONIKER="consumer" +VALIDATOR="validator" +VALIDATOR1="validator1" +KEYRING="--keyring-backend test" +TX_FLAGS="--gas-adjustment 100 --gas auto" +PROVIDER_BINARY="interchain-security-pd" +SOVEREIGN_BINARY="interchain-security-sd" +CONSUMER_BINARY="interchain-security-cdd" +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +SOVEREIGN_RPC_LADDR="$NODE_IP:26648" +SOVEREIGN_GRPC_ADDR="$NODE_IP:9081" +CONSUMER_RPC_LADDR="$NODE_IP:26638" +CONSUMER_GRPC_ADDR="$NODE_IP:9071" +CONSUMER_RPC_LADDR1="$NODE_IP:26628" +CONSUMER_GRPC_ADDR1="$NODE_IP:9061" +CONSUMER_USER="consumer" +SOVEREIGN_VALIDATOR="sovereign_validator" +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_NODE_ADDRESS="tcp://localhost:26658" + +# Clean start +killall $SOVEREIGN_BINARY &> /dev/null || true +killall $CONSUMER_BINARY &> /dev/null || true +rm -rf $CONSUMER_HOME +rm -rf $CONSUMER_HOME1 +rm -rf $SOVEREIGN_HOME + +################SOVEREIGN############################ +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $SOVEREIGN_HOME +sleep 1 + +# Create user account keypair +$SOVEREIGN_BINARY keys add $CONSUMER_USER $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/consumer_keypair.json 2>&1 +$SOVEREIGN_BINARY keys add $SOVEREIGN_VALIDATOR $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/sovereign_validator_keypair.json 2>&1 + +# Add account in genesis (required by Hermes) +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/consumer_keypair.json) 1000000000stake --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/sovereign_validator_keypair.json) 1000000000000stake --home $SOVEREIGN_HOME + +# generate genesis for sovereign chain +$SOVEREIGN_BINARY gentx $SOVEREIGN_VALIDATOR 11000000000stake $KEYRING --chain-id=$CONSUMER_CHAIN_ID --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY collect-gentxs --home $SOVEREIGN_HOME +sed -i '' 's/"voting_period": "172800s"/"voting_period": "20s"/g' $SOVEREIGN_HOME/config/genesis.json + +################CONSUMER############################ + +# Build genesis file and node directory structure +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME +sleep 1 + +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME/config/priv_validator_key.json $CONSUMER_HOME/config/priv_validator_key.json +cp $PROVIDER_HOME/config/node_key.json $CONSUMER_HOME/config/node_key.json + +#######CHAIN2####### +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME1 +sleep 1 +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME1/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME1/config/priv_validator_key.json $CONSUMER_HOME1/config/priv_validator_key.json +cp $PROVIDER_HOME1/config/node_key.json $CONSUMER_HOME1/config/node_key.json + +##########SET CONFIG.TOML##################### +# Set default client port +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${SOVEREIGN_RPC_LADDR}\"/" $SOVEREIGN_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR}\"/" $CONSUMER_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR1}\"/" $CONSUMER_HOME1/config/client.toml +sovereign=$($SOVEREIGN_BINARY tendermint show-node-id --home $SOVEREIGN_HOME) +node=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME) +node1=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME1) + +# sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636,$node1@localhost:26626\"/" "$SOVEREIGN_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node1@localhost:26626\"/" "$CONSUMER_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node@localhost:26636\"/" "$CONSUMER_HOME1"/config/config.toml + +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636\"/" "$SOVEREIGN_HOME"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646\"/" "$CONSUMER_HOME"/config/config.toml + +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1318\"/" "$CONSUMER_HOME"/config/app.toml +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1319\"/" "$CONSUMER_HOME1"/config/app.toml + +# Start the chain +$SOVEREIGN_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$SOVEREIGN_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $SOVEREIGN_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 10 + +######################################HERMES################################### + +# Setup Hermes in packet relayer mode +killall hermes 2> /dev/null || true + +tee ~/.hermes/config.toml<<EOF +[global] +log_level = "trace" + +[mode] + +[mode.clients] +enabled = true +refresh = true +misbehaviour = true + +[mode.connections] +enabled = true + +[mode.channels] +enabled = true + +[mode.packets] +enabled = true + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${CONSUMER_GRPC_ADDR}" +id = "$CONSUMER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${CONSUMER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${CONSUMER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${PROVIDER_GRPC_ADDR}" +id = "$PROVIDER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${PROVIDER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${PROVIDER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" +EOF + +# Delete all previous keys in relayer +hermes keys delete $CONSUMER_CHAIN_ID -a +hermes keys delete $PROVIDER_CHAIN_ID -a + +# Restore keys to hermes relayer +hermes keys restore --mnemonic "$(jq -r .mnemonic $SOVEREIGN_HOME/consumer_keypair.json)" $CONSUMER_CHAIN_ID +# temp_start_provider.sh creates key pair and stores it in keypair.json +hermes keys restore --mnemonic "$(jq -r .mnemonic $PROVIDER_HOME/keypair.json)" $PROVIDER_CHAIN_ID + +sleep 5 + +hermes create client consumer provider +hermes create client provider consumer +# hermes query clients consumer +# hermes query client consensus consumer 07-tendermint-0 +# hermes query clients provider +hermes create connection $CONSUMER_CHAIN_ID --client-a 07-tendermint-0 --client-b 07-tendermint-0 +hermes create channel $CONSUMER_CHAIN_ID --port-a transfer --port-b transfer connection-0 + +sleep 1 + +hermes -j start &> ~/.hermes/logs & + +# Build consumer chain proposal file +tee $PROVIDER_HOME/consumer-proposal.json<<EOF +{ + "title": "Create a chain", + "description": "Gonna be a great chain", + "chain_id": "consumer", + "initial_height": { + "revision_number": 0, + "revision_height": 29 + }, + "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", + "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", + "spawn_time": "2022-06-01T09:10:00.000000000-00:00", + "deposit": "10000001stake", + "consumer_redistribution_fraction": "0.75", + "blocks_per_distribution_transmission": 1000, + "ccv_timeout_period": 2419200000000000, + "transfer_timeout_period": 3600000000000, + "historical_entries": 10000, + "unbonding_period": 1200000000000 +} +EOF + +$PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ + --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +sleep 1 + +# Vote yes to proposal +$PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +sleep 5 + +# ###########################UPGRADE TO SOVEREIGN CHAIN########################## + +$SOVEREIGN_BINARY tx gov submit-proposal software-upgrade "v07-Theta" --upgrade-height=26 \ +--title="upgrade to consumer chain" --description="upgrade to consumer chain description" \ +--from=$SOVEREIGN_VALIDATOR $KEYRING --chain-id=$CONSUMER_CHAIN_ID \ +--home=$SOVEREIGN_HOME --yes -b block --deposit="100000000stake" + +# Vote yes to proposal +$SOVEREIGN_BINARY tx gov vote 1 yes --from $SOVEREIGN_VALIDATOR --chain-id $CONSUMER_CHAIN_ID --node tcp://$SOVEREIGN_RPC_LADDR \ +--home $SOVEREIGN_HOME -b block -y $KEYRING +sleep 30 + +###########################START BINARIES AGAIN AFTER UPGRADE########################## +$SOVEREIGN_BINARY query gov proposals --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR +# $SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR1 + +killall $SOVEREIGN_BINARY &> /dev/null || true + +# Add ccv section to SOVEREIGN_HOME genesis to be used on upgrade handler +if ! $PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$SOVEREIGN_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$SOVEREIGN_HOME"/config/genesis.json "$SOVEREIGN_HOME"/consumer_section.json > "$SOVEREIGN_HOME"/genesis_consumer.json && \ + mv "$SOVEREIGN_HOME"/genesis_consumer.json "$SOVEREIGN_HOME"/config/genesis.json + +# Modify genesis params +jq ".app_state.ccvconsumer.params.blocks_per_distribution_transmission = \"70\" | .app_state.tokenfactory.paused = { \"paused\": false }" \ + $SOVEREIGN_HOME/config/genesis.json > \ + $SOVEREIGN_HOME/edited_genesis.json && mv $SOVEREIGN_HOME/edited_genesis.json $SOVEREIGN_HOME/config/genesis.json +sleep 1 + + +$CONSUMER_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$CONSUMER_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $CONSUMER_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 30 + +# # create channel between consumer and provider between provider port and consumer port +# hermes query clients consumer +# hermes query clients provider +# hermes query client consensus consumer 07-tendermint-1 +# hermes query client consensus provider 07-tendermint-1 +hermes create connection $CONSUMER_CHAIN_ID --client-a 07-tendermint-1 --client-b 07-tendermint-1 +hermes create channel $CONSUMER_CHAIN_ID --port-a consumer --port-b provider -o ordered --channel-version 1 connection-1 + +# ############################################################ + +PROVIDER_VALIDATOR_ADDRESS=$(jq -r .address $PROVIDER_HOME/keypair.json) +DELEGATIONS=$($PROVIDER_BINARY q staking delegations $PROVIDER_VALIDATOR_ADDRESS --home $PROVIDER_HOME --node tcp://${PROVIDER_RPC_LADDR} -o json) +OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r .delegation_responses[0].delegation.validator_address) + +$PROVIDER_BINARY tx staking delegate $OPERATOR_ADDR 32000000stake \ + --from $VALIDATOR \ + $KEYRING \ + --home $PROVIDER_HOME \ + --node tcp://${PROVIDER_RPC_LADDR} \ + --chain-id $PROVIDER_CHAIN_ID -y -b block +sleep 1 + +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR} +# $PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR1} + +$CONSUMER_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$CONSUMER_BINARY status --node tcp://$CONSUMER_RPC_LADDR + +# $CONSUMER_BINARY query staking params --node=tcp://$CONSUMER_RPC_LADDR +# $PROVIDER_BINARY query staking params --node=tcp://${PROVIDER_RPC_LADDR} diff --git a/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_provider.sh b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_provider.sh new file mode 100644 index 0000000000..149cf32f80 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0-old-connection/start_provider.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -eux + +TOTAL_COINS=100000000000stake +STAKE_COINS=100000000stake +TOTAL_COINS1=120000000000stake +STAKE_COINS1=1000000stake +PROVIDER_BINARY=interchain-security-pd +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_CHAIN_ID=provider +PROVIDER_MONIKER=provider +VALIDATOR=validator +VALIDATOR1=validator1 +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +PROVIDER_DELEGATOR=delegator + +# Clean start +killall $PROVIDER_BINARY &> /dev/null || true + +#######VALIDATOR1####################### +rm -rf $PROVIDER_HOME + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME --chain-id $PROVIDER_CHAIN_ID +jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"600s\" | .app_state.provider.params.template_client.trusting_period = \"300s\"" \ + $PROVIDER_HOME/config/genesis.json > \ + $PROVIDER_HOME/edited_genesis.json && mv $PROVIDER_HOME/edited_genesis.json $PROVIDER_HOME/config/genesis.json +sleep 1 + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair.json 2>&1 +sleep 1 +$PROVIDER_BINARY keys add $PROVIDER_DELEGATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair_delegator.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair_delegator.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 + +# Stake 1/1000 user's coins +$PROVIDER_BINARY gentx $VALIDATOR $STAKE_COINS --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME --keyring-backend test --moniker $VALIDATOR +sleep 1 + +###########VALIDATOR 2############################ +rm -rf $PROVIDER_HOME1 + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME1 --chain-id $PROVIDER_CHAIN_ID +cp $PROVIDER_HOME/config/genesis.json $PROVIDER_HOME1/config/genesis.json + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR1 --home $PROVIDER_HOME1 --keyring-backend test --output json > $PROVIDER_HOME1/keypair.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME1/keypair.json) $TOTAL_COINS1 --home $PROVIDER_HOME1 --keyring-backend test +sleep 1 + +####################GENTX AND DISTRIBUTE GENESIS############################## +cp -r $PROVIDER_HOME/config/gentx $PROVIDER_HOME1/config/ + +# Stake 1/1000 user's coins +# $PROVIDER_BINARY gentx $VALIDATOR1 $STAKE_COINS1 --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME1 --keyring-backend test --moniker $VALIDATOR1 +# sleep 1 + +$PROVIDER_BINARY collect-gentxs --home $PROVIDER_HOME1 --gentx-dir $PROVIDER_HOME1/config/gentx/ +sleep 1 + +cp $PROVIDER_HOME1/config/genesis.json $PROVIDER_HOME/config/genesis.json + +####################ADDING PEERS#################### +node=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME) +node1=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME1) +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26656\"/" "$PROVIDER_HOME1"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$node1@localhost:26666\"/" "$PROVIDER_HOME"/config/config.toml + +#################### Start the chain node1 ################### +$PROVIDER_BINARY start \ + --home $PROVIDER_HOME \ + --rpc.laddr tcp://$PROVIDER_RPC_LADDR \ + --grpc.address $PROVIDER_GRPC_ADDR \ + --address tcp://${NODE_IP}:26655 \ + --p2p.laddr tcp://${NODE_IP}:26656 \ + --grpc-web.enable=false \ + --trace \ + &> $PROVIDER_HOME/logs & + +#################### Start the chain node2 ################### +# $PROVIDER_BINARY start \ +# --home $PROVIDER_HOME1 \ +# --rpc.laddr tcp://$PROVIDER_RPC_LADDR1 \ +# --grpc.address $PROVIDER_GRPC_ADDR1 \ +# --address tcp://${NODE_IP}:26665 \ +# --p2p.laddr tcp://${NODE_IP}:26666 \ +# --grpc-web.enable=false \ +# --trace \ +# &> $PROVIDER_HOME1/logs & +sleep 10 + +# # Build consumer chain proposal file +# tee $PROVIDER_HOME/consumer-proposal.json<<EOF +# { +# "title": "Create a chain", +# "description": "Gonna be a great chain", +# "chain_id": "consumer", +# "initial_height": { +# "revision_number": 0, +# "revision_height": 1 +# }, +# "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", +# "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", +# "spawn_time": "2022-06-01T09:10:00.000000000-00:00", +# "deposit": "10000001stake", +# "consumer_redistribution_fraction": "0.75", +# "blocks_per_distribution_transmission": 1000, +# "ccv_timeout_period": 2419200000000000, +# "transfer_timeout_period": 3600000000000, +# "historical_entries": 10000, +# "unbonding_period": 1200000000000 +# } +# EOF + +# $PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ +# --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +# sleep 1 + +# # Vote yes to proposal +# $PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +# sleep 5 diff --git a/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_consumer.sh b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_consumer.sh new file mode 100644 index 0000000000..ae885c7a94 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_consumer.sh @@ -0,0 +1,304 @@ +#!/bin/bash +set -eux + +SOVEREIGN_HOME="$HOME/.sovereign" +CONSUMER_HOME="$HOME/.consumer" +CONSUMER_HOME1="$HOME/.consumer1" +PROVIDER_CHAIN_ID="provider" +CONSUMER_CHAIN_ID="consumer" +MONIKER="consumer" +VALIDATOR="validator" +VALIDATOR1="validator1" +KEYRING="--keyring-backend test" +TX_FLAGS="--gas-adjustment 100 --gas auto" +PROVIDER_BINARY="interchain-security-pd" +SOVEREIGN_BINARY="interchain-security-sd" +CONSUMER_BINARY="interchain-security-cdd" +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +SOVEREIGN_RPC_LADDR="$NODE_IP:26648" +SOVEREIGN_GRPC_ADDR="$NODE_IP:9081" +CONSUMER_RPC_LADDR="$NODE_IP:26638" +CONSUMER_GRPC_ADDR="$NODE_IP:9071" +CONSUMER_RPC_LADDR1="$NODE_IP:26628" +CONSUMER_GRPC_ADDR1="$NODE_IP:9061" +CONSUMER_USER="consumer" +SOVEREIGN_VALIDATOR="sovereign_validator" +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_NODE_ADDRESS="tcp://localhost:26658" + +# Clean start +killall $SOVEREIGN_BINARY &> /dev/null || true +killall $CONSUMER_BINARY &> /dev/null || true +rm -rf $CONSUMER_HOME +rm -rf $CONSUMER_HOME1 +rm -rf $SOVEREIGN_HOME + +################SOVEREIGN############################ +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $SOVEREIGN_HOME +sleep 1 + +# Create user account keypair +$SOVEREIGN_BINARY keys add $CONSUMER_USER $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/consumer_keypair.json 2>&1 +$SOVEREIGN_BINARY keys add $SOVEREIGN_VALIDATOR $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/sovereign_validator_keypair.json 2>&1 + +# Add account in genesis (required by Hermes) +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/consumer_keypair.json) 1000000000stake --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/sovereign_validator_keypair.json) 1000000000000stake --home $SOVEREIGN_HOME + +# generate genesis for sovereign chain +$SOVEREIGN_BINARY gentx $SOVEREIGN_VALIDATOR 10000000000stake $KEYRING --chain-id=$CONSUMER_CHAIN_ID --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY collect-gentxs --home $SOVEREIGN_HOME +sed -i '' 's/"voting_period": "172800s"/"voting_period": "20s"/g' $SOVEREIGN_HOME/config/genesis.json + +################CONSUMER############################ + +# Build genesis file and node directory structure +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME +sleep 1 + +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME/config/priv_validator_key.json $CONSUMER_HOME/config/priv_validator_key.json +cp $PROVIDER_HOME/config/node_key.json $CONSUMER_HOME/config/node_key.json + +#######CHAIN2####### +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME1 +sleep 1 +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME1/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME1/config/priv_validator_key.json $CONSUMER_HOME1/config/priv_validator_key.json +cp $PROVIDER_HOME1/config/node_key.json $CONSUMER_HOME1/config/node_key.json + +##########SET CONFIG.TOML##################### +# Set default client port +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${SOVEREIGN_RPC_LADDR}\"/" $SOVEREIGN_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR}\"/" $CONSUMER_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR1}\"/" $CONSUMER_HOME1/config/client.toml +sovereign=$($SOVEREIGN_BINARY tendermint show-node-id --home $SOVEREIGN_HOME) +node=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME) +node1=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME1) + +# sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636,$node1@localhost:26626\"/" "$SOVEREIGN_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node1@localhost:26626\"/" "$CONSUMER_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node@localhost:26636\"/" "$CONSUMER_HOME1"/config/config.toml + +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636\"/" "$SOVEREIGN_HOME"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646\"/" "$CONSUMER_HOME"/config/config.toml + +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1318\"/" "$CONSUMER_HOME"/config/app.toml +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1319\"/" "$CONSUMER_HOME1"/config/app.toml + +# Start the chain +$SOVEREIGN_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$SOVEREIGN_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $SOVEREIGN_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 10 + +###########################UPGRADE TO SOVEREIGN CHAIN########################## + +$SOVEREIGN_BINARY tx gov submit-proposal software-upgrade "v07-Theta" --upgrade-height=7 \ +--title="upgrade to consumer chain" --description="upgrade to consumer chain description" \ +--from=$SOVEREIGN_VALIDATOR $KEYRING --chain-id=$CONSUMER_CHAIN_ID \ +--home=$SOVEREIGN_HOME --yes -b block --deposit="100000000stake" + +# Vote yes to proposal +$SOVEREIGN_BINARY tx gov vote 1 yes --from $SOVEREIGN_VALIDATOR --chain-id $CONSUMER_CHAIN_ID --node tcp://$SOVEREIGN_RPC_LADDR \ +--home $SOVEREIGN_HOME -b block -y $KEYRING +sleep 30 + +###########################START BINARIES AGAIN AFTER UPGRADE########################## +$SOVEREIGN_BINARY query gov proposals --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR +# $SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR1 + +killall $SOVEREIGN_BINARY &> /dev/null || true + +# Add ccv section to SOVEREIGN_HOME genesis to be used on upgrade handler +if ! $PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$SOVEREIGN_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$SOVEREIGN_HOME"/config/genesis.json "$SOVEREIGN_HOME"/consumer_section.json > "$SOVEREIGN_HOME"/genesis_consumer.json && \ + mv "$SOVEREIGN_HOME"/genesis_consumer.json "$SOVEREIGN_HOME"/config/genesis.json + +# Modify genesis params +jq ".app_state.ccvconsumer.params.blocks_per_distribution_transmission = \"70\" | .app_state.tokenfactory.paused = { \"paused\": false }" \ + $SOVEREIGN_HOME/config/genesis.json > \ + $SOVEREIGN_HOME/edited_genesis.json && mv $SOVEREIGN_HOME/edited_genesis.json $SOVEREIGN_HOME/config/genesis.json +sleep 1 + + +$CONSUMER_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$CONSUMER_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $CONSUMER_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 30 + +######################################HERMES################################### + +# Setup Hermes in packet relayer mode +killall hermes 2> /dev/null || true + +tee ~/.hermes/config.toml<<EOF +[global] +log_level = "trace" +[mode] +[mode.clients] +enabled = true +refresh = true +misbehaviour = true +[mode.connections] +enabled = true +[mode.channels] +enabled = true +[mode.packets] +enabled = true +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${CONSUMER_GRPC_ADDR}" +id = "$CONSUMER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${CONSUMER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${CONSUMER_RPC_LADDR}/websocket" +[chains.gas_price] + denom = "stake" + price = 0.00 +[chains.trust_threshold] + denominator = "3" + numerator = "1" +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${PROVIDER_GRPC_ADDR}" +id = "$PROVIDER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${PROVIDER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${PROVIDER_RPC_LADDR}/websocket" +[chains.gas_price] + denom = "stake" + price = 0.00 +[chains.trust_threshold] + denominator = "3" + numerator = "1" +EOF + +# Delete all previous keys in relayer +hermes keys delete $CONSUMER_CHAIN_ID -a +hermes keys delete $PROVIDER_CHAIN_ID -a + +# Restore keys to hermes relayer +hermes keys restore --mnemonic "$(jq -r .mnemonic $SOVEREIGN_HOME/consumer_keypair.json)" $CONSUMER_CHAIN_ID +# temp_start_provider.sh creates key pair and stores it in keypair.json +hermes keys restore --mnemonic "$(jq -r .mnemonic $PROVIDER_HOME/keypair.json)" $PROVIDER_CHAIN_ID + +sleep 5 + +hermes create connection $CONSUMER_CHAIN_ID --client-a 07-tendermint-0 --client-b 07-tendermint-0 +hermes create channel $CONSUMER_CHAIN_ID --port-a consumer --port-b provider -o ordered --channel-version 1 connection-0 + +sleep 1 + +hermes -j start &> ~/.hermes/logs & + +############################################################ + +PROVIDER_VALIDATOR_ADDRESS=$(jq -r .address $PROVIDER_HOME/keypair.json) +DELEGATIONS=$($PROVIDER_BINARY q staking delegations $PROVIDER_VALIDATOR_ADDRESS --home $PROVIDER_HOME --node tcp://${PROVIDER_RPC_LADDR} -o json) +OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r .delegation_responses[0].delegation.validator_address) + +$PROVIDER_BINARY tx staking delegate $OPERATOR_ADDR 32000000stake \ + --from $VALIDATOR \ + $KEYRING \ + --home $PROVIDER_HOME \ + --node tcp://${PROVIDER_RPC_LADDR} \ + --chain-id $PROVIDER_CHAIN_ID -y -b block +sleep 1 + +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR} +# $PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR1} + +$CONSUMER_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$CONSUMER_BINARY status --node tcp://$CONSUMER_RPC_LADDR + +$CONSUMER_BINARY query staking params --node=tcp://$CONSUMER_RPC_LADDR +$PROVIDER_BINARY query staking params --node=tcp://${PROVIDER_RPC_LADDR} \ No newline at end of file diff --git a/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_provider.sh b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_provider.sh new file mode 100644 index 0000000000..e2bd305657 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-0.15.0/start_provider.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -eux + +TOTAL_COINS=100000000000stake +STAKE_COINS=100000000stake +TOTAL_COINS1=120000000000stake +STAKE_COINS1=1000000stake +PROVIDER_BINARY=interchain-security-pd +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_CHAIN_ID=provider +PROVIDER_MONIKER=provider +VALIDATOR=validator +VALIDATOR1=validator1 +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +PROVIDER_DELEGATOR=delegator + +# Clean start +killall $PROVIDER_BINARY &> /dev/null || true + +#######VALIDATOR1####################### +rm -rf $PROVIDER_HOME + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME --chain-id $PROVIDER_CHAIN_ID +jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"600s\" | .app_state.provider.params.template_client.trusting_period = \"300s\"" \ + $PROVIDER_HOME/config/genesis.json > \ + $PROVIDER_HOME/edited_genesis.json && mv $PROVIDER_HOME/edited_genesis.json $PROVIDER_HOME/config/genesis.json +sleep 1 + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair.json 2>&1 +sleep 1 +$PROVIDER_BINARY keys add $PROVIDER_DELEGATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair_delegator.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair_delegator.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 + +# Stake 1/1000 user's coins +$PROVIDER_BINARY gentx $VALIDATOR $STAKE_COINS --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME --keyring-backend test --moniker $VALIDATOR +sleep 1 + +###########VALIDATOR 2############################ +rm -rf $PROVIDER_HOME1 + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME1 --chain-id $PROVIDER_CHAIN_ID +cp $PROVIDER_HOME/config/genesis.json $PROVIDER_HOME1/config/genesis.json + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR1 --home $PROVIDER_HOME1 --keyring-backend test --output json > $PROVIDER_HOME1/keypair.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME1/keypair.json) $TOTAL_COINS1 --home $PROVIDER_HOME1 --keyring-backend test +sleep 1 + +####################GENTX AND DISTRIBUTE GENESIS############################## +cp -r $PROVIDER_HOME/config/gentx $PROVIDER_HOME1/config/ + +# Stake 1/1000 user's coins +# $PROVIDER_BINARY gentx $VALIDATOR1 $STAKE_COINS1 --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME1 --keyring-backend test --moniker $VALIDATOR1 +# sleep 1 + +$PROVIDER_BINARY collect-gentxs --home $PROVIDER_HOME1 --gentx-dir $PROVIDER_HOME1/config/gentx/ +sleep 1 + +cp $PROVIDER_HOME1/config/genesis.json $PROVIDER_HOME/config/genesis.json + +####################ADDING PEERS#################### +node=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME) +node1=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME1) +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26656\"/" "$PROVIDER_HOME1"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$node1@localhost:26666\"/" "$PROVIDER_HOME"/config/config.toml + +#################### Start the chain node1 ################### +$PROVIDER_BINARY start \ + --home $PROVIDER_HOME \ + --rpc.laddr tcp://$PROVIDER_RPC_LADDR \ + --grpc.address $PROVIDER_GRPC_ADDR \ + --address tcp://${NODE_IP}:26655 \ + --p2p.laddr tcp://${NODE_IP}:26656 \ + --grpc-web.enable=false \ + --trace \ + &> $PROVIDER_HOME/logs & + +#################### Start the chain node2 ################### +# $PROVIDER_BINARY start \ +# --home $PROVIDER_HOME1 \ +# --rpc.laddr tcp://$PROVIDER_RPC_LADDR1 \ +# --grpc.address $PROVIDER_GRPC_ADDR1 \ +# --address tcp://${NODE_IP}:26665 \ +# --p2p.laddr tcp://${NODE_IP}:26666 \ +# --grpc-web.enable=false \ +# --trace \ +# &> $PROVIDER_HOME1/logs & +sleep 10 + +# Build consumer chain proposal file +tee $PROVIDER_HOME/consumer-proposal.json<<EOF +{ + "title": "Create a chain", + "description": "Gonna be a great chain", + "chain_id": "consumer", + "initial_height": { + "revision_number": 0, + "revision_height": 8 + }, + "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", + "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", + "spawn_time": "2022-06-01T09:10:00.000000000-00:00", + "deposit": "10000001stake", + "consumer_redistribution_fraction": "0.75", + "blocks_per_distribution_transmission": 1000, + "ccv_timeout_period": 2419200000000000, + "transfer_timeout_period": 3600000000000, + "historical_entries": 10000, + "unbonding_period": 1200000000000 +} +EOF + +$PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ + --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +sleep 1 + +# Vote yes to proposal +$PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +sleep 5 diff --git a/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_consumer.sh b/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_consumer.sh new file mode 100644 index 0000000000..38238c569c --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_consumer.sh @@ -0,0 +1,313 @@ +#!/bin/bash +set -eux + +SOVEREIGN_HOME="$HOME/.sovereign" +CONSUMER_HOME="$HOME/.consumer" +CONSUMER_HOME1="$HOME/.consumer1" +PROVIDER_CHAIN_ID="provider" +CONSUMER_CHAIN_ID="consumer" +MONIKER="consumer" +VALIDATOR="validator" +VALIDATOR1="validator1" +KEYRING="--keyring-backend test" +TX_FLAGS="--gas-adjustment 100 --gas auto" +PROVIDER_BINARY="interchain-security-pd" +SOVEREIGN_BINARY="interchain-security-sd" +CONSUMER_BINARY="interchain-security-cdd" +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +SOVEREIGN_RPC_LADDR="$NODE_IP:26648" +SOVEREIGN_GRPC_ADDR="$NODE_IP:9081" +CONSUMER_RPC_LADDR="$NODE_IP:26638" +CONSUMER_GRPC_ADDR="$NODE_IP:9071" +CONSUMER_RPC_LADDR1="$NODE_IP:26628" +CONSUMER_GRPC_ADDR1="$NODE_IP:9061" +CONSUMER_USER="consumer" +SOVEREIGN_VALIDATOR="sovereign_validator" +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_NODE_ADDRESS="tcp://localhost:26658" + +# Clean start +killall $SOVEREIGN_BINARY &> /dev/null || true +killall $CONSUMER_BINARY &> /dev/null || true +rm -rf $CONSUMER_HOME +rm -rf $CONSUMER_HOME1 +rm -rf $SOVEREIGN_HOME + +################SOVEREIGN############################ +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $SOVEREIGN_HOME +sleep 1 + +# Create user account keypair +$SOVEREIGN_BINARY keys add $CONSUMER_USER $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/consumer_keypair.json 2>&1 +$SOVEREIGN_BINARY keys add $SOVEREIGN_VALIDATOR $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/sovereign_validator_keypair.json 2>&1 + +# Add account in genesis (required by Hermes) +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/consumer_keypair.json) 1000000000stake --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/sovereign_validator_keypair.json) 1000000000000stake --home $SOVEREIGN_HOME + +# generate genesis for sovereign chain +$SOVEREIGN_BINARY gentx $SOVEREIGN_VALIDATOR 10000000000stake $KEYRING --chain-id=$CONSUMER_CHAIN_ID --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY collect-gentxs --home $SOVEREIGN_HOME +sed -i '' 's/"voting_period": "172800s"/"voting_period": "20s"/g' $SOVEREIGN_HOME/config/genesis.json + +################CONSUMER############################ + +# Build genesis file and node directory structure +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME +sleep 1 + +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME/config/priv_validator_key.json $CONSUMER_HOME/config/priv_validator_key.json +cp $PROVIDER_HOME/config/node_key.json $CONSUMER_HOME/config/node_key.json + +#######CHAIN2####### +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME1 +sleep 1 +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME1/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME1/config/priv_validator_key.json $CONSUMER_HOME1/config/priv_validator_key.json +cp $PROVIDER_HOME1/config/node_key.json $CONSUMER_HOME1/config/node_key.json + +##########SET CONFIG.TOML##################### +# Set default client port +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${SOVEREIGN_RPC_LADDR}\"/" $SOVEREIGN_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR}\"/" $CONSUMER_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR1}\"/" $CONSUMER_HOME1/config/client.toml +sovereign=$($SOVEREIGN_BINARY tendermint show-node-id --home $SOVEREIGN_HOME) +node=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME) +node1=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME1) + +# sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636,$node1@localhost:26626\"/" "$SOVEREIGN_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node1@localhost:26626\"/" "$CONSUMER_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node@localhost:26636\"/" "$CONSUMER_HOME1"/config/config.toml + +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636\"/" "$SOVEREIGN_HOME"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646\"/" "$CONSUMER_HOME"/config/config.toml + +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1318\"/" "$CONSUMER_HOME"/config/app.toml +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1319\"/" "$CONSUMER_HOME1"/config/app.toml + +# Start the chain +$SOVEREIGN_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$SOVEREIGN_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $SOVEREIGN_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 10 + +###########################UPGRADE TO SOVEREIGN CHAIN########################## + +$SOVEREIGN_BINARY tx gov submit-proposal software-upgrade "v07-Theta" --upgrade-height=7 \ +--title="upgrade to consumer chain" --description="upgrade to consumer chain description" \ +--from=$SOVEREIGN_VALIDATOR $KEYRING --chain-id=$CONSUMER_CHAIN_ID \ +--home=$SOVEREIGN_HOME --yes -b block --deposit="100000000stake" + +# Vote yes to proposal +$SOVEREIGN_BINARY tx gov vote 1 yes --from $SOVEREIGN_VALIDATOR --chain-id $CONSUMER_CHAIN_ID --node tcp://$SOVEREIGN_RPC_LADDR \ +--home $SOVEREIGN_HOME -b block -y $KEYRING +sleep 30 + +###########################START BINARIES AGAIN AFTER UPGRADE########################## +$SOVEREIGN_BINARY query gov proposals --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR +# $SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR1 + +killall $SOVEREIGN_BINARY &> /dev/null || true + +# Add ccv section to SOVEREIGN_HOME genesis to be used on upgrade handler +if ! $PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$SOVEREIGN_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$SOVEREIGN_HOME"/config/genesis.json "$SOVEREIGN_HOME"/consumer_section.json > "$SOVEREIGN_HOME"/genesis_consumer.json && \ + mv "$SOVEREIGN_HOME"/genesis_consumer.json "$SOVEREIGN_HOME"/config/genesis.json + +# Modify genesis params +jq ".app_state.ccvconsumer.params.blocks_per_distribution_transmission = \"70\" | .app_state.tokenfactory.paused = { \"paused\": false }" \ + $SOVEREIGN_HOME/config/genesis.json > \ + $SOVEREIGN_HOME/edited_genesis.json && mv $SOVEREIGN_HOME/edited_genesis.json $SOVEREIGN_HOME/config/genesis.json +sleep 1 + + +$CONSUMER_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$CONSUMER_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $CONSUMER_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 30 + +######################################HERMES################################### + +# Setup Hermes in packet relayer mode +killall hermes 2> /dev/null || true + +tee ~/.hermes/config.toml<<EOF +[global] +log_level = "trace" + +[mode] + +[mode.clients] +enabled = true +refresh = true +misbehaviour = true + +[mode.connections] +enabled = true + +[mode.channels] +enabled = true + +[mode.packets] +enabled = true + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_multiplier = 1.1 +grpc_addr = "tcp://${CONSUMER_GRPC_ADDR}" +id = "$CONSUMER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${CONSUMER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "1599s" +websocket_addr = "ws://${CONSUMER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_multiplier = 1.1 +grpc_addr = "tcp://${PROVIDER_GRPC_ADDR}" +id = "$PROVIDER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${PROVIDER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "1599s" +websocket_addr = "ws://${PROVIDER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" +EOF + +# Delete all previous keys in relayer +hermes keys delete --chain $CONSUMER_CHAIN_ID --all +hermes keys delete --chain $PROVIDER_CHAIN_ID --all + +# Restore keys to hermes relayer +hermes keys add --key-file $SOVEREIGN_HOME/consumer_keypair.json --chain $CONSUMER_CHAIN_ID +# temp_start_provider.sh creates key pair and stores it in keypair.json +hermes keys add --key-file $PROVIDER_HOME/keypair.json --chain $PROVIDER_CHAIN_ID + +sleep 5 + +hermes create connection --a-chain $CONSUMER_CHAIN_ID --a-client 07-tendermint-0 --b-client 07-tendermint-0 +hermes create channel --a-chain $CONSUMER_CHAIN_ID --a-connection connection-0 --a-port consumer --b-port provider --order ordered --channel-version 1 + +hermes -j start &> ~/.hermes/logs & + +############################################################ + +PROVIDER_VALIDATOR_ADDRESS=$(jq -r .address $PROVIDER_HOME/keypair.json) +DELEGATIONS=$($PROVIDER_BINARY q staking delegations $PROVIDER_VALIDATOR_ADDRESS --home $PROVIDER_HOME --node tcp://${PROVIDER_RPC_LADDR} -o json) +OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r .delegation_responses[0].delegation.validator_address) + +$PROVIDER_BINARY tx staking delegate $OPERATOR_ADDR 50000000stake \ + --from $VALIDATOR \ + $KEYRING \ + --home $PROVIDER_HOME \ + --node tcp://${PROVIDER_RPC_LADDR} \ + --chain-id $PROVIDER_CHAIN_ID -y -b block +sleep 1 + +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR} +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR1} + +$CONSUMER_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$CONSUMER_BINARY status --node tcp://$CONSUMER_RPC_LADDR + +$CONSUMER_BINARY query staking params --node=tcp://$CONSUMER_RPC_LADDR +$PROVIDER_BINARY query staking params --node=tcp://${PROVIDER_RPC_LADDR} diff --git a/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_provider.sh b/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_provider.sh new file mode 100644 index 0000000000..613f7ae597 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/hermes-1.2.0/start_provider.sh @@ -0,0 +1,133 @@ +#!/bin/bash +set -eux + +TOTAL_COINS=100000000000stake +STAKE_COINS=100000000stake +TOTAL_COINS1=120000000000stake +STAKE_COINS1=1000000stake +PROVIDER_BINARY=interchain-security-pd +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_CHAIN_ID=provider +PROVIDER_MONIKER=provider +VALIDATOR=validator +VALIDATOR1=validator1 +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +PROVIDER_DELEGATOR=delegator + +# Clean start +killall $PROVIDER_BINARY &> /dev/null || true + +#######VALIDATOR1####################### +rm -rf $PROVIDER_HOME + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME --chain-id $PROVIDER_CHAIN_ID +jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"11600s\" | .app_state.provider.params.template_client.trusting_period = \"11300s\"" \ $PROVIDER_HOME/config/genesis.json > \ + $PROVIDER_HOME/edited_genesis.json && mv $PROVIDER_HOME/edited_genesis.json $PROVIDER_HOME/config/genesis.json +sleep 1 + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair.json 2>&1 +sleep 1 +$PROVIDER_BINARY keys add $PROVIDER_DELEGATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair_delegator.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair_delegator.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 + +# Stake 1/1000 user's coins +$PROVIDER_BINARY gentx $VALIDATOR $STAKE_COINS --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME --keyring-backend test --moniker $VALIDATOR +sleep 1 + +###########VALIDATOR 2############################ +rm -rf $PROVIDER_HOME1 + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME1 --chain-id $PROVIDER_CHAIN_ID +cp $PROVIDER_HOME/config/genesis.json $PROVIDER_HOME1/config/genesis.json + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR1 --home $PROVIDER_HOME1 --keyring-backend test --output json > $PROVIDER_HOME1/keypair.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME1/keypair.json) $TOTAL_COINS1 --home $PROVIDER_HOME1 --keyring-backend test +sleep 1 + +####################GENTX AND DISTRIBUTE GENESIS############################## +cp -r $PROVIDER_HOME/config/gentx $PROVIDER_HOME1/config/ + +# Stake 1/1000 user's coins +# $PROVIDER_BINARY gentx $VALIDATOR1 $STAKE_COINS1 --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME1 --keyring-backend test --moniker $VALIDATOR1 +# sleep 1 + +$PROVIDER_BINARY collect-gentxs --home $PROVIDER_HOME1 --gentx-dir $PROVIDER_HOME1/config/gentx/ +sleep 1 + +cp $PROVIDER_HOME1/config/genesis.json $PROVIDER_HOME/config/genesis.json + +####################ADDING PEERS#################### +node=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME) +node1=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME1) +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26656\"/" "$PROVIDER_HOME1"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$node1@localhost:26666\"/" "$PROVIDER_HOME"/config/config.toml + +#################### Start the chain node1 ################### +$PROVIDER_BINARY start \ + --home $PROVIDER_HOME \ + --rpc.laddr tcp://$PROVIDER_RPC_LADDR \ + --grpc.address $PROVIDER_GRPC_ADDR \ + --address tcp://${NODE_IP}:26655 \ + --p2p.laddr tcp://${NODE_IP}:26656 \ + --grpc-web.enable=false \ + --trace \ + &> $PROVIDER_HOME/logs & + +#################### Start the chain node2 ################### +# $PROVIDER_BINARY start \ +# --home $PROVIDER_HOME1 \ +# --rpc.laddr tcp://$PROVIDER_RPC_LADDR1 \ +# --grpc.address $PROVIDER_GRPC_ADDR1 \ +# --address tcp://${NODE_IP}:26665 \ +# --p2p.laddr tcp://${NODE_IP}:26666 \ +# --grpc-web.enable=false \ +# --trace \ +# &> $PROVIDER_HOME1/logs & +sleep 10 + +# Build consumer chain proposal file +tee $PROVIDER_HOME/consumer-proposal.json<<EOF +{ + "title": "Create a chain", + "description": "Gonna be a great chain", + "chain_id": "consumer", + "initial_height": { + "revision_number": 0, + "revision_height": 9 + }, + "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", + "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", + "spawn_time": "2022-06-01T09:10:00.000000000-00:00", + "deposit": "10000001stake", + "consumer_redistribution_fraction": "0.75", + "blocks_per_distribution_transmission": 1000, + "ccv_timeout_period": 2419200000000000, + "transfer_timeout_period": 3600000000000, + "historical_entries": 10000, + "unbonding_period": 111200000000000 +} +EOF + +$PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ + --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +sleep 1 + +# Vote yes to proposal +$PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +sleep 5 diff --git a/tests/sovereign_consumer_upgrade_local/run.sh b/tests/sovereign_consumer_upgrade_local/run.sh new file mode 100644 index 0000000000..28f3feacaa --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/run.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -eux + +bash build_binaries.sh +bash start_provider.sh +bash start_consumer.sh diff --git a/tests/sovereign_consumer_upgrade_local/start_consumer.sh b/tests/sovereign_consumer_upgrade_local/start_consumer.sh new file mode 100644 index 0000000000..3ca098f3d3 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/start_consumer.sh @@ -0,0 +1,359 @@ +#!/bin/bash +set -eux + +SOVEREIGN_HOME="$HOME/.sovereign" +CONSUMER_HOME="$HOME/.consumer" +CONSUMER_HOME1="$HOME/.consumer1" +PROVIDER_CHAIN_ID="provider" +CONSUMER_CHAIN_ID="consumer" +MONIKER="consumer" +VALIDATOR="validator" +VALIDATOR1="validator1" +KEYRING="--keyring-backend test" +TX_FLAGS="--gas-adjustment 100 --gas auto" +PROVIDER_BINARY="interchain-security-pd" +SOVEREIGN_BINARY="interchain-security-sd" +CONSUMER_BINARY="interchain-security-cdd" +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +SOVEREIGN_RPC_LADDR="$NODE_IP:26648" +SOVEREIGN_GRPC_ADDR="$NODE_IP:9081" +CONSUMER_RPC_LADDR="$NODE_IP:26638" +CONSUMER_GRPC_ADDR="$NODE_IP:9071" +CONSUMER_RPC_LADDR1="$NODE_IP:26628" +CONSUMER_GRPC_ADDR1="$NODE_IP:9061" +CONSUMER_USER="consumer" +SOVEREIGN_VALIDATOR="sovereign_validator" +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_NODE_ADDRESS="tcp://localhost:26658" + +# Clean start +killall $SOVEREIGN_BINARY &> /dev/null || true +killall $CONSUMER_BINARY &> /dev/null || true +rm -rf $CONSUMER_HOME +rm -rf $CONSUMER_HOME1 +rm -rf $SOVEREIGN_HOME + +################SOVEREIGN############################ +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $SOVEREIGN_HOME +sleep 1 + +# Create user account keypair +$SOVEREIGN_BINARY keys add $CONSUMER_USER $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/consumer_keypair.json 2>&1 +$SOVEREIGN_BINARY keys add $SOVEREIGN_VALIDATOR $KEYRING --home $SOVEREIGN_HOME --output json > $SOVEREIGN_HOME/sovereign_validator_keypair.json 2>&1 + +# Add account in genesis (required by Hermes) +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/consumer_keypair.json) 1000000000stake --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY add-genesis-account $(jq -r .address $SOVEREIGN_HOME/sovereign_validator_keypair.json) 1000000000000stake --home $SOVEREIGN_HOME + +# generate genesis for sovereign chain +$SOVEREIGN_BINARY gentx $SOVEREIGN_VALIDATOR 11000000000stake $KEYRING --chain-id=$CONSUMER_CHAIN_ID --home $SOVEREIGN_HOME +$SOVEREIGN_BINARY collect-gentxs --home $SOVEREIGN_HOME +sed -i '' 's/"voting_period": "172800s"/"voting_period": "20s"/g' $SOVEREIGN_HOME/config/genesis.json + +################CONSUMER############################ + +# Build genesis file and node directory structure +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME +sleep 1 + +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME/config/priv_validator_key.json $CONSUMER_HOME/config/priv_validator_key.json +cp $PROVIDER_HOME/config/node_key.json $CONSUMER_HOME/config/node_key.json + +#######CHAIN2####### +$SOVEREIGN_BINARY init --chain-id $CONSUMER_CHAIN_ID $MONIKER --home $CONSUMER_HOME1 +sleep 1 +#copy genesis +cp $SOVEREIGN_HOME/config/genesis.json $CONSUMER_HOME1/config/genesis.json + +# Copy validator key files +cp $PROVIDER_HOME1/config/priv_validator_key.json $CONSUMER_HOME1/config/priv_validator_key.json +cp $PROVIDER_HOME1/config/node_key.json $CONSUMER_HOME1/config/node_key.json + +##########SET CONFIG.TOML##################### +# Set default client port +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${SOVEREIGN_RPC_LADDR}\"/" $SOVEREIGN_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR}\"/" $CONSUMER_HOME/config/client.toml +sed -i -r "/node =/ s/= .*/= \"tcp:\/\/${CONSUMER_RPC_LADDR1}\"/" $CONSUMER_HOME1/config/client.toml +sovereign=$($SOVEREIGN_BINARY tendermint show-node-id --home $SOVEREIGN_HOME) +node=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME) +node1=$($SOVEREIGN_BINARY tendermint show-node-id --home $CONSUMER_HOME1) + +# sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636,$node1@localhost:26626\"/" "$SOVEREIGN_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node1@localhost:26626\"/" "$CONSUMER_HOME"/config/config.toml +# sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646,$node@localhost:26636\"/" "$CONSUMER_HOME1"/config/config.toml + +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26636\"/" "$SOVEREIGN_HOME"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$sovereign@localhost:26646\"/" "$CONSUMER_HOME"/config/config.toml + +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1318\"/" "$CONSUMER_HOME"/config/app.toml +sed -i -r "118s/.*/address = \"tcp:\/\/0.0.0.0:1319\"/" "$CONSUMER_HOME1"/config/app.toml + +# Start the chain +$SOVEREIGN_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$SOVEREIGN_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $SOVEREIGN_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 10 + +######################################HERMES################################### + +# Setup Hermes in packet relayer mode +killall hermes 2> /dev/null || true + +tee ~/.hermes/config.toml<<EOF +[global] +log_level = "trace" + +[mode] + +[mode.clients] +enabled = true +refresh = true +misbehaviour = true + +[mode.connections] +enabled = true + +[mode.channels] +enabled = true + +[mode.packets] +enabled = true + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${CONSUMER_GRPC_ADDR}" +id = "$CONSUMER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${CONSUMER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${CONSUMER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" + +[[chains]] +account_prefix = "cosmos" +clock_drift = "5s" +gas_adjustment = 0.1 +grpc_addr = "tcp://${PROVIDER_GRPC_ADDR}" +id = "$PROVIDER_CHAIN_ID" +key_name = "relayer" +max_gas = 2000000 +rpc_addr = "http://${PROVIDER_RPC_LADDR}" +rpc_timeout = "10s" +store_prefix = "ibc" +trusting_period = "599s" +websocket_addr = "ws://${PROVIDER_RPC_LADDR}/websocket" + +[chains.gas_price] + denom = "stake" + price = 0.00 + +[chains.trust_threshold] + denominator = "3" + numerator = "1" +EOF + +# Delete all previous keys in relayer +hermes keys delete $CONSUMER_CHAIN_ID -a +hermes keys delete $PROVIDER_CHAIN_ID -a + +# Restore keys to hermes relayer +hermes keys restore --mnemonic "$(jq -r .mnemonic $SOVEREIGN_HOME/consumer_keypair.json)" $CONSUMER_CHAIN_ID +# temp_start_provider.sh creates key pair and stores it in keypair.json +hermes keys restore --mnemonic "$(jq -r .mnemonic $PROVIDER_HOME/keypair.json)" $PROVIDER_CHAIN_ID + +sleep 5 + +hermes create client consumer provider +hermes create client provider consumer +# hermes query clients consumer +# hermes query client consensus consumer 07-tendermint-0 +# hermes query clients provider +hermes create connection $CONSUMER_CHAIN_ID --client-a 07-tendermint-0 --client-b 07-tendermint-0 +hermes create channel $CONSUMER_CHAIN_ID --port-a transfer --port-b transfer connection-0 + +sleep 1 + +hermes -j start &> ~/.hermes/logs & + +# Build consumer chain proposal file +tee $PROVIDER_HOME/consumer-proposal.json<<EOF +{ + "title": "Create a chain", + "description": "Gonna be a great chain", + "chain_id": "consumer", + "initial_height": { + "revision_number": 0, + "revision_height": 29 + }, + "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", + "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", + "spawn_time": "2022-06-01T09:10:00.000000000-00:00", + "deposit": "10000001stake", + "consumer_redistribution_fraction": "0.75", + "blocks_per_distribution_transmission": 1000, + "ccv_timeout_period": 2419200000000000, + "transfer_timeout_period": 3600000000000, + "historical_entries": 10000, + "unbonding_period": 1200000000000 +} +EOF + +$PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ + --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +sleep 1 + +# Vote yes to proposal +$PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +sleep 5 + +# ###########################UPGRADE TO SOVEREIGN CHAIN########################## + +$SOVEREIGN_BINARY tx gov submit-proposal software-upgrade "v07-Theta" --upgrade-height=26 \ +--title="upgrade to consumer chain" --description="upgrade to consumer chain description" \ +--from=$SOVEREIGN_VALIDATOR $KEYRING --chain-id=$CONSUMER_CHAIN_ID \ +--home=$SOVEREIGN_HOME --yes -b block --deposit="100000000stake" + +# Vote yes to proposal +$SOVEREIGN_BINARY tx gov vote 1 yes --from $SOVEREIGN_VALIDATOR --chain-id $CONSUMER_CHAIN_ID --node tcp://$SOVEREIGN_RPC_LADDR \ +--home $SOVEREIGN_HOME -b block -y $KEYRING +sleep 30 + +###########################START BINARIES AGAIN AFTER UPGRADE########################## +$SOVEREIGN_BINARY query gov proposals --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR +# $SOVEREIGN_BINARY status --node tcp://$CONSUMER_RPC_LADDR1 + +killall $SOVEREIGN_BINARY &> /dev/null || true + +# Add ccv section to SOVEREIGN_HOME genesis to be used on upgrade handler +if ! $PROVIDER_BINARY q provider consumer-genesis "$CONSUMER_CHAIN_ID" --node "$PROVIDER_NODE_ADDRESS" --output json > "$SOVEREIGN_HOME"/consumer_section.json; +then + echo "Failed to get consumer genesis for the chain-id '$CONSUMER_CHAIN_ID'! Finalize genesis failed. For more details please check the log file in output directory." + exit 1 +fi + +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' "$SOVEREIGN_HOME"/config/genesis.json "$SOVEREIGN_HOME"/consumer_section.json > "$SOVEREIGN_HOME"/genesis_consumer.json && \ + mv "$SOVEREIGN_HOME"/genesis_consumer.json "$SOVEREIGN_HOME"/config/genesis.json + +# Modify genesis params +jq ".app_state.ccvconsumer.params.blocks_per_distribution_transmission = \"70\" | .app_state.tokenfactory.paused = { \"paused\": false }" \ + $SOVEREIGN_HOME/config/genesis.json > \ + $SOVEREIGN_HOME/edited_genesis.json && mv $SOVEREIGN_HOME/edited_genesis.json $SOVEREIGN_HOME/config/genesis.json +sleep 1 + + +$CONSUMER_BINARY start \ + --home $SOVEREIGN_HOME \ + --rpc.laddr tcp://${SOVEREIGN_RPC_LADDR} \ + --grpc.address ${SOVEREIGN_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26645 \ + --p2p.laddr tcp://${NODE_IP}:26646 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $SOVEREIGN_HOME/logs & + +$CONSUMER_BINARY start \ + --home $CONSUMER_HOME \ + --rpc.laddr tcp://${CONSUMER_RPC_LADDR} \ + --grpc.address ${CONSUMER_GRPC_ADDR} \ + --address tcp://${NODE_IP}:26635 \ + --p2p.laddr tcp://${NODE_IP}:26636 \ + --grpc-web.enable=false \ + --log_level trace \ + --trace \ + &> $CONSUMER_HOME/logs & + +# $CONSUMER_BINARY start \ +# --home $CONSUMER_HOME1 \ +# --rpc.laddr tcp://${CONSUMER_RPC_LADDR1} \ +# --grpc.address ${CONSUMER_GRPC_ADDR1} \ +# --address tcp://${NODE_IP}:26625 \ +# --p2p.laddr tcp://${NODE_IP}:26626 \ +# --grpc-web.enable=false \ +# --log_level trace \ +# --trace \ +# &> $CONSUMER_HOME1/logs & +sleep 30 + +# # create channel between consumer and provider between provider port and consumer port +# hermes query clients consumer +# hermes query clients provider +# hermes query client consensus consumer 07-tendermint-1 +# hermes query client consensus provider 07-tendermint-1 +hermes create connection $CONSUMER_CHAIN_ID --client-a 07-tendermint-1 --client-b 07-tendermint-1 +hermes create channel $CONSUMER_CHAIN_ID --port-a consumer --port-b provider -o ordered --channel-version 1 connection-1 + +# ############################################################ + +PROVIDER_VALIDATOR_ADDRESS=$(jq -r .address $PROVIDER_HOME/keypair.json) +DELEGATIONS=$($PROVIDER_BINARY q staking delegations $PROVIDER_VALIDATOR_ADDRESS --home $PROVIDER_HOME --node tcp://${PROVIDER_RPC_LADDR} -o json) +OPERATOR_ADDR=$(echo $DELEGATIONS | jq -r .delegation_responses[0].delegation.validator_address) + +$PROVIDER_BINARY tx staking delegate $OPERATOR_ADDR 32000000stake \ + --from $VALIDATOR \ + $KEYRING \ + --home $PROVIDER_HOME \ + --node tcp://${PROVIDER_RPC_LADDR} \ + --chain-id $PROVIDER_CHAIN_ID -y -b block +sleep 1 + +$PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR} +# $PROVIDER_BINARY status --node=tcp://${PROVIDER_RPC_LADDR1} + +$CONSUMER_BINARY status --node tcp://$SOVEREIGN_RPC_LADDR +$CONSUMER_BINARY status --node tcp://$CONSUMER_RPC_LADDR + +# $CONSUMER_BINARY query staking params --node=tcp://$CONSUMER_RPC_LADDR +# $PROVIDER_BINARY query staking params --node=tcp://${PROVIDER_RPC_LADDR} diff --git a/tests/sovereign_consumer_upgrade_local/start_provider.sh b/tests/sovereign_consumer_upgrade_local/start_provider.sh new file mode 100644 index 0000000000..149cf32f80 --- /dev/null +++ b/tests/sovereign_consumer_upgrade_local/start_provider.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -eux + +TOTAL_COINS=100000000000stake +STAKE_COINS=100000000stake +TOTAL_COINS1=120000000000stake +STAKE_COINS1=1000000stake +PROVIDER_BINARY=interchain-security-pd +PROVIDER_HOME="$HOME/.provider" +PROVIDER_HOME1="$HOME/.provider1" +PROVIDER_CHAIN_ID=provider +PROVIDER_MONIKER=provider +VALIDATOR=validator +VALIDATOR1=validator1 +NODE_IP="localhost" +PROVIDER_RPC_LADDR="$NODE_IP:26658" +PROVIDER_GRPC_ADDR="$NODE_IP:9091" +PROVIDER_RPC_LADDR1="$NODE_IP:26668" +PROVIDER_GRPC_ADDR1="$NODE_IP:9101" +PROVIDER_DELEGATOR=delegator + +# Clean start +killall $PROVIDER_BINARY &> /dev/null || true + +#######VALIDATOR1####################### +rm -rf $PROVIDER_HOME + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME --chain-id $PROVIDER_CHAIN_ID +jq ".app_state.gov.voting_params.voting_period = \"3s\" | .app_state.staking.params.unbonding_time = \"600s\" | .app_state.provider.params.template_client.trusting_period = \"300s\"" \ + $PROVIDER_HOME/config/genesis.json > \ + $PROVIDER_HOME/edited_genesis.json && mv $PROVIDER_HOME/edited_genesis.json $PROVIDER_HOME/config/genesis.json +sleep 1 + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair.json 2>&1 +sleep 1 +$PROVIDER_BINARY keys add $PROVIDER_DELEGATOR --home $PROVIDER_HOME --keyring-backend test --output json > $PROVIDER_HOME/keypair_delegator.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME/keypair_delegator.json) $TOTAL_COINS --home $PROVIDER_HOME --keyring-backend test +sleep 1 + +# Stake 1/1000 user's coins +$PROVIDER_BINARY gentx $VALIDATOR $STAKE_COINS --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME --keyring-backend test --moniker $VALIDATOR +sleep 1 + +###########VALIDATOR 2############################ +rm -rf $PROVIDER_HOME1 + +$PROVIDER_BINARY init $PROVIDER_MONIKER --home $PROVIDER_HOME1 --chain-id $PROVIDER_CHAIN_ID +cp $PROVIDER_HOME/config/genesis.json $PROVIDER_HOME1/config/genesis.json + +# Create account keypair +$PROVIDER_BINARY keys add $VALIDATOR1 --home $PROVIDER_HOME1 --keyring-backend test --output json > $PROVIDER_HOME1/keypair.json 2>&1 +sleep 1 + +# Add stake to user +$PROVIDER_BINARY add-genesis-account $(jq -r .address $PROVIDER_HOME1/keypair.json) $TOTAL_COINS1 --home $PROVIDER_HOME1 --keyring-backend test +sleep 1 + +####################GENTX AND DISTRIBUTE GENESIS############################## +cp -r $PROVIDER_HOME/config/gentx $PROVIDER_HOME1/config/ + +# Stake 1/1000 user's coins +# $PROVIDER_BINARY gentx $VALIDATOR1 $STAKE_COINS1 --chain-id $PROVIDER_CHAIN_ID --home $PROVIDER_HOME1 --keyring-backend test --moniker $VALIDATOR1 +# sleep 1 + +$PROVIDER_BINARY collect-gentxs --home $PROVIDER_HOME1 --gentx-dir $PROVIDER_HOME1/config/gentx/ +sleep 1 + +cp $PROVIDER_HOME1/config/genesis.json $PROVIDER_HOME/config/genesis.json + +####################ADDING PEERS#################### +node=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME) +node1=$($PROVIDER_BINARY tendermint show-node-id --home $PROVIDER_HOME1) +sed -i -r "/persistent_peers =/ s/= .*/= \"$node@localhost:26656\"/" "$PROVIDER_HOME1"/config/config.toml +sed -i -r "/persistent_peers =/ s/= .*/= \"$node1@localhost:26666\"/" "$PROVIDER_HOME"/config/config.toml + +#################### Start the chain node1 ################### +$PROVIDER_BINARY start \ + --home $PROVIDER_HOME \ + --rpc.laddr tcp://$PROVIDER_RPC_LADDR \ + --grpc.address $PROVIDER_GRPC_ADDR \ + --address tcp://${NODE_IP}:26655 \ + --p2p.laddr tcp://${NODE_IP}:26656 \ + --grpc-web.enable=false \ + --trace \ + &> $PROVIDER_HOME/logs & + +#################### Start the chain node2 ################### +# $PROVIDER_BINARY start \ +# --home $PROVIDER_HOME1 \ +# --rpc.laddr tcp://$PROVIDER_RPC_LADDR1 \ +# --grpc.address $PROVIDER_GRPC_ADDR1 \ +# --address tcp://${NODE_IP}:26665 \ +# --p2p.laddr tcp://${NODE_IP}:26666 \ +# --grpc-web.enable=false \ +# --trace \ +# &> $PROVIDER_HOME1/logs & +sleep 10 + +# # Build consumer chain proposal file +# tee $PROVIDER_HOME/consumer-proposal.json<<EOF +# { +# "title": "Create a chain", +# "description": "Gonna be a great chain", +# "chain_id": "consumer", +# "initial_height": { +# "revision_number": 0, +# "revision_height": 1 +# }, +# "genesis_hash": "519df96a862c30f53e67b1277e6834ab4bd59dfdd08c781d1b7cf3813080fb28", +# "binary_hash": "09184916f3e85aa6fa24d3c12f1e5465af2214f13db265a52fa9f4617146dea5", +# "spawn_time": "2022-06-01T09:10:00.000000000-00:00", +# "deposit": "10000001stake", +# "consumer_redistribution_fraction": "0.75", +# "blocks_per_distribution_transmission": 1000, +# "ccv_timeout_period": 2419200000000000, +# "transfer_timeout_period": 3600000000000, +# "historical_entries": 10000, +# "unbonding_period": 1200000000000 +# } +# EOF + +# $PROVIDER_BINARY tx gov submit-proposal consumer-addition $PROVIDER_HOME/consumer-proposal.json \ +# --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --from $VALIDATOR --home $PROVIDER_HOME --keyring-backend test -b block -y +# sleep 1 + +# # Vote yes to proposal +# $PROVIDER_BINARY tx gov vote 1 yes --from $VALIDATOR --chain-id $PROVIDER_CHAIN_ID --node tcp://$PROVIDER_RPC_LADDR --home $PROVIDER_HOME -b block -y --keyring-backend test +# sleep 5 diff --git a/x/ccv/consumer/ibc_module_test.go b/x/ccv/consumer/ibc_module_test.go index cfa4e61166..db2e1b713b 100644 --- a/x/ccv/consumer/ibc_module_test.go +++ b/x/ccv/consumer/ibc_module_test.go @@ -124,7 +124,7 @@ func TestOnChanOpenInit(t *testing.T) { // Common setup consumerKeeper, ctx, ctrl, mocks := testkeeper.GetConsumerKeeperAndCtx( t, testkeeper.NewInMemKeeperParams(t)) - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) consumerKeeper.SetPort(ctx, ccv.ConsumerPortID) consumerKeeper.SetProviderClientID(ctx, "clientIDToProvider") @@ -175,7 +175,7 @@ func TestOnChanOpenTry(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) // No external keeper methods should be called defer ctrl.Finish() - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) // OnOpenTry must error even with correct arguments _, err := consumerModule.OnChanOpenTry( @@ -269,7 +269,7 @@ func TestOnChanOpenAck(t *testing.T) { // Common setup consumerKeeper, ctx, ctrl, mocks := testkeeper.GetConsumerKeeperAndCtx( t, testkeeper.NewInMemKeeperParams(t)) - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) // Instantiate valid params as default. Individual test cases mutate these as needed. params := params{ @@ -319,7 +319,7 @@ func TestOnChanOpenAck(t *testing.T) { func TestOnChanOpenConfirm(t *testing.T) { consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) defer ctrl.Finish() - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) err := consumerModule.OnChanOpenConfirm(ctx, ccv.ConsumerPortID, "channel-1") require.Error(t, err, "OnChanOpenConfirm callback must error on consumer chain") @@ -359,7 +359,7 @@ func TestOnChanCloseInit(t *testing.T) { for _, tc := range testCases { consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t)) - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) if tc.establishedProviderExists { consumerKeeper.SetProviderChannel(ctx, "provider") @@ -387,7 +387,7 @@ func TestOnChanCloseConfirm(t *testing.T) { // No external keeper methods should be called defer ctrl.Finish() - consumerModule := consumer.NewAppModule(consumerKeeper) + consumerModule := consumer.NewAppModule(consumerKeeper, nil) // Nothing happens, no error returned err := consumerModule.OnChanCloseConfirm(ctx, "portID", "channelID") diff --git a/x/ccv/consumer/keeper/genesis.go b/x/ccv/consumer/keeper/genesis.go index b97a5d00f8..7ceeef7e26 100644 --- a/x/ccv/consumer/keeper/genesis.go +++ b/x/ccv/consumer/keeper/genesis.go @@ -17,6 +17,12 @@ import ( // 2. A consumer chain restarts after a client to the provider was created, but the CCV channel handshake is still in progress // 3. A consumer chain restarts after the CCV channel handshake was completed. func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate { + // PreCCV is true when consumer chain used to be running on non-consumer chain, and when it is in the progress of upgrading + // to consumer chain, where consumer chain upgrade is done. + if state.PreCCV { + k.SetPreCCV(ctx, state) + } + k.SetParams(ctx, state.Params) // TODO: Remove enabled flag and find a better way to setup e2e tests // See: https://github.com/cosmos/interchain-security/issues/339 @@ -87,7 +93,10 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) // set provider client id k.SetProviderClientID(ctx, state.ProviderClientId) + } + if state.PreCCV { + return []abci.ValidatorUpdate{} } // populate cross chain validators states with initial valset diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 95f72689e0..f2e235756a 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/interchain-security/x/ccv/consumer/types" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" + tmtypes "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" ) @@ -32,6 +33,7 @@ type Keeper struct { portKeeper ccv.PortKeeper connectionKeeper ccv.ConnectionKeeper clientKeeper ccv.ClientKeeper + stakingKeeper ccv.StakingKeeper slashingKeeper ccv.SlashingKeeper hooks ccv.ConsumerHooks bankKeeper ccv.BankKeeper @@ -49,6 +51,7 @@ func NewKeeper( scopedKeeper ccv.ScopedKeeper, channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper, connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper, + stakingKeeper ccv.StakingKeeper, slashingKeeper ccv.SlashingKeeper, bankKeeper ccv.BankKeeper, accountKeeper ccv.AccountKeeper, ibcTransferKeeper ccv.IBCTransferKeeper, ibcCoreKeeper ccv.IBCCoreKeeper, feeCollectorName string, @@ -67,6 +70,7 @@ func NewKeeper( portKeeper: portKeeper, connectionKeeper: connectionKeeper, clientKeeper: clientKeeper, + stakingKeeper: stakingKeeper, slashingKeeper: slashingKeeper, bankKeeper: bankKeeper, authKeeper: accountKeeper, @@ -211,6 +215,57 @@ func (k Keeper) DeletePendingChanges(ctx sdk.Context) { store.Delete(types.PendingChangesKey()) } +func (k Keeper) LastSovereignHeight(ctx sdk.Context) int64 { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.LastSovereignHeightKey()) + if bz == nil { + return 0 + } + height := sdk.BigEndianToUint64(bz) + return int64(height) +} + +func (k Keeper) SetLastSovereignHeight(ctx sdk.Context, height int64) { + bz := sdk.Uint64ToBigEndian(uint64(height)) + store := ctx.KVStore(k.storeKey) + store.Set(types.LastSovereignHeightKey(), bz) +} + +func (k Keeper) IsPreCCV(ctx sdk.Context) bool { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PreCCVKey()) + if bz != nil { + return true + } + return false +} + +func (k Keeper) SetPreCCV(ctx sdk.Context, state *types.GenesisState) { + initialValSet := types.GenesisState{ + InitialValSet: state.InitialValSet, + } + bz := k.cdc.MustMarshal(&initialValSet) + store := ctx.KVStore(k.storeKey) + store.Set(types.PreCCVKey(), bz) +} + +func (k Keeper) DeletePreCCV(ctx sdk.Context) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.PreCCVKey()) +} + +func (k Keeper) GetInitialValSet(ctx sdk.Context) []tmtypes.ValidatorUpdate { + store := ctx.KVStore(k.storeKey) + initialValSet := types.GenesisState{} + bz := store.Get(types.PreCCVKey()) + if bz != nil { + k.cdc.MustUnmarshal(bz, &initialValSet) + return initialValSet.InitialValSet + } + + return []tmtypes.ValidatorUpdate{} +} + // GetElapsedPacketMaturityTimes returns a slice of already elapsed PacketMaturityTimes, sorted by maturity times, // i.e., the slice contains the IDs of the matured VSCPackets. func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []consumertypes.MaturingVSCPacket) { diff --git a/x/ccv/consumer/keeper/validators.go b/x/ccv/consumer/keeper/validators.go index debb4c66ce..0d963da511 100644 --- a/x/ccv/consumer/keeper/validators.go +++ b/x/ccv/consumer/keeper/validators.go @@ -61,24 +61,43 @@ func (k Keeper) ApplyCCValidatorChanges(ctx sdk.Context, changes []abci.Validato return ret } -// IterateValidators - unimplemented on CCV keeper but perform a no-op in order to pass the slashing module InitGenesis. -// It is allowed since the condition verifying validator public keys in HandleValidatorSignature (x/slashing/keeper/infractions.go) is removed -// therefore it isn't required to store any validator public keys to the slashing states during genesis. -func (k Keeper) IterateValidators(sdk.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool)) { +// IterateValidators iterate democracy staking validators when the block height is before the last sovereign height +func (k Keeper) IterateValidators(ctx sdk.Context, f func(index int64, validator stakingtypes.ValidatorI) (stop bool)) { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + panic("empty staking keeper") + } + + k.stakingKeeper.IterateValidators(ctx, f) + } } -// Validator - unimplemented on CCV keeper +// Validator returns democracy staking validator when the block height is before the last sovereign height func (k Keeper) Validator(ctx sdk.Context, addr sdk.ValAddress) stakingtypes.ValidatorI { - panic("unimplemented on CCV keeper") + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + panic("empty staking keeper") + } + + return k.stakingKeeper.Validator(ctx, addr) + } + panic("unused after preCCV") } // IsJailed returns the outstanding slashing flag for the given validator adddress func (k Keeper) IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + panic("empty staking keeper") + } + + return k.stakingKeeper.IsValidatorJailed(ctx, addr) + } return k.OutstandingDowntime(ctx, addr) } // ValidatorByConsAddr returns an empty validator -func (k Keeper) ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI { +func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) stakingtypes.ValidatorI { /* NOTE: @@ -89,16 +108,32 @@ func (k Keeper) ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.V Also, the slashing module will cal lthis function when it observes downtime. In that case the only requirement on the returned value is that it isn't null. */ + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + return stakingtypes.Validator{} + } + + return k.stakingKeeper.ValidatorByConsAddr(ctx, consAddr) + } return stakingtypes.Validator{} } // Slash queues a slashing request for the the provider chain // All queued slashing requests will be cleared in EndBlock -func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, _ sdk.Dec, infraction stakingtypes.InfractionType) { +func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, infraction stakingtypes.InfractionType) { if infraction == stakingtypes.InfractionEmpty { return } + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + return + } + + k.stakingKeeper.Slash(ctx, addr, infractionHeight, power, slashFactor, infraction) + return + } + // get VSC ID for infraction height vscID := k.GetHeightValsetUpdateID(ctx, uint64(infractionHeight)) @@ -117,20 +152,51 @@ func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, p ) } -// Jail - unimplemented on CCV keeper -func (k Keeper) Jail(ctx sdk.Context, addr sdk.ConsAddress) {} +// Jail performs jail operation on democracy staking validator if block height after last sovereign height +func (k Keeper) Jail(ctx sdk.Context, addr sdk.ConsAddress) { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + return + } + + k.stakingKeeper.Jail(ctx, addr) + return + } +} + +// Unjail performs unjail operation on democracy staking validator if block height after last sovereign height +func (k Keeper) Unjail(ctx sdk.Context, addr sdk.ConsAddress) { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + return + } + + k.stakingKeeper.Unjail(ctx, addr) + } +} -// Unjail - unimplemented on CCV keeper -func (k Keeper) Unjail(sdk.Context, sdk.ConsAddress) {} +// Delegation returns delegation from an address to a democracy staking validator if block height after last sovereign height +func (k Keeper) Delegation(ctx sdk.Context, addr sdk.AccAddress, valAddr sdk.ValAddress) stakingtypes.DelegationI { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + panic("empty staking keeper") + } -// Delegation - unimplemented on CCV keeper -func (k Keeper) Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingtypes.DelegationI { - panic("unimplemented on CCV keeper") + return k.stakingKeeper.Delegation(ctx, addr, valAddr) + } + panic("unused after preCCV") } -// MaxValidators - unimplemented on CCV keeper -func (k Keeper) MaxValidators(sdk.Context) uint32 { - panic("unimplemented on CCV keeper") +// MaxValidators returns max number of validators on democracy staking if block height after last sovereign height +func (k Keeper) MaxValidators(ctx sdk.Context) uint32 { + if k.IsPreCCV(ctx) || ctx.BlockHeight() <= k.LastSovereignHeight(ctx) { + if k.stakingKeeper == nil { + panic("empty staking keeper") + } + + return k.stakingKeeper.MaxValidators(ctx) + } + panic("unused after preCCV") } // UnbondingTime returns consumer unbonding period, satisfying the staking keeper interface diff --git a/x/ccv/consumer/module.go b/x/ccv/consumer/module.go index 68a2d60c1c..988d74ed19 100644 --- a/x/ccv/consumer/module.go +++ b/x/ccv/consumer/module.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" + ccvtypes "github.com/cosmos/interchain-security/x/ccv/types" ) var ( @@ -92,12 +93,14 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic keeper keeper.Keeper + sk ccvtypes.DemocracyStakingKeeper } // NewAppModule creates a new consumer module -func NewAppModule(k keeper.Keeper) AppModule { +func NewAppModule(k keeper.Keeper, sk ccvtypes.DemocracyStakingKeeper) AppModule { return AppModule{ keeper: k, + sk: sk, } } @@ -149,6 +152,7 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } // Set the VSC ID for the subsequent block to the same value as the current block // Panic if the provider's channel was established and then closed func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + channelID, found := am.keeper.GetProviderChannel(ctx) if found && am.keeper.IsChannelClosed(ctx, channelID) { // The CCV channel was established, but it was then closed; @@ -172,6 +176,30 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { // EndBlock implements the AppModule interface // Flush PendingChanges to ABCI, send pending packets, write acknowledgements for packets that have finished unbonding. func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { + if am.keeper.IsPreCCV(ctx) { + initialValSet := am.keeper.GetInitialValSet(ctx) + // Note: validator set update is only done on consumer chain from first endblocker + // on soft fork from existing chain + am.keeper.DeletePreCCV(ctx) + // set last sovereign height + am.keeper.SetLastSovereignHeight(ctx, ctx.BlockHeight()) + // populate cross chain validators states with initial valset + am.keeper.ApplyCCValidatorChanges(ctx, initialValSet) + + initialSetFlag := make(map[string]bool) + for _, val := range initialValSet { + initialSetFlag[val.PubKey.String()] = true + } + for _, val := range am.sk.GetLastValidators(ctx) { + update := val.ABCIValidatorUpdateZero() + if !initialSetFlag[update.PubKey.String()] { + initialValSet = append(initialValSet, update) + } + } + + return initialValSet + } + // Execute EndBlock logic for the Reward Distribution sub-protocol am.keeper.EndBlockRD(ctx) diff --git a/x/ccv/consumer/module_test.go b/x/ccv/consumer/module_test.go new file mode 100644 index 0000000000..0851aa3188 --- /dev/null +++ b/x/ccv/consumer/module_test.go @@ -0,0 +1,119 @@ +package consumer_test + +import ( + "encoding/json" + "testing" + + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/staking/teststaking" + ccvstakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + democracyapp "github.com/cosmos/interchain-security/app/consumer-democracy" + "github.com/cosmos/interchain-security/x/ccv/consumer" + "github.com/cosmos/interchain-security/x/ccv/consumer/types" + "github.com/stretchr/testify/require" + "github.com/tendermint/spm/cosmoscmd" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + dbm "github.com/tendermint/tm-db" +) + +func TestEndBlock(t *testing.T) { + PKs := simapp.CreateTestPubKeys(500) + validator1 := teststaking.NewValidator(t, sdk.ValAddress(PKs[0].Address().Bytes()), PKs[0]) + validator2 := teststaking.NewValidator(t, sdk.ValAddress(PKs[1].Address().Bytes()), PKs[1]) + _ = validator2 + + tmPK1, err := cryptocodec.ToTmPubKeyInterface(PKs[0]) + require.NoError(t, err) + tmValidator1 := tmtypes.NewValidator(tmPK1, 1) + _ = tmValidator1 + + tmPK2, err := cryptocodec.ToTmPubKeyInterface(PKs[1]) + require.NoError(t, err) + tmValidator2 := tmtypes.NewValidator(tmPK2, 1) + _ = tmValidator2 + + tmPK3, err := cryptocodec.ToTmPubKeyInterface(PKs[2]) + require.NoError(t, err) + tmValidator3 := tmtypes.NewValidator(tmPK3, 1) + _ = tmValidator3 + + testCases := []struct { + name string + preCCV bool + sovereignValidators []ccvstakingtypes.Validator + providerValidators []abci.ValidatorUpdate + expValUpdateLen int + }{ + { + name: "case not preCCV", + preCCV: false, + sovereignValidators: []ccvstakingtypes.Validator{validator1}, + providerValidators: []abci.ValidatorUpdate{tmtypes.TM2PB.ValidatorUpdate(tmValidator1)}, + expValUpdateLen: 1, + }, + { + name: "case preCCV - no duplication with sovereign validators", + preCCV: true, + sovereignValidators: []ccvstakingtypes.Validator{validator1, validator2}, + providerValidators: []abci.ValidatorUpdate{tmtypes.TM2PB.ValidatorUpdate(tmValidator3)}, + expValUpdateLen: 3, + }, + { + name: "case preCCV - duplication with sovereign validators", + preCCV: true, + sovereignValidators: []ccvstakingtypes.Validator{validator1, validator2}, + providerValidators: []abci.ValidatorUpdate{tmtypes.TM2PB.ValidatorUpdate(tmValidator2), tmtypes.TM2PB.ValidatorUpdate(tmValidator3)}, + expValUpdateLen: 3, + }, + } + + for _, tc := range testCases { + db := dbm.NewMemDB() + encodingConfig := cosmoscmd.MakeEncodingConfig(democracyapp.ModuleBasics) + appCodec := encodingConfig.Marshaler + app := democracyapp.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, "", 5, encodingConfig, simapp.EmptyAppOptions{}) + dApp := app.(*democracyapp.App) + ctx := dApp.BaseApp.NewContext(true, tmproto.Header{}) + + genesisState := democracyapp.NewDefaultGenesisState(appCodec) + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + if err != nil { + panic(err) + } + + app.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: simapp.DefaultConsensusParams, + AppStateBytes: stateBytes, + }, + ) + + dApp.StakingKeeper.SetParams(ctx, ccvstakingtypes.DefaultParams()) + for _, val := range tc.sovereignValidators { + dApp.StakingKeeper.SetValidator(ctx, val) + dApp.StakingKeeper.SetLastValidatorPower(ctx, val.GetOperator(), 1) + } + + dApp.ConsumerKeeper.SetPreCCV(ctx, &types.GenesisState{ + InitialValSet: tc.providerValidators, + PreCCV: tc.preCCV, + }) + consumerModule := consumer.NewAppModule(dApp.ConsumerKeeper, dApp.StakingKeeper) + + valUpdate := consumerModule.EndBlock( + ctx, + abci.RequestEndBlock{}, + ) + + // check returned initial validators are expected values + require.Len(t, valUpdate, tc.expValUpdateLen) + // check preCCV deleted after the execution + require.False(t, dApp.ConsumerKeeper.IsPreCCV(ctx)) + } +} diff --git a/x/ccv/consumer/types/genesis.pb.go b/x/ccv/consumer/types/genesis.pb.go index d55baa92ad..47253f25a1 100644 --- a/x/ccv/consumer/types/genesis.pb.go +++ b/x/ccv/consumer/types/genesis.pb.go @@ -50,6 +50,7 @@ type GenesisState struct { PendingConsumerPackets types2.ConsumerPacketDataList `protobuf:"bytes,11,opt,name=pending_consumer_packets,json=pendingConsumerPackets,proto3" json:"pending_consumer_packets"` // LastTransmissionBlockHeight nil on new chain, filled in on restart. LastTransmissionBlockHeight LastTransmissionBlockHeight `protobuf:"bytes,12,opt,name=last_transmission_block_height,json=lastTransmissionBlockHeight,proto3" json:"last_transmission_block_height"` + PreCCV bool `protobuf:"varint,13,opt,name=preCCV,proto3" json:"preCCV,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -169,6 +170,13 @@ func (m *GenesisState) GetLastTransmissionBlockHeight() LastTransmissionBlockHei return LastTransmissionBlockHeight{} } +func (m *GenesisState) GetPreCCV() bool { + if m != nil { + return m.PreCCV + } + return false +} + // HeightValsetUpdateID defines the genesis information for the mapping // of each block height to a valset update id type HeightToValsetUpdateID struct { @@ -280,56 +288,56 @@ func init() { } var fileDescriptor_2db73a6057a27482 = []byte{ - // 773 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xcf, 0x6f, 0xdb, 0x36, - 0x14, 0xb6, 0x92, 0xcc, 0xb3, 0x99, 0x6c, 0xc9, 0x98, 0xcd, 0xd0, 0x6c, 0x4c, 0xf3, 0xb2, 0x1d, - 0x0c, 0x6c, 0x93, 0x60, 0x0f, 0x18, 0x86, 0x15, 0x28, 0xda, 0x24, 0x40, 0x6b, 0x20, 0x6d, 0x03, - 0x3b, 0xf1, 0x21, 0x17, 0x81, 0xa6, 0x58, 0x89, 0x88, 0x44, 0x1a, 0x22, 0xa5, 0x34, 0x87, 0x5e, - 0x7a, 0xed, 0xa5, 0x7f, 0x56, 0x8e, 0x39, 0xf6, 0x14, 0x14, 0xc9, 0x3f, 0x52, 0x88, 0xa4, 0xfc, - 0xa3, 0x71, 0x50, 0x9f, 0x4c, 0xf2, 0x7d, 0xef, 0xfb, 0xde, 0x7b, 0x1f, 0x4d, 0x81, 0x2e, 0x65, - 0x92, 0xa4, 0x38, 0x42, 0x94, 0xf9, 0x82, 0xe0, 0x2c, 0xa5, 0xf2, 0xd2, 0xc3, 0x38, 0xf7, 0x30, - 0x67, 0x22, 0x4b, 0x48, 0xea, 0xe5, 0x5d, 0x2f, 0x24, 0x8c, 0x08, 0x2a, 0xdc, 0x49, 0xca, 0x25, - 0x87, 0xbf, 0x2f, 0x49, 0x71, 0x31, 0xce, 0xdd, 0x32, 0xc5, 0xcd, 0xbb, 0xcd, 0x3f, 0x1e, 0xe2, - 0xcd, 0xbb, 0xc5, 0x8f, 0xa6, 0x6a, 0xf6, 0x56, 0x51, 0x9f, 0xd2, 0xea, 0x9c, 0x96, 0x24, 0x2c, - 0x20, 0x69, 0x42, 0x99, 0xf4, 0xd0, 0x18, 0x53, 0x4f, 0x5e, 0x4e, 0x88, 0xa9, 0xad, 0xe9, 0xd1, - 0x31, 0xf6, 0x62, 0x1a, 0x46, 0x12, 0xc7, 0x94, 0x30, 0x29, 0xbc, 0x39, 0x74, 0xde, 0x9d, 0xdb, - 0x99, 0x84, 0xdf, 0x8a, 0x04, 0xcc, 0x53, 0xe2, 0xe1, 0x08, 0x31, 0x46, 0x62, 0xa5, 0xa8, 0x97, - 0x06, 0xe2, 0x84, 0x9c, 0x87, 0x31, 0xf1, 0xd4, 0x6e, 0x9c, 0xbd, 0xf6, 0x82, 0x2c, 0x45, 0x92, - 0x72, 0x66, 0xe2, 0x3f, 0x86, 0x3c, 0xe4, 0x6a, 0xe9, 0x15, 0x2b, 0x7d, 0xba, 0x77, 0x53, 0x03, - 0x5b, 0xcf, 0xf4, 0xdc, 0x86, 0x12, 0x49, 0x02, 0xfb, 0xa0, 0x3a, 0x41, 0x29, 0x4a, 0x84, 0x6d, - 0xb5, 0xad, 0xce, 0x66, 0xef, 0x4f, 0x77, 0x85, 0x39, 0xba, 0xc7, 0x2a, 0x65, 0x7f, 0xe3, 0xea, - 0xe6, 0xd7, 0xca, 0xc0, 0x10, 0xc0, 0xbf, 0x00, 0x9c, 0xa4, 0x3c, 0xa7, 0x01, 0x49, 0x7d, 0xdd, - 0xa7, 0x4f, 0x03, 0x7b, 0xad, 0x6d, 0x75, 0xea, 0x83, 0x9d, 0x32, 0x72, 0xa0, 0x02, 0xfd, 0x00, - 0xba, 0x60, 0x77, 0x86, 0xd6, 0x9d, 0x15, 0xf0, 0x75, 0x05, 0xff, 0x61, 0x0a, 0xd7, 0x91, 0x7e, - 0x00, 0x5b, 0xa0, 0xce, 0xc8, 0x85, 0xaf, 0x0a, 0xb3, 0x37, 0xda, 0x56, 0xa7, 0x36, 0xa8, 0x31, - 0x72, 0x71, 0x50, 0xec, 0xa1, 0x0f, 0x7e, 0xfa, 0x52, 0x5a, 0x14, 0xed, 0xd9, 0xdf, 0x94, 0x4d, - 0x8d, 0xb1, 0x3b, 0x6f, 0x80, 0x3b, 0x37, 0xf2, 0xbc, 0xeb, 0xea, 0xaa, 0xd4, 0x44, 0x06, 0xbb, - 0x8b, 0xa5, 0xea, 0x31, 0x45, 0xc0, 0x9e, 0x09, 0x70, 0x26, 0x08, 0x13, 0x99, 0x30, 0x1a, 0x55, - 0xa5, 0xe1, 0x7e, 0x55, 0xa3, 0x4c, 0xd3, 0x32, 0x8d, 0xa9, 0xcc, 0xc2, 0x39, 0x0c, 0xc1, 0x4e, - 0x82, 0x64, 0x96, 0x52, 0x16, 0xfa, 0x13, 0x84, 0xcf, 0x89, 0x14, 0xf6, 0xb7, 0xed, 0xf5, 0xce, - 0x66, 0xef, 0xdf, 0x95, 0xac, 0x79, 0x61, 0x92, 0x47, 0xc3, 0x83, 0x63, 0x95, 0x6e, 0x5c, 0xda, - 0x2e, 0x59, 0xf5, 0xa9, 0x80, 0x2f, 0xc1, 0x36, 0x65, 0x54, 0x52, 0x14, 0xfb, 0x39, 0x8a, 0x7d, - 0x41, 0xa4, 0x5d, 0x53, 0x3a, 0xed, 0xf9, 0xc2, 0x8b, 0xbb, 0xec, 0x8e, 0x50, 0x4c, 0x03, 0x24, - 0x79, 0x7a, 0x3a, 0x09, 0x90, 0x24, 0x86, 0xf1, 0x3b, 0x93, 0x3e, 0x42, 0xf1, 0x90, 0x48, 0xf8, - 0x16, 0x34, 0x23, 0x52, 0xb4, 0xef, 0x4b, 0x5e, 0x30, 0x0a, 0x22, 0xfd, 0x4c, 0xe1, 0x0b, 0x5f, - 0xeb, 0x8a, 0xfa, 0xd1, 0x4a, 0x2d, 0x3c, 0x57, 0x34, 0x27, 0x7c, 0xa4, 0x48, 0xb4, 0x66, 0xff, - 0xd0, 0xa8, 0x36, 0xa2, 0x65, 0xd1, 0x00, 0xbe, 0xb3, 0xc0, 0x2f, 0x3c, 0x93, 0x42, 0x22, 0x16, - 0x14, 0xb3, 0x0b, 0xf8, 0x05, 0x93, 0x34, 0x21, 0xbe, 0x88, 0x91, 0x88, 0x28, 0x0b, 0x6d, 0xa0, - 0x4a, 0xf8, 0x6f, 0xa5, 0x12, 0x5e, 0xcd, 0x98, 0x0e, 0x0d, 0x91, 0xd1, 0x6f, 0xf1, 0xfb, 0xa1, - 0xa1, 0x91, 0x80, 0x29, 0xb0, 0x27, 0x44, 0xeb, 0x97, 0x6c, 0x53, 0x13, 0x37, 0xd5, 0x35, 0xe9, - 0x3d, 0x28, 0x6f, 0xae, 0x48, 0x91, 0xa3, 0x2d, 0x3a, 0x44, 0x12, 0x1d, 0x51, 0x51, 0x1a, 0xd8, - 0x30, 0xcc, 0x8b, 0x20, 0x01, 0xdf, 0x5b, 0xc0, 0x89, 0x91, 0x90, 0xbe, 0x4c, 0x11, 0x13, 0x09, - 0x15, 0x82, 0x72, 0xe6, 0x8f, 0x63, 0x8e, 0xcf, 0x7d, 0x3d, 0x2b, 0x7b, 0x4b, 0x49, 0x3f, 0x59, - 0xa9, 0xf3, 0x23, 0x24, 0xe4, 0xc9, 0x1c, 0xd3, 0x7e, 0x41, 0xa4, 0x1d, 0x29, 0x27, 0x10, 0x3f, - 0x0c, 0xd9, 0x3b, 0x03, 0x8d, 0xe5, 0xf6, 0xc1, 0x06, 0xa8, 0x9a, 0x72, 0x8a, 0x97, 0x66, 0x63, - 0x60, 0x76, 0xb0, 0x03, 0x76, 0xee, 0xdd, 0x96, 0x35, 0x85, 0xf8, 0x3e, 0x5f, 0xb0, 0x78, 0xef, - 0x14, 0xec, 0x2e, 0xf1, 0x05, 0x3e, 0x06, 0xad, 0xbc, 0xbc, 0xa0, 0x73, 0x7f, 0x4e, 0x14, 0x04, - 0x29, 0x11, 0xfa, 0x5d, 0xab, 0x0f, 0x7e, 0x9e, 0x42, 0xa6, 0xff, 0xb7, 0xa7, 0x1a, 0xb0, 0x7f, - 0x72, 0x75, 0xeb, 0x58, 0xd7, 0xb7, 0x8e, 0xf5, 0xe9, 0xd6, 0xb1, 0x3e, 0xdc, 0x39, 0x95, 0xeb, - 0x3b, 0xa7, 0xf2, 0xf1, 0xce, 0xa9, 0x9c, 0xfd, 0x1f, 0x52, 0x19, 0x65, 0x63, 0x17, 0xf3, 0xc4, - 0xc3, 0x5c, 0x24, 0x5c, 0x78, 0xb3, 0x11, 0xfe, 0x3d, 0xfd, 0x34, 0xbc, 0x59, 0xfc, 0x38, 0xa8, - 0x97, 0x7f, 0x5c, 0x55, 0x0f, 0xee, 0x3f, 0x9f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xb4, 0x5a, 0x50, - 0x50, 0xcb, 0x06, 0x00, 0x00, + // 782 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xcf, 0x6f, 0xeb, 0x34, + 0x1c, 0x6f, 0xde, 0x1b, 0xa5, 0xf5, 0xde, 0xe3, 0x0d, 0x0f, 0xaa, 0xd0, 0x8a, 0x50, 0x06, 0x87, + 0x4a, 0x40, 0xa2, 0x16, 0x09, 0x21, 0x90, 0x10, 0xac, 0x93, 0xa0, 0xd2, 0x80, 0xa9, 0xdd, 0x7a, + 0xd8, 0x25, 0x72, 0x1d, 0x93, 0x58, 0x4b, 0xec, 0xc8, 0x76, 0x32, 0x76, 0xe0, 0xc2, 0x95, 0x0b, + 0x7f, 0xd6, 0x8e, 0x3b, 0x72, 0x42, 0x68, 0xfb, 0x1f, 0x38, 0xa3, 0xd8, 0x4e, 0x7f, 0xb0, 0x4e, + 0xaf, 0xa7, 0xc4, 0xf9, 0x7e, 0x7e, 0x7c, 0x7f, 0x38, 0x36, 0x18, 0x52, 0xa6, 0x88, 0xc0, 0x09, + 0xa2, 0x2c, 0x94, 0x04, 0x17, 0x82, 0xaa, 0x9b, 0x00, 0xe3, 0x32, 0xc0, 0x9c, 0xc9, 0x22, 0x23, + 0x22, 0x28, 0x87, 0x41, 0x4c, 0x18, 0x91, 0x54, 0xfa, 0xb9, 0xe0, 0x8a, 0xc3, 0x8f, 0xb6, 0x50, + 0x7c, 0x8c, 0x4b, 0xbf, 0xa6, 0xf8, 0xe5, 0xb0, 0xfb, 0xf1, 0x53, 0xba, 0xe5, 0xb0, 0x7a, 0x18, + 0xa9, 0xee, 0x68, 0x17, 0xf7, 0xa5, 0xac, 0xe1, 0xf4, 0x14, 0x61, 0x11, 0x11, 0x19, 0x65, 0x2a, + 0x40, 0x0b, 0x4c, 0x03, 0x75, 0x93, 0x13, 0x9b, 0x5b, 0x37, 0xa0, 0x0b, 0x1c, 0xa4, 0x34, 0x4e, + 0x14, 0x4e, 0x29, 0x61, 0x4a, 0x06, 0x6b, 0xe8, 0x72, 0xb8, 0xb6, 0xb2, 0x84, 0x0f, 0x2b, 0x02, + 0xe6, 0x82, 0x04, 0x38, 0x41, 0x8c, 0x91, 0x54, 0x3b, 0x9a, 0x57, 0x0b, 0xf1, 0x62, 0xce, 0xe3, + 0x94, 0x04, 0x7a, 0xb5, 0x28, 0x7e, 0x09, 0xa2, 0x42, 0x20, 0x45, 0x39, 0xb3, 0xf1, 0x77, 0x62, + 0x1e, 0x73, 0xfd, 0x1a, 0x54, 0x6f, 0xe6, 0xeb, 0xd1, 0xbf, 0x2d, 0xf0, 0xe2, 0x7b, 0xd3, 0xb7, + 0x99, 0x42, 0x8a, 0xc0, 0x09, 0x68, 0xe6, 0x48, 0xa0, 0x4c, 0xba, 0x4e, 0xdf, 0x19, 0xec, 0x8f, + 0x3e, 0xf1, 0x77, 0xe8, 0xa3, 0x7f, 0xa6, 0x29, 0xc7, 0x7b, 0xb7, 0x7f, 0x7f, 0xd0, 0x98, 0x5a, + 0x01, 0xf8, 0x29, 0x80, 0xb9, 0xe0, 0x25, 0x8d, 0x88, 0x08, 0x4d, 0x9d, 0x21, 0x8d, 0xdc, 0x67, + 0x7d, 0x67, 0xd0, 0x9e, 0x1e, 0xd4, 0x91, 0xb1, 0x0e, 0x4c, 0x22, 0xe8, 0x83, 0xc3, 0x15, 0xda, + 0x54, 0x56, 0xc1, 0x9f, 0x6b, 0xf8, 0xdb, 0x4b, 0xb8, 0x89, 0x4c, 0x22, 0xd8, 0x03, 0x6d, 0x46, + 0xae, 0x43, 0x9d, 0x98, 0xbb, 0xd7, 0x77, 0x06, 0xad, 0x69, 0x8b, 0x91, 0xeb, 0x71, 0xb5, 0x86, + 0x21, 0x78, 0xf7, 0xff, 0xd6, 0xb2, 0x2a, 0xcf, 0x7d, 0xa3, 0x2e, 0x6a, 0x81, 0xfd, 0xf5, 0x01, + 0xf8, 0x6b, 0x2d, 0x2f, 0x87, 0xbe, 0xc9, 0x4a, 0x77, 0x64, 0x7a, 0xb8, 0x99, 0xaa, 0x69, 0x53, + 0x02, 0xdc, 0x95, 0x01, 0x67, 0x92, 0x30, 0x59, 0x48, 0xeb, 0xd1, 0xd4, 0x1e, 0xfe, 0x6b, 0x3d, + 0x6a, 0x9a, 0xb1, 0xe9, 0x2c, 0x6d, 0x36, 0xbe, 0xc3, 0x18, 0x1c, 0x64, 0x48, 0x15, 0x82, 0xb2, + 0x38, 0xcc, 0x11, 0xbe, 0x22, 0x4a, 0xba, 0x6f, 0xf6, 0x9f, 0x0f, 0xf6, 0x47, 0x5f, 0xec, 0x34, + 0x9a, 0x1f, 0x2d, 0x79, 0x3e, 0x1b, 0x9f, 0x69, 0xba, 0x9d, 0xd2, 0xab, 0x5a, 0xd5, 0x7c, 0x95, + 0xf0, 0x27, 0xf0, 0x8a, 0x32, 0xaa, 0x28, 0x4a, 0xc3, 0x12, 0xa5, 0xa1, 0x24, 0xca, 0x6d, 0x69, + 0x9f, 0xfe, 0x7a, 0xe2, 0xd5, 0x5e, 0xf6, 0xe7, 0x28, 0xa5, 0x11, 0x52, 0x5c, 0x5c, 0xe4, 0x11, + 0x52, 0xc4, 0x2a, 0xbe, 0xb4, 0xf4, 0x39, 0x4a, 0x67, 0x44, 0xc1, 0xdf, 0x40, 0x37, 0x21, 0x55, + 0xf9, 0xa1, 0xe2, 0x95, 0xa2, 0x24, 0x2a, 0x2c, 0x34, 0xbe, 0x9a, 0x6b, 0x5b, 0x4b, 0x7f, 0xbd, + 0x53, 0x09, 0x3f, 0x68, 0x99, 0x73, 0x3e, 0xd7, 0x22, 0xc6, 0x73, 0x72, 0x62, 0x5d, 0x3b, 0xc9, + 0xb6, 0x68, 0x04, 0x7f, 0x77, 0xc0, 0xfb, 0xbc, 0x50, 0x52, 0x21, 0x16, 0x55, 0xbd, 0x8b, 0xf8, + 0x35, 0x53, 0x34, 0x23, 0xa1, 0x4c, 0x91, 0x4c, 0x28, 0x8b, 0x5d, 0xa0, 0x53, 0xf8, 0x72, 0xa7, + 0x14, 0x7e, 0x5e, 0x29, 0x9d, 0x58, 0x21, 0xeb, 0xdf, 0xe3, 0x8f, 0x43, 0x33, 0x6b, 0x01, 0x05, + 0x70, 0x73, 0x62, 0xfc, 0x6b, 0xb5, 0xe5, 0x10, 0xf7, 0xf5, 0x36, 0x19, 0x3d, 0x69, 0x6f, 0xb7, + 0x48, 0xc5, 0x31, 0x23, 0x3a, 0x41, 0x0a, 0x9d, 0x52, 0x59, 0x0f, 0xb0, 0x63, 0x95, 0x37, 0x41, + 0x12, 0xfe, 0xe1, 0x00, 0x2f, 0x45, 0x52, 0x85, 0x4a, 0x20, 0x26, 0x33, 0x2a, 0x25, 0xe5, 0x2c, + 0x5c, 0xa4, 0x1c, 0x5f, 0x85, 0xa6, 0x57, 0xee, 0x0b, 0x6d, 0xfd, 0xed, 0x4e, 0x95, 0x9f, 0x22, + 0xa9, 0xce, 0xd7, 0x94, 0x8e, 0x2b, 0x21, 0x33, 0x91, 0xba, 0x03, 0xe9, 0xd3, 0x10, 0xd8, 0x01, + 0xcd, 0x5c, 0x90, 0xf1, 0x78, 0xee, 0xbe, 0xd4, 0xff, 0xa8, 0x5d, 0x1d, 0x5d, 0x82, 0xce, 0xf6, + 0xb1, 0x56, 0x0c, 0x9b, 0x66, 0x75, 0x02, 0xed, 0x4d, 0xed, 0x0a, 0x0e, 0xc0, 0xc1, 0xa3, 0x5d, + 0xf4, 0x4c, 0x23, 0xde, 0x2a, 0x37, 0x46, 0x7f, 0x74, 0x01, 0x0e, 0xb7, 0xcc, 0x0b, 0x7e, 0x03, + 0x7a, 0x65, 0xbd, 0x71, 0xd7, 0x7e, 0x5a, 0x14, 0x45, 0x82, 0x48, 0x73, 0xde, 0xb5, 0xa7, 0xef, + 0x2d, 0x21, 0xcb, 0xff, 0xf0, 0x3b, 0x03, 0x38, 0x3e, 0xbf, 0xbd, 0xf7, 0x9c, 0xbb, 0x7b, 0xcf, + 0xf9, 0xe7, 0xde, 0x73, 0xfe, 0x7c, 0xf0, 0x1a, 0x77, 0x0f, 0x5e, 0xe3, 0xaf, 0x07, 0xaf, 0x71, + 0xf9, 0x55, 0x4c, 0x55, 0x52, 0x2c, 0x7c, 0xcc, 0xb3, 0x00, 0x73, 0x99, 0x71, 0x19, 0xac, 0x5a, + 0xfb, 0xd9, 0xf2, 0xca, 0xf8, 0x75, 0xf3, 0xd2, 0xd0, 0x37, 0xc2, 0xa2, 0xa9, 0x0f, 0xe2, 0xcf, + 0xff, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xab, 0x08, 0x12, 0x9c, 0xe3, 0x06, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -352,6 +360,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.PreCCV { + i-- + if m.PreCCV { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x68 + } { size, err := m.LastTransmissionBlockHeight.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -618,6 +636,9 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) l = m.LastTransmissionBlockHeight.Size() n += 1 + l + sovGenesis(uint64(l)) + if m.PreCCV { + n += 2 + } return n } @@ -1075,6 +1096,26 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 13: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PreCCV", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.PreCCV = bool(v != 0) default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/ccv/consumer/types/genesis_test.go b/x/ccv/consumer/types/genesis_test.go index a0046a5387..ebac47eafc 100644 --- a/x/ccv/consumer/types/genesis_test.go +++ b/x/ccv/consumer/types/genesis_test.go @@ -100,6 +100,7 @@ func TestValidateInitialGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{}, + false, }, true, }, @@ -118,6 +119,7 @@ func TestValidateInitialGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{}, + false, }, true, }, @@ -136,6 +138,7 @@ func TestValidateInitialGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{}, + false, }, true, }, @@ -154,6 +157,7 @@ func TestValidateInitialGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{Height: 1}, + false, }, true, }, @@ -172,6 +176,7 @@ func TestValidateInitialGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{List: []ccv.ConsumerPacketData{{}}}, types.LastTransmissionBlockHeight{}, + false, }, true, }, @@ -336,6 +341,7 @@ func TestValidateRestartGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{}, + false, }, true, }, @@ -354,6 +360,7 @@ func TestValidateRestartGenesisState(t *testing.T) { nil, ccv.ConsumerPacketDataList{}, types.LastTransmissionBlockHeight{}, + false, }, true, }, diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index 1e2d6ae0a8..f54fbd8d1f 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -68,8 +68,14 @@ const ( // because the client is expired PendingDataPacketsBytePrefix - // CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address + // CrossChainValidatorPrefix is the byte that will store cross-chain validators by consensus address CrossChainValidatorBytePrefix + + // PreCCVByteKey is the byte to store the consumer is running on democracy staking module without consumer + PreCCVByteKey + + // LastSovereignHeightByteKey is the byte that will store last sovereign height + LastSovereignHeightByteKey ) // PortKey returns the key to the port ID in the store @@ -102,6 +108,14 @@ func PendingChangesKey() []byte { return []byte{PendingChangesByteKey} } +func PreCCVKey() []byte { + return []byte{PreCCVByteKey} +} + +func LastSovereignHeightKey() []byte { + return []byte{LastSovereignHeightByteKey} +} + // PacketMaturityTimeKey returns the key for storing the maturity time for a given received VSC packet id func PacketMaturityTimeKey(vscID uint64, maturityTime time.Time) []byte { ts := uint64(maturityTime.UTC().UnixNano()) @@ -115,6 +129,12 @@ func PacketMaturityTimeKey(vscID uint64, maturityTime time.Time) []byte { ) } +// IdFromPacketMaturityTimeKey returns the packet id corresponding to a maturity time full key (including prefix) +func IdFromPacketMaturityTimeKey(key []byte) uint64 { + // Bytes after single byte prefix are converted to uin64 + return binary.BigEndian.Uint64(key[1:]) +} + // HeightValsetUpdateIDKey returns the key to a valset update ID for a given block height func HeightValsetUpdateIDKey(height uint64) []byte { hBytes := make([]byte, 8) diff --git a/x/ccv/democracy/staking/expected_keepers.go b/x/ccv/democracy/staking/expected_keepers.go new file mode 100644 index 0000000000..66cb093d37 --- /dev/null +++ b/x/ccv/democracy/staking/expected_keepers.go @@ -0,0 +1,12 @@ +package staking + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" +) + +// ConsumerKeeper defines the contract needed to be fulfilled for staking module. +type ConsumerKeeper interface { + GetParams(ctx sdk.Context) consumertypes.Params + IsPreCCV(ctx sdk.Context) bool +} diff --git a/x/ccv/democracy/staking/module.go b/x/ccv/democracy/staking/module.go index aa27177f0a..9180652acf 100644 --- a/x/ccv/democracy/staking/module.go +++ b/x/ccv/democracy/staking/module.go @@ -29,20 +29,22 @@ type AppModule struct { // embed the Cosmos SDK's x/staking AppModule staking.AppModule - keeper keeper.Keeper - accKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper + accKeeper types.AccountKeeper + bankKeeper types.BankKeeper + consumerKeeper ConsumerKeeper } // NewAppModule creates a new AppModule object using the native x/staking module // AppModule constructor. -func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule { +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, ck ConsumerKeeper) AppModule { stakingAppMod := staking.NewAppModule(cdc, keeper, ak, bk) return AppModule{ - AppModule: stakingAppMod, - keeper: keeper, - accKeeper: ak, - bankKeeper: bk, + AppModule: stakingAppMod, + keeper: keeper, + accKeeper: ak, + bankKeeper: bk, + consumerKeeper: ck, } } @@ -54,7 +56,10 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - _ = staking.InitGenesis(ctx, am.keeper, am.accKeeper, am.bankKeeper, &genesisState) + valUpdates := staking.InitGenesis(ctx, am.keeper, am.accKeeper, am.bankKeeper, &genesisState) + if am.consumerKeeper.IsPreCCV(ctx) { + return valUpdates + } return []abci.ValidatorUpdate{} } @@ -64,6 +69,9 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // consumer chain's x/cvv/consumer module and so this module is not responsible // for returning the initial validator set. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - _ = am.keeper.BlockValidatorUpdates(ctx) + valUpdates := am.keeper.BlockValidatorUpdates(ctx) + if am.consumerKeeper.IsPreCCV(ctx) { + return valUpdates + } return []abci.ValidatorUpdate{} } diff --git a/x/ccv/types/expected_keepers.go b/x/ccv/types/expected_keepers.go index 6ce079f454..cd62bf62f4 100644 --- a/x/ccv/types/expected_keepers.go +++ b/x/ccv/types/expected_keepers.go @@ -18,6 +18,11 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) +// DemocracyStakingKeeper defines the interface expected by consumer module +type DemocracyStakingKeeper interface { + GetLastValidators(ctx sdk.Context) (validators []stakingtypes.Validator) +} + // StakingKeeper defines the contract expected by provider-chain ccv module from a Staking Module that will keep track // of the provider validator set. This version of the interchain-security protocol will mirror the provider chain's changes // so we do not need a registry module between the staking module and CCV. @@ -30,10 +35,17 @@ type StakingKeeper interface { // slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction Jail(sdk.Context, sdk.ConsAddress) // jail a validator Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.InfractionType) + Unjail(ctx sdk.Context, addr sdk.ConsAddress) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) IterateLastValidatorPowers(ctx sdk.Context, cb func(addr sdk.ValAddress, power int64) (stop bool)) PowerReduction(ctx sdk.Context) sdk.Int PutUnbondingOnHold(ctx sdk.Context, id uint64) error + IterateValidators(ctx sdk.Context, f func(index int64, validator stakingtypes.ValidatorI) (stop bool)) + Validator(ctx sdk.Context, addr sdk.ValAddress) stakingtypes.ValidatorI + IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool + ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) stakingtypes.ValidatorI + Delegation(ctx sdk.Context, addr sdk.AccAddress, valAddr sdk.ValAddress) stakingtypes.DelegationI + MaxValidators(ctx sdk.Context) uint32 GetLastTotalPower(ctx sdk.Context) sdk.Int }