-
Notifications
You must be signed in to change notification settings - Fork 66
/
upgrades.go
87 lines (74 loc) · 3.2 KB
/
upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package v010
import (
appparams "github.com/bitsongofficial/go-bitsong/app/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/feegrant"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/packetforward/types"
)
func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
bank bankkeeper.Keeper,
ibc *ibckeeper.Keeper,
staking *stakingkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ibc.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())
fromVM := make(map[string]uint64)
for moduleName := range mm.Modules {
fromVM[moduleName] = 1
}
// delete new modules from the map, for _new_ modules as to not skip InitGenesis
delete(fromVM, authz.ModuleName)
delete(fromVM, feegrant.ModuleName)
delete(fromVM, packetforwardtypes.ModuleName)
// make fromVM[authtypes.ModuleName] = 2 to skip the first RunMigrations for auth (because from version 2 to migration version 2 will not migrate)
fromVM[authtypes.ModuleName] = 2
// the first RunMigrations, which will migrate all the old modules except auth module
newVM, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}
// now update auth version back to 1, to make the second RunMigrations includes only auth
newVM[authtypes.ModuleName] = 1
// Proposal #5
// Force an update of validator min commission
validators := staking.GetAllValidators(ctx)
minCommissionRate := sdk.NewDecWithPrec(5, 2)
for _, v := range validators {
if v.Commission.Rate.LT(minCommissionRate) {
if v.Commission.MaxRate.LT(minCommissionRate) {
v.Commission.MaxRate = minCommissionRate
}
v.Commission.Rate = minCommissionRate
v.Commission.UpdateTime = ctx.BlockHeader().Time
// call the before-modification hook since we're about to update the commission
staking.BeforeValidatorModified(ctx, v.GetOperator())
staking.SetValidator(ctx, v)
}
}
// Proposal #6
// Mint BTSGs for Cassini-Bridge
multisigWallet, err := sdk.AccAddressFromBech32(CassiniMultiSig)
if err != nil {
return nil, err
}
mintCoins := sdk.NewCoins(sdk.NewCoin(appparams.DefaultBondDenom, sdk.NewInt(CassiniMintAmount)))
// mint coins
if err := bank.MintCoins(ctx, minttypes.ModuleName, mintCoins); err != nil {
return nil, err
}
if err := bank.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, multisigWallet, mintCoins); err != nil {
return nil, err
}
// RunMigrations twice is just a way to make auth module's migrates after staking
return mm.RunMigrations(ctx, configurator, newVM)
}
}