-
Notifications
You must be signed in to change notification settings - Fork 568
/
upgrades.go
144 lines (126 loc) · 5.83 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package v24
import (
"sort"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
"github.com/osmosis-labs/osmosis/v24/app/keepers"
"github.com/osmosis-labs/osmosis/v24/app/upgrades"
concentratedliquidity "github.com/osmosis-labs/osmosis/v24/x/concentrated-liquidity"
concentratedtypes "github.com/osmosis-labs/osmosis/v24/x/concentrated-liquidity/types"
cwpooltypes "github.com/osmosis-labs/osmosis/v24/x/cosmwasmpool/types"
incentivestypes "github.com/osmosis-labs/osmosis/v24/x/incentives/types"
txfeestypes "github.com/osmosis-labs/osmosis/v24/x/txfees/types"
)
const (
mainnetChainID = "osmosis-1"
// Edgenet is to function exactly the same as mainnet, and expected
// to be state-exported from mainnet state.
edgenetChainID = "edgenet"
)
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Run migrations before applying any other state changes.
// NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations().
migrations, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}
// We no longer use the base denoms array and instead use the repeated base denoms field for performance reasons.
// We retrieve the old base denoms array from the KVStore, delete the array from the KVStore, and set them as a repeated field in the new KVStore.
baseDenoms, err := keepers.ProtoRevKeeper.DeprecatedGetAllBaseDenoms(ctx)
if err != nil {
return nil, err
}
keepers.ProtoRevKeeper.DeprecatedDeleteBaseDenoms(ctx)
err = keepers.ProtoRevKeeper.SetBaseDenoms(ctx, baseDenoms)
if err != nil {
return nil, err
}
// Now that the TWAP keys are refactored, we can delete all time indexed TWAPs
// since we only need the pool indexed TWAPs. We set the is pruning store value to true
// and spread the pruning time across multiple blocks to avoid a single block taking too long.
keepers.TwapKeeper.SetDeprecatedHistoricalTWAPsIsPruning(ctx)
// Set the new min value for distribution for the incentives module.
// https://www.mintscan.io/osmosis/proposals/733
keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyMinValueForDistr, incentivestypes.DefaultMinValueForDistr)
chainID := ctx.ChainID()
// We only perform the migration on mainnet pools since we hard-coded the pool IDs to migrate
// in the types package. And the testnet was migrated in v24
if chainID == mainnetChainID || chainID == edgenetChainID {
if err := migrateMainnetPools(ctx, *keepers.ConcentratedLiquidityKeeper); err != nil {
return nil, err
}
}
// Enable ICA controllers
keepers.ICAControllerKeeper.SetParams(ctx, icacontrollertypes.DefaultParams())
// White Whale uploaded a broken contract. They later migrated cwpool via the governance
// proposal in x/cosmwasmpool
// However, there was a problem in the migration logic where the CosmWasmpool state CodeId did not get updated.
// As a result, the CodeID for the contract that is tracked in x/wasmd was migrated correctly. However, the code ID that we track in the x/cosmwasmpool state did not.
// Therefore, we should perform a migration for each of the hardcoded white whale pools.
poolIds := []uint64{1584, 1575, 1514, 1463, 1462, 1461}
for _, poolId := range poolIds {
pool, err := keepers.CosmwasmPoolKeeper.GetPool(ctx, poolId)
if err != nil {
// Skip non-existent pools. This way we don't need to create the pools on E2E tests
continue
}
cwPool, ok := pool.(cwpooltypes.CosmWasmExtension)
if !ok {
ctx.Logger().Error("Pool has incorrect type", "poolId", poolId, "pool", pool)
return nil, cwpooltypes.InvalidPoolTypeError{
ActualPool: pool,
}
}
if cwPool.GetCodeId() != 503 && cwPool.GetCodeId() != 572 {
ctx.Logger().Error("Pool has incorrect code id", "poolId", poolId, "codeId", cwPool.GetCodeId())
return nil, cwpooltypes.InvalidPoolTypeError{
ActualPool: pool,
}
}
cwPool.SetCodeId(641)
keepers.CosmwasmPoolKeeper.SetPool(ctx, cwPool)
}
// Set whitelistedFeeTokenSetters param as per https://forum.osmosis.zone/t/temperature-check-add-a-permissioned-address-to-manage-the-fee-token-whitelist/2604
keepers.TxFeesKeeper.SetParam(ctx, txfeestypes.KeyWhitelistedFeeTokenSetters, WhitelistedFeeTokenSetters)
return migrations, nil
}
}
// migrateMainnetPools migrates the specified mainnet pools to the new accumulator scaling factor.
func migrateMainnetPools(ctx sdk.Context, concentratedKeeper concentratedliquidity.Keeper) error {
poolIDsToMigrate := make([]uint64, 0, len(concentratedtypes.MigratedIncentiveAccumulatorPoolIDsV24))
for poolID := range concentratedtypes.MigratedIncentiveAccumulatorPoolIDsV24 {
poolIDsToMigrate = append(poolIDsToMigrate, poolID)
}
// Sort for determinism
sort.Slice(poolIDsToMigrate, func(i, j int) bool {
return poolIDsToMigrate[i] < poolIDsToMigrate[j]
})
// Migrate concentrated pools
thresholdId, err := concentratedKeeper.GetIncentivePoolIDMigrationThreshold(ctx)
if err != nil {
return err
}
for _, poolID := range poolIDsToMigrate {
// This should never happen, this check is defence in depth in case we have wrong data by accident
if poolID >= thresholdId {
continue
}
// This should never happen, this check is defence in depth in case we have wrong data by accident
_, isMigrated := concentratedtypes.MigratedIncentiveAccumulatorPoolIDs[poolID]
if isMigrated {
continue
}
if err := concentratedKeeper.MigrateAccumulatorToScalingFactor(ctx, poolID); err != nil {
return err
}
}
return nil
}