@@ -13,9 +13,9 @@ import (
1313
1414// MigrateStore migrates the x/dlc module state from the consensus version 1 to
1515// version 2
16- func MigrateStore (ctx sdk.Context , storeKey storetypes.StoreKey , tssStoreKey storetypes. StoreKey , cdc codec.BinaryCodec ) error {
16+ func MigrateStore (ctx sdk.Context , storeKey storetypes.StoreKey , tssKeeper types. TSSKeeper , cdc codec.BinaryCodec ) error {
1717 migrateDLCEvents (ctx , storeKey , cdc )
18- migrateDCMsAndOracles (ctx , storeKey , tssStoreKey , cdc )
18+ migrateDCMsAndOracles (ctx , storeKey , tssKeeper , cdc )
1919
2020 return nil
2121}
@@ -31,40 +31,28 @@ func migrateDLCEvents(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.B
3131 var dlcEvent types.DLCEvent
3232 cdc .MustUnmarshal (iterator .Value (), & dlcEvent )
3333
34- // set the DKG request by status
34+ // set event by status
3535 store .Set (types .EventByStatusKey (dlcEvent .HasTriggered , dlcEvent .Id ), []byte {})
3636 }
3737}
3838
3939// 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
40+ func migrateDCMsAndOracles (ctx sdk.Context , storeKey storetypes.StoreKey , tssKeeper types. TSSKeeper , cdc codec.BinaryCodec ) {
41+ tssKeeper . IterateDKGRequests ( ctx , func ( req * tsstypes. DKGRequest ) ( stop bool ) {
42+ if req . Status == tsstypes . DKGStatus_DKG_STATUS_COMPLETED {
43+ // dcm or oracle pub key
44+ pubKey := tssKeeper . GetDKGPubKeys ( ctx , req . Id )[ 0 ]
45+ pubKeyBz , _ := hex . DecodeString ( pubKey )
46+
47+ if req . Type == types . DKG_TYPE_DCM {
48+ updateDCM ( ctx , storeKey , req . Id , pubKeyBz , cdc )
49+ } else if req . Type == types . DKG_TYPE_NONCE {
50+ updateOracle ( ctx , storeKey , req . Id , pubKeyBz , cdc )
51+ }
5252 }
5353
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- }
54+ return false
55+ })
6856}
6957
7058// updateDCM updates the given dcm
0 commit comments