Skip to content

Commit 2936120

Browse files
committed
upgrade to v2.0.0-rc.13
1 parent 0aeb1d4 commit 2936120

File tree

17 files changed

+3062
-389
lines changed

17 files changed

+3062
-389
lines changed

api/side/dlc/dlc.pulsar.go

Lines changed: 1861 additions & 299 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
@@ -162,6 +162,7 @@ import (
162162
upgradev2rc10 "github.com/sideprotocol/side/app/upgrades/v2_rc10"
163163
upgradev2rc11 "github.com/sideprotocol/side/app/upgrades/v2_rc11"
164164
upgradev2rc12 "github.com/sideprotocol/side/app/upgrades/v2_rc12"
165+
upgradev2rc13 "github.com/sideprotocol/side/app/upgrades/v2_rc13"
165166
upgradev2rc8 "github.com/sideprotocol/side/app/upgrades/v2_rc8"
166167
upgradev2rc9 "github.com/sideprotocol/side/app/upgrades/v2_rc9"
167168
)
@@ -1338,6 +1339,7 @@ func (app *App) SetUpgradeHandlers() {
13381339
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc10.UpgradeName, upgradev2rc10.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13391340
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc11.UpgradeName, upgradev2rc11.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13401341
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc12.UpgradeName, upgradev2rc12.CreateUpgradeHandler(app.ModuleManager, app.configurator))
1342+
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc13.UpgradeName, upgradev2rc13.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13411343

13421344
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
13431345
if err != nil {

app/upgrades/v2_rc13/upgrade.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package v2_rc13
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.13"
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/dlc.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ message DLCOracle {
2121
DLCOracleStatus status = 7;
2222
}
2323

24+
message DLCOracleV1 {
25+
uint64 id = 1;
26+
string desc = 2;
27+
string pubkey = 3;
28+
uint64 nonce_index = 4;
29+
google.protobuf.Timestamp time = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
30+
DLCOracleStatus status = 6;
31+
}
32+
2433
enum DCMStatus {
2534
DCM_status_Enable = 0;
2635
DCM_status_Disable = 1;
@@ -35,6 +44,14 @@ message DCM {
3544
DCMStatus status = 6;
3645
}
3746

47+
message DCMV1 {
48+
uint64 id = 1;
49+
string desc = 2;
50+
string pubkey = 3;
51+
google.protobuf.Timestamp time = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
52+
DCMStatus status = 5;
53+
}
54+
3855
message DLCNonce {
3956
uint64 index = 1;
4057
string nonce = 2;

x/dlc/keeper/migrations.go

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

x/dlc/migrations/v2/store.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package v2
2+
3+
import (
4+
"encoding/hex"
5+
6+
storetypes "cosmossdk.io/store/types"
7+
"github.com/cosmos/cosmos-sdk/codec"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
10+
"github.com/sideprotocol/side/x/dlc/types"
11+
tsstypes "github.com/sideprotocol/side/x/tss/types"
12+
)
13+
14+
// MigrateStore migrates the x/dlc module state from the consensus version 1 to
15+
// version 2
16+
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, tssStoreKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
17+
migrateDLCEvents(ctx, storeKey, cdc)
18+
migrateDCMsAndOracles(ctx, storeKey, tssStoreKey, cdc)
19+
20+
return nil
21+
}
22+
23+
// migrateDLCEvents performs the dlc events migration
24+
func migrateDLCEvents(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
25+
store := ctx.KVStore(storeKey)
26+
27+
iterator := storetypes.KVStorePrefixIterator(store, types.EventKeyPrefix)
28+
defer iterator.Close()
29+
30+
for ; iterator.Valid(); iterator.Next() {
31+
var dlcEvent types.DLCEvent
32+
cdc.MustUnmarshal(iterator.Value(), &dlcEvent)
33+
34+
// set the DKG request by status
35+
store.Set(types.EventByStatusKey(dlcEvent.HasTriggered, dlcEvent.Id), []byte{})
36+
}
37+
}
38+
39+
// migrateDCMsAndOracles performs the DCMs and oracles migration
40+
func migrateDCMsAndOracles(ctx sdk.Context, storeKey storetypes.StoreKey, tssStoreKey storetypes.StoreKey, cdc codec.BinaryCodec) {
41+
tssStore := ctx.KVStore(tssStoreKey)
42+
43+
iterator := storetypes.KVStorePrefixIterator(tssStore, tsstypes.DKGRequestKeyPrefix)
44+
defer iterator.Close()
45+
46+
for ; iterator.Valid(); iterator.Next() {
47+
var dkgRequest tsstypes.DKGRequest
48+
cdc.MustUnmarshal(iterator.Value(), &dkgRequest)
49+
50+
if dkgRequest.Status != tsstypes.DKGStatus_DKG_STATUS_COMPLETED {
51+
continue
52+
}
53+
54+
bz := tssStore.Get(tsstypes.DKGCompletionKey(dkgRequest.Id, dkgRequest.Participants[0]))
55+
var dkgCompletion tsstypes.DKGCompletion
56+
cdc.MustUnmarshal(bz, &dkgCompletion)
57+
58+
// DCM or oracle pub key
59+
pubKey := dkgCompletion.PubKeys[0]
60+
pubKeyBz, _ := hex.DecodeString(pubKey)
61+
62+
if dkgRequest.Type == types.DKG_TYPE_DCM {
63+
updateDCM(ctx, storeKey, dkgRequest.Id, pubKeyBz, cdc)
64+
} else if dkgRequest.Type == types.DKG_TYPE_NONCE {
65+
updateOracle(ctx, storeKey, dkgRequest.Id, pubKeyBz, cdc)
66+
}
67+
}
68+
}
69+
70+
// updateDCM updates the given dcm
71+
func updateDCM(ctx sdk.Context, storeKey storetypes.StoreKey, dkgId uint64, pubKey []byte, cdc codec.BinaryCodec) {
72+
store := ctx.KVStore(storeKey)
73+
74+
bz := store.Get(types.DCMByPubKeyKey(pubKey))
75+
id := sdk.BigEndianToUint64(bz)
76+
77+
// unmarshal to DCM v1
78+
dcmBz := store.Get(types.DCMKey(id))
79+
var dcmV1 types.DCMV1
80+
cdc.MustUnmarshal(dcmBz, &dcmV1)
81+
82+
// build new DCM
83+
dcm := &types.DCM{
84+
Id: id,
85+
DkgId: dkgId,
86+
Desc: dcmV1.Desc,
87+
Pubkey: dcmV1.Pubkey,
88+
Time: dcmV1.Time,
89+
Status: dcmV1.Status,
90+
}
91+
92+
// update DCM
93+
store.Set(types.DCMKey(id), cdc.MustMarshal(dcm))
94+
}
95+
96+
// updateOracle updates the given oracle
97+
func updateOracle(ctx sdk.Context, storeKey storetypes.StoreKey, dkgId uint64, pubKey []byte, cdc codec.BinaryCodec) {
98+
store := ctx.KVStore(storeKey)
99+
100+
bz := store.Get(types.OracleByPubKeyKey(pubKey))
101+
id := sdk.BigEndianToUint64(bz)
102+
103+
// unmarshal to oracle v1
104+
oracleBz := store.Get(types.OracleKey(id))
105+
var oracleV1 types.DLCOracleV1
106+
cdc.MustUnmarshal(oracleBz, &oracleV1)
107+
108+
// build new oracle
109+
oracle := &types.DLCOracle{
110+
Id: id,
111+
DkgId: dkgId,
112+
Desc: oracleV1.Desc,
113+
Pubkey: oracleV1.Pubkey,
114+
NonceIndex: oracleV1.NonceIndex,
115+
Time: oracleV1.Time,
116+
Status: oracleV1.Status,
117+
}
118+
119+
// update oracle
120+
store.Set(types.OracleKey(id), cdc.MustMarshal(oracle))
121+
}

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)