Skip to content

Commit

Permalink
upgrade: cosmos to 0.47, evmos to v19 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyunpark authored Aug 16, 2024
1 parent 426c647 commit a84b183
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 38 deletions.
32 changes: 24 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (

memiavlstore "github.com/crypto-org-chain/cronos/store"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/settlus/chain/app/ante"
"github.com/settlus/chain/app/post"
"github.com/settlus/chain/app/upgrades/v1"
Expand All @@ -77,9 +78,10 @@ func init() {
}

DefaultNodeHome = filepath.Join(userHomeDir, "."+Name)

// manually update the power reduction by replacing micro (u) -> atto (a) evmos
sdk.DefaultPowerReduction = evmostypes.PowerReduction
// Set power reduction
sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000)
// Constant reward is true to follow Settlus reward distribution rules
sdk.ConstantReward = true
// modify fee market parameter defaults through global
feemarkettypes.DefaultMinGasPrice = evmosapp.MainnetMinGasPrices
feemarkettypes.DefaultMinGasMultiplier = evmosapp.MainnetMinGasMultiplier
Expand All @@ -91,10 +93,8 @@ const (
Name = "settlus"
)

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
)
// DefaultNodeHome default home directories for the application daemon
var DefaultNodeHome string

var (
_ runtime.AppI = (*SettlusApp)(nil)
Expand Down Expand Up @@ -262,6 +262,7 @@ func NewSettlus(
app.setPostHandler()
app.SetEndBlocker(app.EndBlocker)
app.setupUpgradeHandlers()
app.setUpgradeStoreLoaders()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -485,11 +486,26 @@ func (app *SettlusApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
v1.UpgradeName,
v1.CreateUpgradeHandler(
app.mm, app.configurator,
app.mm, app.configurator, app.AccountKeeper, 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/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func NewAppKeeper(
// NOTE: app.Erc20Keeper is already initialized elsewhere

// Override the ICS20 app module
//transferModule := transfer.NewAppModule(appKeepers.TransferKeeper)
// transferModule := transfer.NewAppModule(appKeepers.TransferKeeper)

/*
Create Transfer Stack
Expand Down
1 change: 0 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func GenesisStateWithValSet(app *SettlusApp, genesisState simapp.GenesisState,
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
Probono: false,
ProbonoRate: sdk.ZeroDec(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
Expand Down
13 changes: 13 additions & 0 deletions app/upgrades/v1/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
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,
},
}
100 changes: 98 additions & 2 deletions app/upgrades/v1/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,114 @@
package v1

import (
"fmt"

"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"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
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,
ak authkeeper.AccountKeeper,
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
}

if err := MigrateFeeCollector(ak, ctx); err != nil {
return nil, err
}

logger.Debug("running module migrations ...")
return mm.RunMigrations(ctx, configurator, vm)
}
}

func MigrateFeeCollector(ak authkeeper.AccountKeeper, ctx sdk.Context) error {
feeCollectorModuleAccount := ak.GetModuleAccount(ctx, authtypes.FeeCollectorName)
if feeCollectorModuleAccount == nil {
return fmt.Errorf("fee collector module account not found")
}

modAcc, ok := feeCollectorModuleAccount.(*authtypes.ModuleAccount)
if !ok {
return fmt.Errorf("fee collector module account is not a module account")
}

// Create a new FeeCollector module account with the same address and balance as the old one.
newFeeCollectorModuleAccount := authtypes.NewModuleAccount(modAcc.BaseAccount, authtypes.FeeCollectorName, authtypes.Burner)

// Override the FeeCollector module account in the auth keeper.
ak.SetModuleAccount(ctx, newFeeCollectorModuleAccount)

return nil
}
11 changes: 9 additions & 2 deletions cmd/settlusd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func initTestnetFiles(
stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
math.OneInt(),
math.ZeroInt(),
sdk.ZeroDec(),
false,
)
if err != nil {
return err
Expand Down Expand Up @@ -428,6 +428,13 @@ func initGenFiles(
appGenState[stakingtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&stakingGenState)

var govGenState govv1.GenesisState
newPeriod := time.Minute * 2
clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)

govGenState.Params.MaxDepositPeriod = &newPeriod
govGenState.Params.VotingPeriod = &newPeriod
govGenState.Params.MinDeposit[0].Amount = sdk.NewInt(1000)
govGenState.Params.MinDeposit[0].Denom = coinDenom
clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)

appGenState[govtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&govGenState)
Expand All @@ -436,7 +443,7 @@ func initGenFiles(
clientCtx.Codec.MustUnmarshalJSON(appGenState[minttypes.ModuleName], &mintGenState)

mintGenState.Params.MintDenom = coinDenom
mintGenState.Params.BlockReward = sdk.NewInt(5000000000000000000)
mintGenState.Params.BlockReward = sdk.NewInt(3000000000000000000)
appGenState[minttypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&mintGenState)

var crisisGenState crisistypes.GenesisState
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/settlus/chain

go 1.22.2

toolchain go1.22.5

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.1
Expand Down Expand Up @@ -253,11 +251,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.2
// 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.3.rc
// 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.2 h1:ho5ED+o0UI3ITiEckNdlqxgIxE++tYU2CgwfBanbttA=
github.com/settlus/cosmos-sdk v0.47.12-settlus.2/go.mod h1:ADjORYzUQqQv/FxDi0H0K5gW/rAk1CiDR3ZKsExfJV0=
github.com/settlus/evmos/v19 v19.0.0-settlus.3.rc h1:z9ctKKoVsTw18fhFLW+OTUqwA76gMK63f/1ECU8T0dY=
github.com/settlus/evmos/v19 v19.0.0-settlus.3.rc/go.mod h1:cH2IV7ZrZlp+2KfeExMvtlQe8sxOYt2cC4J3ZiiwJHU=
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 testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
stakingtypes.NewCommissionRates(commission, sdk.ZeroDec(), sdk.ZeroDec()),
math.OneInt(),
math.ZeroInt(),
sdk.ZeroDec(),
false,
)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion types/hex_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewHexAddrFromBytes(addr []byte) HexAddressString {
return HexAddressString(common.BytesToAddress(addr).Hex())
}

func NoramlizeHexAddress(addr string) HexAddressString {
func NormalizeHexAddress(addr string) HexAddressString {
return HexAddressString(common.HexToAddress(addr).Hex())
}

Expand Down
4 changes: 2 additions & 2 deletions types/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func ParseNftId(nftId string) (Nft, error) {

return Nft{
ChainId: data[0],
ContractAddr: NoramlizeHexAddress(data[1]),
TokenId: NoramlizeHexAddress(data[2]),
ContractAddr: NormalizeHexAddress(data[1]),
TokenId: NormalizeHexAddress(data[2]),
}, nil
}

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.IsProbono() {
probonoReward = probonoReward.Add(rewardCoins...)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (suite *OracleTestSuite) NewValidator(amt sdkmath.Int) *stakingtypes.MsgCre
stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
sdkmath.OneInt(),
sdkmath.ZeroInt(),
sdk.ZeroDec(),
false,
)
suite.Require().NoError(err)
return msgCreate
Expand Down Expand Up @@ -499,7 +499,7 @@ func (suite *OracleTestSuite) TestKeeper_RewardBallotWinners_WithProbono() {
s.NoError(err)

for _, validator := range s.validators {
if validator.Probono {
if validator.IsProbono() {
probonoRewards = probonoRewards.Add(tt.rewardMap[validator.GetOperator().String()].AmountOf("asetl"))
validator.Probono = false
continue
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/vote_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func StringToOwnershipData(voteString string) (ctypes.Nft, ctypes.HexAddressStri
return ctypes.Nft{}, "", fmt.Errorf("invalid nftId: %s", data[0])
}

owner := ctypes.NoramlizeHexAddress(data[1])
owner := ctypes.NormalizeHexAddress(data[1])

return nft, owner, err
}
Expand Down
12 changes: 6 additions & 6 deletions x/oracle/types/vote_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func TestStringToOwnershipData(t *testing.T) {
expected: Result{
nft: ctypes.Nft{
ChainId: "1",
ContractAddr: ctypes.NoramlizeHexAddress("0x123"),
TokenId: ctypes.NoramlizeHexAddress("0x0"),
ContractAddr: ctypes.NormalizeHexAddress("0x123"),
TokenId: ctypes.NormalizeHexAddress("0x0"),
},
owner: ctypes.NoramlizeHexAddress("0x777"),
owner: ctypes.NormalizeHexAddress("0x777"),
err: false,
},
},
Expand All @@ -43,10 +43,10 @@ func TestStringToOwnershipData(t *testing.T) {
expected: Result{
nft: ctypes.Nft{
ChainId: "1",
ContractAddr: ctypes.NoramlizeHexAddress("0x123"),
TokenId: ctypes.NoramlizeHexAddress("0xa"),
ContractAddr: ctypes.NormalizeHexAddress("0x123"),
TokenId: ctypes.NormalizeHexAddress("0xa"),
},
owner: ctypes.NoramlizeHexAddress("777"),
owner: ctypes.NormalizeHexAddress("777"),
err: false,
},
},
Expand Down
4 changes: 2 additions & 2 deletions x/settlement/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (k msgServer) Record(goCtx context.Context, msg *types.MsgRecord) (*types.M
}

payoutBlock := uint64(ctx.BlockHeight())
contractAddr := ctypes.NoramlizeHexAddress(msg.ContractAddress)
tokenId := ctypes.NoramlizeHexAddress(msg.TokenIdHex)
contractAddr := ctypes.NormalizeHexAddress(msg.ContractAddress)
tokenId := ctypes.NormalizeHexAddress(msg.TokenIdHex)
utxrId, err := k.CreateUTXR(
ctx,
msg.TenantId,
Expand Down

0 comments on commit a84b183

Please sign in to comment.