Skip to content

Commit 246ba80

Browse files
yihuangcalvinaco
andauthored
Problem: Cronos New Golden Age not released (#1125)
* Project tic-tac fix typo * update v4 in test * changelog * python format * fix upgrade * fix upgrade test * fix upgrade test * fix upgrade test * fix upgrade * fix upgrade test --------- Co-authored-by: Calvin Lau <calvin@crypto.com>
1 parent 18d675a commit 246ba80

File tree

8 files changed

+154
-102
lines changed

8 files changed

+154
-102
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
*Mar 3, 2025*
4+
5+
## v5.0.0
6+
7+
### State Machine Breaking
8+
9+
- [#1125](https://github.com/crypto-org-chain/chain-main/pull/1125) Cronos New Golden Age.
10+
311
*Feb 28, 2025*
412

513
## v4.2.13

app/upgrades.go

Lines changed: 86 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,123 +3,109 @@ package app
33
import (
44
"fmt"
55

6-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
76
sdk "github.com/cosmos/cosmos-sdk/types"
87
"github.com/cosmos/cosmos-sdk/types/module"
9-
"github.com/cosmos/cosmos-sdk/x/group"
10-
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
8+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
9+
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
10+
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
1111
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
12-
ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts"
13-
icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
14-
icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
15-
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
16-
ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
17-
icaauthmoduletypes "github.com/crypto-org-chain/chain-main/v4/x/icaauth/types"
18-
nfttransfertypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types"
12+
13+
"github.com/crypto-org-chain/chain-main/v4/config"
1914
)
2015

21-
func (app *ChainApp) RegisterUpgradeHandlers() {
22-
planName := "v4.2.0"
23-
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
24-
// the minimal commission rate of 5% (0.05)
25-
// (default is needed to be set because of SDK store migrations that set the param)
26-
stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2)
16+
type VestingAccountSpec struct {
17+
Account string
18+
Periods int
19+
PeriodDuration int64
20+
}
2721

28-
app.StakingKeeper.IterateValidators(ctx, func(index int64, val stakingtypes.ValidatorI) (stop bool) {
29-
if val.GetCommission().LT(stakingtypes.DefaultMinCommissionRate) {
30-
validator, found := app.StakingKeeper.GetValidator(ctx, val.GetOperator())
31-
if !found {
32-
ctx.Logger().Error("validator not found", val)
33-
return true
34-
}
35-
ctx.Logger().Info("update validator's commission rate to a minimal one", val)
36-
validator.Commission.Rate = stakingtypes.DefaultMinCommissionRate
37-
if validator.Commission.MaxRate.LT(stakingtypes.DefaultMinCommissionRate) {
38-
validator.Commission.MaxRate = stakingtypes.DefaultMinCommissionRate
39-
}
40-
app.StakingKeeper.SetValidator(ctx, validator)
41-
}
42-
return false
43-
})
22+
var (
23+
MintAmount = sdk.NewInt(7000000000000000000)
24+
VestingSpec = map[string]VestingAccountSpec{
25+
"chaintest": {
26+
Account: "cro1jgt29q28ehyc6p0fd5wqhwswfxv59lhppz3v65",
27+
Periods: 60,
28+
PeriodDuration: 60,
29+
},
30+
"testnet-croeseid-4": {
31+
Account: "tcro1t7y7hzl3spx8pdqfzsmw5u5n3y2fwg2nh9rngm",
32+
Periods: 60,
33+
PeriodDuration: 600,
34+
},
35+
"crypto-org-chain-mainnet-dryrun-1": {
36+
Account: "cro1jgt29q28ehyc6p0fd5wqhwswfxv59lhppz3v65",
37+
Periods: 60,
38+
PeriodDuration: 600,
39+
},
40+
"crypto-org-chain-mainnet-1": {
41+
Account: "cro198pra975lcj526974r80fflr6retphnl3l7f4h",
42+
Periods: 60,
43+
PeriodDuration: 2628000, // 1 month
44+
},
45+
}
46+
)
4447

45-
icaModule := app.mm.Modules[icatypes.ModuleName].(ica.AppModule)
48+
func (app *ChainApp) RegisterUpgradeHandlers() {
49+
planName := "v5.0.0"
50+
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
51+
vestingSpec, ok := VestingSpec[ctx.ChainID()]
52+
if !ok {
53+
return nil, fmt.Errorf("vesting spec not found for chainID %s", ctx.ChainID())
54+
}
4655

47-
// set the ICS27 consensus version so InitGenesis is not run
48-
fromVM[icatypes.ModuleName] = icaModule.ConsensusVersion()
56+
params := app.MintKeeper.GetParams(ctx)
57+
params.InflationMax = sdk.NewDecWithPrec(1, 2) // 1%
58+
params.InflationMin = sdk.NewDecWithPrec(85, 4) // 0.85%
59+
app.MintKeeper.SetParams(ctx, params)
4960

50-
// create ICS27 Controller submodule params
51-
controllerParams := icacontrollertypes.Params{
52-
ControllerEnabled: false,
61+
// Mint 70B CRO
62+
totalAmount := sdk.NewCoins(sdk.NewCoin(config.BaseCoinUnit, MintAmount))
63+
if err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, totalAmount); err != nil {
64+
return nil, fmt.Errorf("failed to mint coins: %w", err)
5365
}
5466

55-
// create ICS27 Host submodule params
56-
hostParams := icahosttypes.Params{
57-
HostEnabled: false,
58-
AllowMessages: []string{
59-
"/cosmos.authz.v1beta1.MsgExec",
60-
"/cosmos.authz.v1beta1.MsgGrant",
61-
"/cosmos.authz.v1beta1.MsgRevoke",
62-
"/cosmos.bank.v1beta1.MsgSend",
63-
"/cosmos.bank.v1beta1.MsgMultiSend",
64-
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
65-
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
66-
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
67-
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
68-
"/cosmos.gov.v1beta1.MsgVoteWeighted",
69-
"/cosmos.gov.v1beta1.MsgSubmitProposal",
70-
"/cosmos.gov.v1beta1.MsgDeposit",
71-
"/cosmos.gov.v1beta1.MsgVote",
72-
"/cosmos.staking.v1beta1.MsgCreateValidator",
73-
"/cosmos.staking.v1beta1.MsgEditValidator",
74-
"/cosmos.staking.v1beta1.MsgDelegate",
75-
"/cosmos.staking.v1beta1.MsgUndelegate",
76-
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
77-
"/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation",
78-
"/cosmos.slashing.v1beta1.MsgUnjail",
79-
"/ibc.applications.transfer.v1.MsgTransfer",
80-
"/chainmain.nft_transfer.v1.MsgTransfer",
81-
"/chainmain.nft.v1.MsgBurnNFT",
82-
"/chainmain.nft.v1.MsgEditNFT",
83-
"/chainmain.nft.v1.MsgIssueDenom",
84-
"/chainmain.nft.v1.MsgMintNFT",
85-
"/chainmain.nft.v1.MsgTransferNFT",
86-
},
67+
vestingAddr, err := sdk.AccAddressFromBech32(vestingSpec.Account)
68+
if err != nil {
69+
return nil, fmt.Errorf("failed to parse vesting address: %w", err)
8770
}
8871

89-
ctx.Logger().Info("start to init interchain account module...")
72+
// Create vesting periods (60 periods)
73+
startTime := ctx.BlockTime()
9074

91-
// initialize ICS27 module
92-
icaModule.InitModule(ctx, controllerParams, hostParams)
75+
amountPerPeriod := MintAmount.QuoRaw(int64(vestingSpec.Periods))
76+
// the last period keep the remainder
77+
amountLastPeriod := MintAmount.Sub(amountPerPeriod.MulRaw(int64(vestingSpec.Periods - 1)))
9378

94-
ctx.Logger().Info("start to run module migrations...")
79+
periods := make([]vesting.Period, vestingSpec.Periods)
80+
for i := 0; i < vestingSpec.Periods-1; i++ {
81+
periods[i] = vesting.Period{
82+
Length: vestingSpec.PeriodDuration,
83+
Amount: sdk.NewCoins(sdk.NewCoin(config.BaseCoinUnit, amountPerPeriod)),
84+
}
85+
}
86+
periods[vestingSpec.Periods-1] = vesting.Period{
87+
Length: vestingSpec.PeriodDuration,
88+
Amount: sdk.NewCoins(sdk.NewCoin(config.BaseCoinUnit, amountLastPeriod)),
89+
}
9590

96-
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
97-
})
91+
baseAcc := authtypes.NewBaseAccount(vestingAddr, nil, 0, 0)
92+
vestingAcc := vesting.NewPeriodicVestingAccount(
93+
baseAcc,
94+
totalAmount,
95+
startTime.Unix(),
96+
periods,
97+
)
98+
app.AccountKeeper.SetAccount(ctx, vestingAcc)
99+
100+
if err := app.BankKeeper.SendCoinsFromModuleToAccount(
101+
ctx,
102+
minttypes.ModuleName,
103+
vestingAddr,
104+
totalAmount,
105+
); err != nil {
106+
return nil, fmt.Errorf("failed to send coins to vesting account: %w", err)
107+
}
98108

99-
// testnets need to do a coordinated upgrade to keep in sync with current mainnet version
100-
testnetPlanName := "v4.2.7-testnet"
101-
app.UpgradeKeeper.SetUpgradeHandler(testnetPlanName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
102109
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
103110
})
104-
105-
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
106-
if err != nil {
107-
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
108-
}
109-
110-
if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
111-
storeUpgrades := storetypes.StoreUpgrades{
112-
Added: []string{
113-
group.ModuleName,
114-
icacontrollertypes.StoreKey,
115-
icahosttypes.StoreKey,
116-
icaauthmoduletypes.StoreKey,
117-
ibcfeetypes.StoreKey,
118-
nfttransfertypes.StoreKey,
119-
},
120-
}
121-
122-
// configure store loader that checks if version == upgradeHeight and applies store upgrades
123-
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
124-
}
125111
}

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let
3838
in
3939
buildGoApplication rec {
4040
pname = "chain-maind";
41-
version = "4.2.13";
41+
version = "5.0.0";
4242
go = buildPackages.go_1_23;
4343
src = lib.cleanSourceWith {
4444
name = "src";

integration_tests/cosmoscli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def gov_propose_legacy(self, proposer, kind, proposal, no_validate=False, **kwar
2323
description=proposal.get("description"),
2424
upgrade_height=proposal.get("upgrade-height"),
2525
upgrade_time=proposal.get("upgrade-time"),
26-
upgrade_info=proposal.get("upgrade-info"),
26+
upgrade_info=proposal.get("upgrade-info", "info"),
2727
deposit=proposal.get("deposit"),
2828
# basic
2929
home=self.data_dir,

integration_tests/test_upgrade.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def upgrade(cluster, plan_name, target_height, cosmos_sdk_46=True):
198198
"deposit": "0.1cro",
199199
},
200200
cosmos_sdk_46,
201+
no_validate=True,
201202
)
202203

203204
# wait for upgrade plan activated
@@ -420,6 +421,34 @@ def assert_commission(adr, expected):
420421
assert_commission(validator1_operator_address, min_commission_rate)
421422
assert_commission(validator2_operator_address, default_rate)
422423

424+
target_height = cluster.block_height() + 30
425+
upgrade(cluster, "v5.0.0", target_height)
426+
cli = cluster.cosmos_cli()
427+
428+
acct = cli.account("cro1jgt29q28ehyc6p0fd5wqhwswfxv59lhppz3v65")
429+
assert acct["@type"] == "/cosmos.vesting.v1beta1.PeriodicVestingAccount"
430+
print(acct)
431+
vesting_acct = acct["base_vesting_account"]
432+
assert vesting_acct["original_vesting"] == [
433+
{"denom": "basecro", "amount": "7000000000000000000"}
434+
]
435+
assert len(acct["vesting_periods"]) == 60
436+
for period in acct["vesting_periods"][:-1]:
437+
assert period == {
438+
"length": "60",
439+
"amount": [{"denom": "basecro", "amount": "116666666666666666"}],
440+
}
441+
assert acct["vesting_periods"][-1] == {
442+
"length": "60",
443+
"amount": [{"denom": "basecro", "amount": "116666666666666706"}],
444+
}
445+
446+
params = json.loads(
447+
cli.raw("query", "mint", "params", output="json", node=cli.node_rpc)
448+
)
449+
assert params["inflation_max"] == "0.010000000000000000"
450+
assert params["inflation_min"] == "0.008500000000000000"
451+
423452

424453
def test_cancel_upgrade(cluster):
425454
"""

integration_tests/upgrade-test.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ let
1515
(builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v3.3.4.tar.gz")
1616
{ }
1717
).chain-maind;
18+
fetchFlake =
19+
repo: rev:
20+
(pkgs.flake-compat {
21+
src = {
22+
outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz";
23+
inherit rev;
24+
shortRev = builtins.substring 0 7 rev;
25+
};
26+
}).defaultNix;
27+
# v4.2.13
28+
released4 =
29+
(fetchFlake "crypto-org-chain/chain-main" "18d675a0a0a61a7e2b265d90c51959f4888e925e").default;
1830
current = pkgs.callPackage ../. { };
1931
in
2032
pkgs.linkFarm "upgrade-test-package" [
@@ -32,6 +44,10 @@ pkgs.linkFarm "upgrade-test-package" [
3244
}
3345
{
3446
name = "v4.2.0";
47+
path = released4;
48+
}
49+
{
50+
name = "v5.0.0";
3551
path = current;
3652
}
3753
]

nix/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sources.nixpkgs {
66
overlays = [
77
(_: pkgs: {
8+
flake-compat = import sources.flake-compat;
89
cosmovisor = pkgs.buildGoModule rec {
910
name = "cosmovisor";
1011
src = sources.cosmos-sdk + "/cosmovisor";

nix/sources.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
"url": "https://github.com/cosmos/cosmos-sdk/archive/b6c77e6c819f8a51166649eaef125d1bfb276f04.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
},
14+
"flake-compat": {
15+
"branch": "master",
16+
"description": null,
17+
"homepage": null,
18+
"owner": "edolstra",
19+
"repo": "flake-compat",
20+
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
21+
"sha256": "1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7",
22+
"type": "tarball",
23+
"url": "https://github.com/edolstra/flake-compat/archive/b4a34015c698c7793d592d66adbab377907a2be8.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
},
1426
"gomod2nix": {
1527
"branch": "master",
1628
"description": "Convert applications using Go modules to Nix expressions",

0 commit comments

Comments
 (0)