Skip to content

Commit

Permalink
migration additions
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Dec 7, 2024
1 parent 3786cbb commit fe19c3c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
8 changes: 0 additions & 8 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,12 @@ type Keeper struct {
LastTotalPower collections.Item[math.Int]
// DelegationsByValidator key: valAddr+delAddr | value: none used (index key for delegations by validator index)
DelegationsByValidator collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte]
UnbondingID collections.Sequence
// ValidatorByConsensusAddress key: consAddr | value: valAddr
ValidatorByConsensusAddress collections.Map[sdk.ConsAddress, sdk.ValAddress]
// UnbondingType key: unbondingID | value: index of UnbondingType
UnbondingType collections.Map[uint64, uint64]
// Redelegations key: AccAddr+SrcValAddr+DstValAddr | value: Redelegation
Redelegations collections.Map[collections.Triple[[]byte, []byte, []byte], types.Redelegation]
// Delegations key: AccAddr+valAddr | value: Delegation
Delegations collections.Map[collections.Pair[sdk.AccAddress, sdk.ValAddress], types.Delegation]
// UnbondingIndex key:UnbondingID | value: ubdKey (ubdKey = [UnbondingDelegationKey(Prefix)+len(delAddr)+delAddr+len(valAddr)+valAddr])
UnbondingIndex collections.Map[uint64, []byte]
// UnbondingQueue key: Timestamp | value: DVPairs [delAddr+valAddr]
UnbondingQueue collections.Map[time.Time, types.DVPairs]
// Validators key: valAddr | value: Validator
Expand Down Expand Up @@ -178,14 +173,12 @@ func NewKeeper(
),
collections.BytesValue,
),
UnbondingID: collections.NewSequence(sb, types.UnbondingIDKey, "unbonding_id"),
ValidatorByConsensusAddress: collections.NewMap(
sb, types.ValidatorsByConsAddrKey,
"validator_by_cons_addr",
sdk.LengthPrefixedAddressKey(sdk.ConsAddressKey).WithName("cons_address"), //nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility
collcodec.KeyToValueCodec(sdk.ValAddressKey),
),
UnbondingType: collections.NewMap(sb, types.UnbondingTypeKey, "unbonding_type", collections.Uint64Key.WithName("unbonding_id"), collections.Uint64Value),
// key format is: 52 | lengthPrefixedBytes(AccAddr) | lengthPrefixedBytes(SrcValAddr) | lengthPrefixedBytes(DstValAddr)
Redelegations: collections.NewMap(
sb, types.RedelegationKey,
Expand All @@ -200,7 +193,6 @@ func NewKeeper(
),
codec.CollValue[types.Redelegation](cdc),
),
UnbondingIndex: collections.NewMap(sb, types.UnbondingIndexKey, "unbonding_index", collections.Uint64Key.WithName("index"), collections.BytesValue.WithName("ubd_key")),
UnbondingDelegationByValIndex: collections.NewMap(
sb, types.UnbondingDelegationByValIndexKey,
"unbonding_delegation_by_val_index",
Expand Down
11 changes: 9 additions & 2 deletions x/staking/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,16 @@ func (k Keeper) unbondMatureValidators(
return errors.New("unexpected validator in unbonding queue; status was not unbonding")
}

val = k.UnbondingToUnbonded(ctx, val)
val, err = k.UnbondingToUnbonded(ctx, val)
if err != nil {
return err
}
if val.GetDelegatorShares().IsZero() {
k.RemoveValidator(ctx, val.GetOperator())
addr, err := k.validatorAddressCodec.StringToBytes(val.OperatorAddress)
if err != nil {
return err
}
k.RemoveValidator(ctx, addr)
}
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions x/staking/migrations/v6/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package v6
import "cosmossdk.io/collections"

var (
UnbondingTypeKey = collections.NewPrefix(57) // prefix for an index containing the type of unbonding operations
UnbondingIDKey = collections.NewPrefix(55) // key for the counter for the incrementing id for UnbondingOperations
UnbondingIndexKey = collections.NewPrefix(56) // prefix for an index for looking up unbonding operations by their IDs
ValidatorUpdatesKey = collections.NewPrefix(97)
HistoricalInfoKey = collections.NewPrefix(80) // prefix for the historical info
)
3 changes: 3 additions & 0 deletions x/staking/migrations/v6/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ import (
func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
store.Delete(ValidatorUpdatesKey)
store.Delete(HistoricalInfoKey)
store.Delete(UnbondingIDKey)
store.Delete(UnbondingIndexKey)
store.Delete(UnbondingTypeKey)
return nil
}
4 changes: 0 additions & 4 deletions x/staking/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ var (
RedelegationByValSrcIndexKey = collections.NewPrefix(53) // prefix for each key for a redelegation, by source validator operator
RedelegationByValDstIndexKey = collections.NewPrefix(54) // prefix for each key for a redelegation, by destination validator operator

UnbondingIDKey = collections.NewPrefix(55) // key for the counter for the incrementing id for UnbondingOperations
UnbondingIndexKey = collections.NewPrefix(56) // prefix for an index for looking up unbonding operations by their IDs
UnbondingTypeKey = collections.NewPrefix(57) // prefix for an index containing the type of unbonding operations

UnbondingQueueKey = collections.NewPrefix(65) // prefix for the timestamps in unbonding queue
RedelegationQueueKey = collections.NewPrefix(66) // prefix for the timestamps in redelegations queue
ValidatorQueueKey = collections.NewPrefix(67) // prefix for the timestamps in validator queue
Expand Down

0 comments on commit fe19c3c

Please sign in to comment.