Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/staking): Migrate UnbondingDelegationByValIndex to use collections #17291

Merged
merged 63 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f551008
change UnbondingDelegationByValIndexKey to use collections prefix
likhita-809 Aug 3, 2023
ecf2d25
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 4, 2023
49bb6d9
move UnbondingDelegationByValIndex
likhita-809 Aug 4, 2023
74aa65d
fix lint
likhita-809 Aug 7, 2023
2a94074
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 7, 2023
54e3f91
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 7, 2023
0a02c45
remove unused GetUBDKeyFromValIndexKey
likhita-809 Aug 7, 2023
ec03801
fix integration tests
likhita-809 Aug 7, 2023
6a511b7
fix tests
likhita-809 Aug 7, 2023
b1ae859
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 7, 2023
efd620c
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 8, 2023
6932ae8
add changelog
likhita-809 Aug 8, 2023
b255839
nit
likhita-809 Aug 8, 2023
1496889
wip: use keyset
likhita-809 Aug 8, 2023
5005687
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 8, 2023
4dcf9ef
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
1bd8833
Revert "wip: use keyset"
likhita-809 Aug 9, 2023
f5ccac8
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
2aa4e7c
bump collections & remove ErrInvaliIterator
likhita-809 Aug 9, 2023
de9ff14
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
0bb8455
run go mod tidy
likhita-809 Aug 9, 2023
348229f
fix tests
likhita-809 Aug 9, 2023
81b81cb
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 10, 2023
512a428
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 10, 2023
9c6c248
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 10, 2023
b067556
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 10, 2023
71c9730
increase consensus version
likhita-809 Aug 10, 2023
76a5189
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 11, 2023
400aa1a
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 16, 2023
bfac9f9
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 16, 2023
cc7b5ea
revert cons version change
likhita-809 Aug 16, 2023
cfdd38c
revert go mod changes
likhita-809 Aug 16, 2023
3087457
address review comments
likhita-809 Aug 18, 2023
d1e26bc
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 18, 2023
ac2eefb
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 18, 2023
2bb19fe
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 18, 2023
6cd410c
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 21, 2023
9e8ca80
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 21, 2023
e65f4d7
add diff test
likhita-809 Aug 21, 2023
c5f2950
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 21, 2023
a1b2ee6
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 22, 2023
eec358e
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 23, 2023
01ab986
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 23, 2023
af7c7a0
address review comment
likhita-809 Aug 23, 2023
f78356c
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 23, 2023
a7143e3
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 23, 2023
3e51a94
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 24, 2023
053127a
address review comments
likhita-809 Aug 24, 2023
a6c9044
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 24, 2023
3da55cf
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 28, 2023
b15183a
address review comments
likhita-809 Aug 28, 2023
b1a5200
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 28, 2023
a0cc241
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 28, 2023
012f9f4
remove duplicate keeper test
likhita-809 Aug 28, 2023
caee945
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 28, 2023
2ce8b8a
Merge branch 'main' into likhita/ubdValIndex-coll
likhita-809 Aug 28, 2023
f1be944
Merge branch 'main' into likhita/ubdValIndex-coll
likhita-809 Aug 29, 2023
e4cc6c5
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 29, 2023
9504954
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 29, 2023
d3c738f
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 29, 2023
a6ca994
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 29, 2023
41e3b1d
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 30, 2023
6d3e6f0
Merge branch 'main' into likhita/ubdValIndex-coll
facundomedica Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/staking) [#17291](https://github.com/cosmos/cosmos-sdk/pull/17291) Use collections for `UnbondingDelegationByValIndex`:
* remove from `types`: `GetUBDKeyFromValIndexKey`, `GetUBDsByValIndexKey`
* (types) `module.BeginBlockAppModule` has been replaced by Core API `appmodule.HasBeginBlocker`.
* (types) `module.EndBlockAppModule` has been replaced by Core API `appmodule.HasEndBlocker` or `module.HasABCIEndBlock` when needing validator updates.
* (types) [#17358](https://github.com/cosmos/cosmos-sdk/pull/17358) Remove deprecated `sdk.Handler`, use `baseapp.MsgServiceHandler` instead.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module github.com/cosmos/cosmos-sdk

require (
cosmossdk.io/api v0.7.0
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4=
cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b h1:iO8c5DtWPLW2P93UyOck15qUXa2Ov8YC4NB4NuAkAGo=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b/go.mod h1:gsMCmujMwe1w5+0NvHGyvUUvOmJt1EMZuyjPH41yvzQ=
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
Expand Down
2 changes: 1 addition & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.31.0 // indirect
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 // indirect
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b // indirect
cosmossdk.io/errors v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4=
cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b h1:iO8c5DtWPLW2P93UyOck15qUXa2Ov8YC4NB4NuAkAGo=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b/go.mod h1:gsMCmujMwe1w5+0NvHGyvUUvOmJt1EMZuyjPH41yvzQ=
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
Expand Down
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
cosmossdk.io/api v0.7.0
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b
cosmossdk.io/core v0.9.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4=
cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68 h1:aFHpJtJgdqBH8kRvD86Rl92rvd1+JFpaUpj+5NZNodg=
cosmossdk.io/collections v0.3.1-0.20230808102719-f04fefdc7a68/go.mod h1:OK08xZu8fxXLoQcFIfkBDayo2aRokLfC3vVcXX0MB8E=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b h1:iO8c5DtWPLW2P93UyOck15qUXa2Ov8YC4NB4NuAkAGo=
cosmossdk.io/collections v0.3.1-0.20230809092832-b83d90a4737b/go.mod h1:gsMCmujMwe1w5+0NvHGyvUUvOmJt1EMZuyjPH41yvzQ=
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
cosmossdk.io/core v0.9.0/go.mod h1:NFgl5r41Q36+RixTvyrfsS6qQ65agCbZ1FTpnN7/G1Y=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
Expand Down
38 changes: 21 additions & 17 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,30 @@ func (k Keeper) GetUnbondingDelegation(ctx context.Context, delAddr sdk.AccAddre
// particular validator.
func (k Keeper) GetUnbondingDelegationsFromValidator(ctx context.Context, valAddr sdk.ValAddress) (ubds []types.UnbondingDelegation, err error) {
store := k.storeService.OpenKVStore(ctx)
prefix := types.GetUBDsByValIndexKey(valAddr)
iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix))
rng := collections.NewPrefixUntilPairRange[sdk.ValAddress, sdk.AccAddress](valAddr)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
err = k.UnbondingDelegationByValIndex.Walk(
ctx,
rng,
func(key collections.Pair[sdk.ValAddress, sdk.AccAddress], value []byte) (stop bool, err error) {
valAddr := key.K1()
delAddr := key.K2()
delAddr = delAddr[1:] // remove prefix bytes
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
ubdkey := types.GetUBDKey(delAddr, valAddr)
ubdValue, err := store.Get(ubdkey)
if err != nil {
return true, err
}
unbondingDelegation, err := types.UnmarshalUBD(k.cdc, ubdValue)
if err != nil {
return true, err
}
ubds = append(ubds, unbondingDelegation)
return false, nil
},
)
if err != nil {
return ubds, err
}
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
key := types.GetUBDKeyFromValIndexKey(iterator.Key())
value, err := store.Get(key)
if err != nil {
return ubds, err
}
ubd, err := types.UnmarshalUBD(k.cdc, value)
if err != nil {
return ubds, err
}
ubds = append(ubds, ubd)
}

return ubds, nil
}

Expand Down
33 changes: 20 additions & 13 deletions x/staking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,26 @@ func (k Querier) ValidatorUnbondingDelegations(ctx context.Context, req *types.Q
}

store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
srcValPrefix := types.GetUBDsByValIndexKey(valAddr)
ubdStore := prefix.NewStore(store, srcValPrefix)
pageRes, err := query.Paginate(ubdStore, req.Pagination, func(key, value []byte) error {
storeKey := types.GetUBDKeyFromValIndexKey(append(srcValPrefix, key...))
storeValue := store.Get(storeKey)

ubd, err := types.UnmarshalUBD(k.cdc, storeValue)
if err != nil {
return err
}
ubds = append(ubds, ubd)
return nil
})
_, pageRes, err := query.CollectionPaginate(
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
ctx,
k.UnbondingDelegationByValIndex,
req.Pagination,
func(key collections.Pair[sdk.ValAddress, sdk.AccAddress], value []byte) (types.UnbondingDelegation, error) {
valAddr := key.K1()
delAddr := key.K2()
delAddr = delAddr[1:] // remove prefix bytes
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
ubdKey := types.GetUBDKey(delAddr, valAddr)
storeValue := store.Get(ubdKey)

ubd, err := types.UnmarshalUBD(k.cdc, storeValue)
if err != nil {
return types.UnbondingDelegation{}, err
}
ubds = append(ubds, ubd)
return ubd, nil
},
query.WithCollectionPaginationPairPrefix[sdk.ValAddress, sdk.AccAddress](valAddr),
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
27 changes: 17 additions & 10 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ type Keeper struct {
validatorAddressCodec addresscodec.Codec
consensusAddressCodec addresscodec.Codec

Schema collections.Schema
HistoricalInfo collections.Map[uint64, types.HistoricalInfo]
LastTotalPower collections.Item[math.Int]
ValidatorUpdates collections.Item[types.ValidatorUpdates]
DelegationsByValidator collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte]
UnbondingID collections.Sequence
ValidatorByConsensusAddress collections.Map[sdk.ConsAddress, sdk.ValAddress]
UnbondingType collections.Map[uint64, uint64]
Delegations collections.Map[collections.Pair[sdk.AccAddress, sdk.ValAddress], types.Delegation]
UnbondingIndex collections.Map[uint64, []byte]
Schema collections.Schema
HistoricalInfo collections.Map[uint64, types.HistoricalInfo]
LastTotalPower collections.Item[math.Int]
ValidatorUpdates collections.Item[types.ValidatorUpdates]
DelegationsByValidator collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte]
UnbondingID collections.Sequence
ValidatorByConsensusAddress collections.Map[sdk.ConsAddress, sdk.ValAddress]
UnbondingType collections.Map[uint64, uint64]
Delegations collections.Map[collections.Pair[sdk.AccAddress, sdk.ValAddress], types.Delegation]
UnbondingIndex collections.Map[uint64, []byte]
UnbondingDelegationByValIndex collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte]
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
}

// NewKeeper creates a new staking Keeper instance
Expand Down Expand Up @@ -109,6 +110,12 @@ func NewKeeper(
),
UnbondingType: collections.NewMap(sb, types.UnbondingTypeKey, "unbonding_type", collections.Uint64Key, collections.Uint64Value),
UnbondingIndex: collections.NewMap(sb, types.UnbondingIndexKey, "unbonding_index", collections.Uint64Key, collections.BytesValue),
UnbondingDelegationByValIndex: collections.NewMap(
sb, types.UnbondingDelegationByValIndexKey,
"unbonding_delegation_by_val_index",
collections.PairKeyCodec(sdk.LengthPrefixedAddressKey(sdk.ValAddressKey), sdk.AccAddressKey), // nolint: staticcheck // sdk.LengthPrefixedAddressKey is needed to retain state compatibility
collections.BytesValue,
),
}

schema, err := sb.Build()
Expand Down
4 changes: 2 additions & 2 deletions x/staking/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec/address"
sdktestuil "github.com/cosmos/cosmos-sdk/testutil"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
v1 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1"
Expand All @@ -22,7 +22,7 @@ import (
func TestStoreMigration(t *testing.T) {
stakingKey := storetypes.NewKVStoreKey("staking")
tStakingKey := storetypes.NewTransientStoreKey("transient_test")
ctx := sdktestuil.DefaultContext(stakingKey, tStakingKey)
ctx := sdktestutil.DefaultContext(stakingKey, tStakingKey)
store := ctx.KVStore(stakingKey)

_, pk1, addr1 := testdata.KeyTestPubAddr()
Expand Down
23 changes: 2 additions & 21 deletions x/staking/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

DelegationKey = collections.NewPrefix(49) // key for a delegation
UnbondingDelegationKey = []byte{0x32} // key for an unbonding-delegation
UnbondingDelegationByValIndexKey = []byte{0x33} // prefix for each key for an unbonding-delegation, by validator operator
UnbondingDelegationByValIndexKey = collections.NewPrefix(51) // prefix for each key for an unbonding-delegation, by validator operator
RedelegationKey = []byte{0x34} // key for a redelegation
RedelegationByValSrcIndexKey = []byte{0x35} // prefix for each key for an redelegation, by source validator operator
RedelegationByValDstIndexKey = []byte{0x36} // prefix for each key for an redelegation, by destination validator operator
Expand Down Expand Up @@ -199,33 +199,14 @@ func GetUBDKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte {
// GetUBDByValIndexKey creates the index-key for an unbonding delegation, stored by validator-index
// VALUE: none (key rearrangement used)
func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte {
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
return append(GetUBDsByValIndexKey(valAddr), address.MustLengthPrefix(delAddr)...)
}

// GetUBDKeyFromValIndexKey rearranges the ValIndexKey to get the UBDKey
func GetUBDKeyFromValIndexKey(indexKey []byte) []byte {
kv.AssertKeyAtLeastLength(indexKey, 2)
addrs := indexKey[1:] // remove prefix bytes

valAddrLen := addrs[0]
kv.AssertKeyAtLeastLength(addrs, 2+int(valAddrLen))
valAddr := addrs[1 : 1+valAddrLen]
kv.AssertKeyAtLeastLength(addrs, 3+int(valAddrLen))
delAddr := addrs[valAddrLen+2:]

return GetUBDKey(delAddr, valAddr)
return append(append(UnbondingDelegationByValIndexKey, address.MustLengthPrefix(valAddr)...), address.MustLengthPrefix(delAddr)...)
}

// GetUBDsKey creates the prefix for all unbonding delegations from a delegator
func GetUBDsKey(delAddr sdk.AccAddress) []byte {
return append(UnbondingDelegationKey, address.MustLengthPrefix(delAddr)...)
}

// GetUBDsByValIndexKey creates the prefix keyspace for the indexes of unbonding delegations for a validator
func GetUBDsByValIndexKey(valAddr sdk.ValAddress) []byte {
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
return append(UnbondingDelegationByValIndexKey, address.MustLengthPrefix(valAddr)...)
}

// GetUnbondingDelegationTimeKey creates the prefix for all unbonding delegations from a delegator
func GetUnbondingDelegationTimeKey(timestamp time.Time) []byte {
bz := sdk.FormatTimeBytes(timestamp)
Expand Down