Skip to content

Commit

Permalink
bump cosmos-sdk and evmos, add upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyunpark committed Aug 7, 2024
1 parent ac331b3 commit c6c921c
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 15 deletions.
21 changes: 19 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/v1/constants.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
)
72 changes: 70 additions & 2 deletions app/upgrades/v1/upgrades.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 8 additions & 0 deletions draft_metadata.json
Original file line number Diff line number Diff line change
@@ -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"
}
17 changes: 17 additions & 0 deletions draft_proposal.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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())
Expand Down

0 comments on commit c6c921c

Please sign in to comment.