diff --git a/app/app.go b/app/app.go index 3286a58f..159315f2 100644 --- a/app/app.go +++ b/app/app.go @@ -65,6 +65,7 @@ import ( "github.com/settlus/chain/app/ante" "github.com/settlus/chain/app/post" "github.com/settlus/chain/app/upgrades/v1" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/settlus/chain/swagger" // this line is used by starport scaffolding # stargate/app/moduleImport @@ -262,7 +263,8 @@ func NewSettlus( app.setPostHandler() app.SetEndBlocker(app.EndBlocker) app.setupUpgradeHandlers() - + app.setUpgradeStoreLoaders() + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(fmt.Sprintf("failed to load latest version: %s", err)) @@ -485,11 +487,26 @@ func (app *SettlusApp) setupUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( v1.UpgradeName, v1.CreateUpgradeHandler( - app.mm, app.configurator, + app.mm, app.configurator, app.ConsensusParamsKeeper, app.IBCKeeper.ClientKeeper, app.ParamsKeeper, app.appCodec, ), ) } +func (app *SettlusApp) setUpgradeStoreLoaders() { + upgradeInfo, err := app.AppKeepers.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) + } + if app.AppKeepers.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + return + } + + if upgradeInfo.Name == v1.UpgradeName { + storeUpgrades := v1.StoreUpgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/app/test_helpers.go b/app/test_helpers.go index 37595050..43e35b12 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -158,7 +158,7 @@ func GenesisStateWithValSet(app *SettlusApp, genesisState simapp.GenesisState, UnbondingTime: time.Unix(0, 0).UTC(), Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), MinSelfDelegation: sdk.ZeroInt(), - Probono: false, + // Probono: false, ProbonoRate: sdk.ZeroDec(), } validators = append(validators, validator) diff --git a/app/upgrades/v1/constants.go b/app/upgrades/v1/constants.go index 17bf8bf3..5311e98e 100644 --- a/app/upgrades/v1/constants.go +++ b/app/upgrades/v1/constants.go @@ -1,6 +1,21 @@ package v1 +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" +) + const ( // UpgradeName is the shared upgrade plan name for mainnet UpgradeName = "v2.0.0" ) + +var ( + StoreUpgrades = store.StoreUpgrades{ + Added: []string{ + consensustypes.ModuleName, + crisistypes.ModuleName, + }, + } +) \ No newline at end of file diff --git a/app/upgrades/v1/upgrades.go b/app/upgrades/v1/upgrades.go index bb7468a8..630557fc 100644 --- a/app/upgrades/v1/upgrades.go +++ b/app/upgrades/v1/upgrades.go @@ -1,18 +1,86 @@ package v1 import ( + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" + evmtypes "github.com/evmos/evmos/v19/x/evm/types" + feemarkettypes "github.com/evmos/evmos/v19/x/feemarket/types" ) -// CreateUpgradeHandler creates an SDK upgrade handler for v2 func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + ck consensuskeeper.Keeper, + clientKeeper ibctmmigrations.ClientKeeper, + pk paramskeeper.Keeper, + cdc codec.BinaryCodec, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // Leave modules as-is to avoid running InitGenesis. + logger := ctx.Logger().With("upgrade", UpgradeName) + + // Set param key table for params module migration + for _, subspace := range pk.GetSubspaces() { + var keyTable paramstypes.KeyTable + switch subspace.Name() { + case authtypes.ModuleName: + keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + case banktypes.ModuleName: + keyTable = banktypes.ParamKeyTable() //nolint:staticcheck,nolintlint + case stakingtypes.ModuleName: + keyTable = stakingtypes.ParamKeyTable() + case minttypes.ModuleName: + keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck,nolintlint + case slashingtypes.ModuleName: + keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + case govtypes.ModuleName: + keyTable = govv1.ParamKeyTable() //nolint:staticcheck + case crisistypes.ModuleName: + keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + case ibctransfertypes.ModuleName: + keyTable = ibctransfertypes.ParamKeyTable() + case evmtypes.ModuleName: + keyTable = evmtypes.ParamKeyTable() //nolint:staticcheck + case feemarkettypes.ModuleName: + keyTable = feemarkettypes.ParamKeyTable() + default: + continue + } + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + + baseAppLegacySS := pk.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + + baseapp.MigrateParams(ctx, baseAppLegacySS, &ck) + + // Include this when migrating to ibc-go v7 (optional) + // source: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md + // prune expired tendermint consensus states to save storage space + if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper); err != nil { + return nil, err + } + + logger.Debug("running module migrations ...") return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/draft_metadata.json b/draft_metadata.json new file mode 100644 index 00000000..e297ccf3 --- /dev/null +++ b/draft_metadata.json @@ -0,0 +1,8 @@ +{ + "title": "v2.0.0", + "authors": "adf", + "summary": "upgrade to v2.0.0", + "details": "da", + "proposal_forum_url": "https:dsafc", + "vote_option_context": "null" +} \ No newline at end of file diff --git a/draft_proposal.json b/draft_proposal.json new file mode 100644 index 00000000..eed668e3 --- /dev/null +++ b/draft_proposal.json @@ -0,0 +1,17 @@ +{ + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "settlus10d07y265gmmuvt4z0w9aw880jnsr700jdl3s23", + "plan": { + "name": "v2.0.0", + "time": "0001-01-01T00:00:00Z", + "height": "100", + "info": "", + "upgraded_client_state": null + } + } + ], + "metadata": "ipfs://CID", + "deposit": "1000asetl" +} diff --git a/go.mod b/go.mod index 7d7c0020..8b80f509 100644 --- a/go.mod +++ b/go.mod @@ -253,11 +253,11 @@ replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // use Settlus flavored Cosmos-SDK https://github.com/settlus/cosmos-sdk/releases - github.com/cosmos/cosmos-sdk => github.com/settlus/cosmos-sdk v0.47.12-settlus-alpha + github.com/cosmos/cosmos-sdk => github.com/settlus/cosmos-sdk v0.47.12-settlus.1 // use Evmos geth fork github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc4 // use Settlus flavored Evmos - github.com/evmos/evmos/v19 => github.com/settlus/evmos/v19 v19.0.0-settlus.1 + github.com/evmos/evmos/v19 => github.com/settlus/evmos/v19 v19.0.0-settlus.2 // Security Advisory https://github.com/advisories/GHSA-h395-qcrw-5vmq github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 // use cosmos flavored protobufs diff --git a/go.sum b/go.sum index 02157d29..f2a379d5 100644 --- a/go.sum +++ b/go.sum @@ -1213,10 +1213,10 @@ github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KR github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/settlus/cosmos-sdk v0.47.12-settlus-alpha h1:8XEuwxKhRIA1mZvL3y71wz0jSnqazZTWCNZv06Ja+f4= -github.com/settlus/cosmos-sdk v0.47.12-settlus-alpha/go.mod h1:ADjORYzUQqQv/FxDi0H0K5gW/rAk1CiDR3ZKsExfJV0= -github.com/settlus/evmos/v19 v19.0.0-settlus.1 h1:/Mflt1By3l92QiJiSXg4exUzmAjji1YVRZSQXtQ4i4I= -github.com/settlus/evmos/v19 v19.0.0-settlus.1/go.mod h1:BjlwXOxPrB+9o3zdxseaPV7gylV1XHoJrJYQIYshQ6E= +github.com/settlus/cosmos-sdk v0.47.12-settlus.1 h1:e1/VfWFPPpRCcFnJP2wrD7fCzGPkLAu5tX805eRdKYw= +github.com/settlus/cosmos-sdk v0.47.12-settlus.1/go.mod h1:ADjORYzUQqQv/FxDi0H0K5gW/rAk1CiDR3ZKsExfJV0= +github.com/settlus/evmos/v19 v19.0.0-settlus.2 h1:ZBfhDOoAKUTyaWcDwt5bD37XLmGNugaIXuzCxkaeP1k= +github.com/settlus/evmos/v19 v19.0.0-settlus.2/go.mod h1:+x+Q/kYytddmg6XpUGW5NPaHhMhURrvL6gmTBdkcjns= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= diff --git a/x/oracle/keeper/feeder.go b/x/oracle/keeper/feeder.go index 87ea5041..b954d82c 100644 --- a/x/oracle/keeper/feeder.go +++ b/x/oracle/keeper/feeder.go @@ -313,7 +313,7 @@ func (k Keeper) RewardBallotWinners(ctx sdk.Context, validatorClaimMap map[strin } if !rewardCoins.IsZero() { - if receiverVal.Probono { + if receiverVal.ProbonoRate.GT(sdk.ZeroDec()) { probonoReward = probonoReward.Add(rewardCoins...) continue } diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 685fc949..124ed5f9 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -523,7 +523,7 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners_WithProbono() { s.Equal(s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx).AmountOf("asetl"), sdk.ZeroDec()) for _, idx := range tt.probonoIndex { - s.validators[idx].Probono = true + s.validators[idx].ProbonoRate = sdk.OneDec() s.validators[idx] = stakingkeeper.TestingUpdateValidator(s.app.StakingKeeper, s.ctx, s.validators[idx], true) } @@ -533,9 +533,9 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners_WithProbono() { s.NoError(err) for _, validator := range s.validators { - if validator.Probono { + if validator.ProbonoRate.Equal(sdk.OneDec()) { probonoRewards = probonoRewards.Add(tt.rewardMap[validator.GetOperator().String()].AmountOf("asetl")) - validator.Probono = false + validator.ProbonoRate = sdk.ZeroDec() continue } rewards := s.app.DistrKeeper.GetValidatorCurrentRewards(s.ctx, validator.GetOperator())