Skip to content

Commit 4efd205

Browse files
committed
upgrade to v2.0.0-rc.6
1 parent 02c0de6 commit 4efd205

File tree

17 files changed

+3037
-47
lines changed

17 files changed

+3037
-47
lines changed

api/side/dlc/params.pulsar.go

Lines changed: 1822 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import (
159159

160160
upgradev2 "github.com/sideprotocol/side/app/upgrades/v2"
161161
upgradev2rc5 "github.com/sideprotocol/side/app/upgrades/v2_rc5"
162+
upgradev2rc6 "github.com/sideprotocol/side/app/upgrades/v2_rc6"
162163
)
163164

164165
const (
@@ -1311,6 +1312,7 @@ func BlockedAddresses() map[string]bool {
13111312
func (app *App) SetUpgradeHandlers() {
13121313
app.UpgradeKeeper.SetUpgradeHandler(upgradev2.UpgradeName, upgradev2.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13131314
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc5.UpgradeName, upgradev2rc5.CreateUpgradeHandler(app.ModuleManager, app.configurator))
1315+
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc6.UpgradeName, upgradev2rc6.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13141316

13151317
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
13161318
if err != nil {

app/upgrades/v2_rc6/upgrade.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package v2_rc7
2+
3+
import (
4+
"context"
5+
6+
upgradetypes "cosmossdk.io/x/upgrade/types"
7+
"github.com/cosmos/cosmos-sdk/types/module"
8+
)
9+
10+
// UpgradeName is the upgrade version name
11+
const UpgradeName = "v2.0.0-rc.6"
12+
13+
// CreateUpgradeHandler creates the upgrade handler
14+
func CreateUpgradeHandler(
15+
mm *module.Manager,
16+
configurator module.Configurator,
17+
) upgradetypes.UpgradeHandler {
18+
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
19+
return mm.RunMigrations(ctx, configurator, vm)
20+
}
21+
}

proto/side/dlc/params.proto

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,27 @@ message Params {
1616
uint32 oracle_participant_num = 5;
1717
uint32 oracle_participant_threshold = 6;
1818
}
19+
20+
message PricePair {
21+
string pair = 1;
22+
int32 decimals = 2;
23+
string interval = 3 [
24+
(cosmos_proto.scalar) = "cosmos.Dec",
25+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
26+
(gogoproto.nullable) = false
27+
];
28+
}
29+
30+
// ParamsV1 defines the v1 parameters for the module.
31+
message ParamsV1 {
32+
uint32 price_event_nonce_queue_size = 1;
33+
repeated PricePair price_pairs = 2 [(gogoproto.nullable) = false];
34+
uint32 date_event_nonce_queue_size = 3;
35+
google.protobuf.Duration date_interval = 4 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
36+
uint32 lending_event_nonce_queue_size = 5;
37+
repeated string allowed_oracle_participants = 6;
38+
uint32 oracle_participant_num = 7;
39+
uint32 oracle_participant_threshold = 8;
40+
uint32 nonce_generation_batch_size = 9;
41+
int64 nonce_generation_interval = 10;
42+
}

x/dlc/keeper/migrations.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package keeper
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
6+
v2 "github.com/sideprotocol/side/x/dlc/migrations/v2"
7+
)
8+
9+
// Migrator is a struct for handling in-place store migrations
10+
type Migrator struct {
11+
keeper Keeper
12+
}
13+
14+
// NewMigrator returns a new Migrator
15+
func NewMigrator(keeper Keeper) Migrator {
16+
return Migrator{keeper: keeper}
17+
}
18+
19+
// Migrate1to2 migrates from version 1 to 2
20+
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
21+
return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
22+
}

x/dlc/migrations/v2/store.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package v3
2+
3+
import (
4+
storetypes "cosmossdk.io/store/types"
5+
"github.com/cosmos/cosmos-sdk/codec"
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
8+
"github.com/sideprotocol/side/x/dlc/types"
9+
)
10+
11+
// MigrateStore migrates the x/dlc module state from the consensus version 1 to
12+
// version 2
13+
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
14+
migrateParams(ctx, storeKey, cdc)
15+
migrateStore(ctx, storeKey, cdc)
16+
17+
return nil
18+
}
19+
20+
// migrateParams performs the params migration
21+
func migrateParams(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
22+
store := ctx.KVStore(storeKey)
23+
24+
// get current params
25+
var paramsV1 types.ParamsV1
26+
bz := store.Get(types.ParamsKey)
27+
cdc.MustUnmarshal(bz, &paramsV1)
28+
29+
// build new params
30+
params := &types.Params{
31+
NonceQueueSize: paramsV1.LendingEventNonceQueueSize,
32+
NonceGenerationBatchSize: paramsV1.NonceGenerationBatchSize,
33+
NonceGenerationInterval: paramsV1.NonceGenerationInterval,
34+
AllowedOracleParticipants: paramsV1.AllowedOracleParticipants,
35+
OracleParticipantNum: paramsV1.OracleParticipantNum,
36+
OracleParticipantThreshold: paramsV1.OracleParticipantThreshold,
37+
}
38+
39+
bz = cdc.MustMarshal(params)
40+
store.Set(types.ParamsKey, bz)
41+
42+
for _, participant := range params.AllowedOracleParticipants {
43+
liveness := &types.OracleParticipantLiveness{
44+
ConsensusPubkey: participant,
45+
IsAlive: true,
46+
LastDkgId: 0,
47+
LastBlockHeight: 0,
48+
}
49+
50+
bz := cdc.MustMarshal(liveness)
51+
52+
store.Set(types.OracleParticipantLivenessKey(participant), bz)
53+
}
54+
}
55+
56+
// migrateStore performs the store migration
57+
func migrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
58+
store := ctx.KVStore(storeKey)
59+
60+
// get the current dcm id
61+
dcmIdBz := store.Get(types.DCMIdKey)
62+
63+
// update the current oracle id to the latest dcm id
64+
store.Set(types.OracleIdKey, dcmIdBz)
65+
66+
// update the current dcm id to the latest dcm id
67+
iterateDCMs(ctx, storeKey, cdc, func(dcm *types.DCM) (stop bool) {
68+
store.Set(types.DCMIdKey, sdk.Uint64ToBigEndian(dcm.Id))
69+
return false
70+
})
71+
}
72+
73+
// iterateDCMs iterates through all DCMs
74+
func iterateDCMs(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, cb func(dcm *types.DCM) (stop bool)) {
75+
store := ctx.KVStore(storeKey)
76+
77+
iterator := storetypes.KVStorePrefixIterator(store, types.DCMKeyPrefix)
78+
defer iterator.Close()
79+
80+
for ; iterator.Valid(); iterator.Next() {
81+
var dcm types.DCM
82+
cdc.MustUnmarshal(iterator.Value(), &dcm)
83+
84+
if cb(&dcm) {
85+
break
86+
}
87+
}
88+
}

x/dlc/module/module.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
"github.com/sideprotocol/side/x/dlc/types"
2424
)
2525

26+
// ConsensusVersion defines the current x/dlc module consensus version.
27+
const ConsensusVersion = 2
28+
2629
var (
2730
_ module.AppModule = AppModule{}
2831
_ module.AppModuleBasic = AppModuleBasic{}
@@ -118,6 +121,11 @@ func (am AppModule) IsAppModule() {}
118121
func (am AppModule) RegisterServices(cfg module.Configurator) {
119122
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
120123
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
124+
125+
m := keeper.NewMigrator(am.keeper)
126+
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
127+
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
128+
}
121129
}
122130

123131
// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
@@ -141,7 +149,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
141149
}
142150

143151
// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
144-
func (AppModule) ConsensusVersion() uint64 { return 1 }
152+
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
145153

146154
// BeginBlock contains the logic that is automatically triggered at the beginning of each block
147155
func (am AppModule) BeginBlock(_ context.Context) error {

0 commit comments

Comments
 (0)