Skip to content

Commit b7c7e97

Browse files
authored
fix(staking): temporary fix for key duplicated issue (#28)
* fix(staking): temporary solution for key duplicated issue * fix(staking): add GetUnbondingID func
1 parent ccb63d8 commit b7c7e97

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

x/staking/keeper/unbonding.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,48 @@ import (
1010
"github.com/cosmos/cosmos-sdk/x/staking/types"
1111
)
1212

13+
func (k Keeper) GetOldUnbondingID(ctx context.Context) (unbondingID uint64, err error) {
14+
store := k.storeService.OpenKVStore(ctx)
15+
// Old UnbondingID used same key as period delegation
16+
bz, err := store.Get(types.PeriodDelegationKey)
17+
if err != nil {
18+
return 0, err
19+
}
20+
21+
if bz != nil {
22+
unbondingID = binary.BigEndian.Uint64(bz)
23+
}
24+
25+
return unbondingID, err
26+
}
27+
28+
func (k Keeper) GetUnbondingID(ctx context.Context) (unbondingID uint64, err error) {
29+
store := k.storeService.OpenKVStore(ctx)
30+
bz, err := store.Get(types.UnbondingIDKey)
31+
if err != nil {
32+
return 0, err
33+
}
34+
35+
if bz != nil {
36+
unbondingID = binary.BigEndian.Uint64(bz)
37+
}
38+
39+
return unbondingID, err
40+
}
41+
42+
func (k Keeper) SetUnbondingID(ctx context.Context, unbondingID uint64) error {
43+
store := k.storeService.OpenKVStore(ctx)
44+
// Convert into bytes for storage
45+
bz := make([]byte, 8)
46+
binary.BigEndian.PutUint64(bz, unbondingID)
47+
48+
if err := store.Set(types.UnbondingIDKey, bz); err != nil {
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
1355
// IncrementUnbondingID increments and returns a unique ID for an unbonding operation
1456
func (k Keeper) IncrementUnbondingID(ctx context.Context) (unbondingID uint64, err error) {
1557
store := k.storeService.OpenKVStore(ctx)

x/staking/types/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ var (
4343
RedelegationByValDstIndexKey = []byte{0x36} // prefix for each key for an redelegation, by destination validator operator
4444
PeriodDelegationKey = []byte{0x37} // key for a period delegation
4545

46-
UnbondingIDKey = []byte{0x37} // key for the counter for the incrementing id for UnbondingOperations
4746
UnbondingIndexKey = []byte{0x38} // prefix for an index for looking up unbonding operations by their IDs
4847
UnbondingTypeKey = []byte{0x39} // prefix for an index containing the type of unbonding operations
48+
UnbondingIDKey = []byte{0x40} // key for the counter for the incrementing id for UnbondingOperations
4949

5050
UnbondingQueueKey = []byte{0x41} // prefix for the timestamps in unbonding queue
5151
RedelegationQueueKey = []byte{0x42} // prefix for the timestamps in redelegations queue

0 commit comments

Comments
 (0)