Skip to content

Commit 99af2c5

Browse files
committed
backport refactor(x/staking)!: removing unbonding queue index (cosmos#22795)
(cherry picked from commit 234cdc4)
1 parent 4459c77 commit 99af2c5

29 files changed

+1105
-6713
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040

4141
### Features
4242

43+
* (x/staking) [#22795](https://github.com/cosmos/cosmos-sdk/pull/22795) `NewUnbondingDelegationEntry`, `NewUnbondingDelegation`, `AddEntry`, `NewRedelegationEntry`, `NewRedelegation` and `NewRedelegationEntryResponse` no longer take an ID in there function signatures.
44+
* (x/staking) [#22795](https://github.com/cosmos/cosmos-sdk/pull/22795) AfterUnbondingInitiated hook has been removed as it is no longer required by ICS.
45+
* (x/staking) [#22795](https://github.com/cosmos/cosmos-sdk/pull/22795) Keys `stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey, stakingtypes.UnbondingTypeKey` have been removed as they are no longer required by ICS.
4346
* (baseapp) [#205](https://github.com/crypto-org-chain/cosmos-sdk/pull/205) Add `TxExecutor` baseapp option, add `TxIndex`/`TxCount`/`MsgIndex`/`BlockGasUsed` fields to `Context, to support tx parallel execution.
4447
* (baseapp) [#206](https://github.com/crypto-org-chain/cosmos-sdk/pull/206) Support mount object store in baseapp, add `ObjectStore` api in context, [#585](https://github.com/crypto-org-chain/cosmos-sdk/pull/585) Skip snapshot for object store.
4548
* (bank) [#237](https://github.com/crypto-org-chain/cosmos-sdk/pull/237) Support virtual accounts in sending coins.

api/cosmos/staking/v1beta1/staking.pulsar.go

Lines changed: 180 additions & 177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/devtools/Dockerfile.custom

Lines changed: 0 additions & 17 deletions
This file was deleted.

contrib/devtools/nscacert_combined.pem

Lines changed: 0 additions & 4677 deletions
This file was deleted.

proto/cosmos/staking/v1beta1/staking.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ message UnbondingDelegationEntry {
245245
(gogoproto.nullable) = false
246246
];
247247
// Incrementing id that uniquely identifies this entry
248-
uint64 unbonding_id = 5;
248+
uint64 unbonding_id = 5 [deprecated = true];
249249

250250
// Strictly positive if this entry's unbonding has been stopped by external modules
251251
int64 unbonding_on_hold_ref_count = 6;

simapp/sim_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ func TestAppImportExport(t *testing.T) {
194194
skipPrefixes := map[string][][]byte{
195195
stakingtypes.StoreKey: {
196196
stakingtypes.UnbondingQueueKey, stakingtypes.RedelegationQueueKey, stakingtypes.ValidatorQueueKey,
197-
stakingtypes.HistoricalInfoKey, stakingtypes.UnbondingIDKey, stakingtypes.UnbondingIndexKey,
198-
stakingtypes.UnbondingTypeKey, stakingtypes.ValidatorUpdatesKey,
197+
stakingtypes.HistoricalInfoKey, stakingtypes.ValidatorUpdatesKey,
199198
},
200199
authzkeeper.StoreKey: {authzkeeper.GrantQueuePrefix},
201200
feegrant.StoreKey: {feegrant.FeeAllowanceQueueKeyPrefix},

tests/integration/staking/keeper/determinstic_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
464464
ValidatorAddr: validator.OperatorAddress,
465465
}
466466

467-
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorUnbondingDelegations, 3719, false)
467+
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorUnbondingDelegations, 3707, false)
468468
}
469469

470470
func TestGRPCDelegation(t *testing.T) {
@@ -536,7 +536,7 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
536536
DelegatorAddr: delegator1,
537537
}
538538

539-
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.UnbondingDelegation, 1621, false)
539+
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.UnbondingDelegation, 1615, false)
540540
}
541541

542542
func TestGRPCDelegatorDelegations(t *testing.T) {
@@ -647,7 +647,7 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
647647
DelegatorAddr: delegator1,
648648
}
649649

650-
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorUnbondingDelegations, 1302, false)
650+
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorUnbondingDelegations, 1290, false)
651651
}
652652

653653
func TestGRPCHistoricalInfo(t *testing.T) {

tests/integration/staking/keeper/msg_server_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func TestCancelUnbondingDelegation(t *testing.T) {
5555
delegatorAddr, validatorAddr, 10,
5656
ctx.BlockTime().Add(time.Minute*10),
5757
unbondingAmount.Amount,
58-
0,
5958
address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"),
6059
)
6160

tests/integration/staking/keeper/slash_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
6262
// set an unbonding delegation with expiration timestamp (beyond which the
6363
// unbonding delegation shouldn't be slashed)
6464
ubd := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 0,
65-
time.Unix(5, 0), math.NewInt(10), 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
65+
time.Unix(5, 0), math.NewInt(10), address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
6666

6767
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
6868

@@ -121,7 +121,7 @@ func TestSlashRedelegation(t *testing.T) {
121121
// set a redelegation with an expiration timestamp beyond which the
122122
// redelegation shouldn't be slashed
123123
rd := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 0,
124-
time.Unix(5, 0), math.NewInt(10), math.LegacyNewDec(10), 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
124+
time.Unix(5, 0), math.NewInt(10), math.LegacyNewDec(10), address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
125125

126126
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
127127

@@ -265,7 +265,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
265265
// set an unbonding delegation with expiration timestamp beyond which the
266266
// unbonding delegation shouldn't be slashed
267267
ubdTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 4)
268-
ubd := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 11, time.Unix(0, 0), ubdTokens, 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
268+
ubd := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 11, time.Unix(0, 0), ubdTokens, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
269269
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubd))
270270

271271
// slash validator for the first time
@@ -395,7 +395,7 @@ func TestSlashWithRedelegation(t *testing.T) {
395395

396396
// set a redelegation
397397
rdTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 6)
398-
rd := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdTokens, math.LegacyNewDecFromInt(rdTokens), 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
398+
rd := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdTokens, math.LegacyNewDecFromInt(rdTokens), address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
399399
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rd))
400400

401401
// set the associated delegation
@@ -553,7 +553,7 @@ func TestSlashBoth(t *testing.T) {
553553
// set a redelegation with expiration timestamp beyond which the
554554
// redelegation shouldn't be slashed
555555
rdATokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 6)
556-
rdA := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdATokens, math.LegacyNewDecFromInt(rdATokens), 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
556+
rdA := types.NewRedelegation(addrDels[0], addrVals[0], addrVals[1], 11, time.Unix(0, 0), rdATokens, math.LegacyNewDecFromInt(rdATokens), address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
557557
assert.NilError(t, f.stakingKeeper.SetRedelegation(f.sdkCtx, rdA))
558558

559559
// set the associated delegation
@@ -564,7 +564,7 @@ func TestSlashBoth(t *testing.T) {
564564
// unbonding delegation shouldn't be slashed)
565565
ubdATokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, 4)
566566
ubdA := types.NewUnbondingDelegation(addrDels[0], addrVals[0], 11,
567-
time.Unix(0, 0), ubdATokens, 0, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
567+
time.Unix(0, 0), ubdATokens, address.NewBech32Codec("cosmosvaloper"), address.NewBech32Codec("cosmos"))
568568
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(f.sdkCtx, ubdA))
569569

570570
bondedCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdATokens.MulRaw(2)))

x/staking/keeper/delegation.go

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,11 @@ func (k Keeper) SetUnbondingDelegationEntry(
425425
ctx context.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
426426
creationHeight int64, minTime time.Time, balance math.Int,
427427
) (types.UnbondingDelegation, error) {
428-
id, err := k.IncrementUnbondingID(ctx)
429-
if err != nil {
430-
return types.UnbondingDelegation{}, err
431-
}
432-
433-
isNewUbdEntry := true
434428
ubd, err := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
435429
if err == nil {
436-
isNewUbdEntry = ubd.AddEntry(creationHeight, minTime, balance, id)
430+
ubd.AddEntry(creationHeight, minTime, balance)
437431
} else if errors.Is(err, types.ErrNoUnbondingDelegation) {
438-
ubd = types.NewUnbondingDelegation(delegatorAddr, validatorAddr, creationHeight, minTime, balance, id, k.validatorAddressCodec, k.authKeeper.AddressCodec())
432+
ubd = types.NewUnbondingDelegation(delegatorAddr, validatorAddr, creationHeight, minTime, balance, k.validatorAddressCodec, k.authKeeper.AddressCodec())
439433
} else {
440434
return ubd, err
441435
}
@@ -444,18 +438,6 @@ func (k Keeper) SetUnbondingDelegationEntry(
444438
return ubd, err
445439
}
446440

447-
// only call the hook for new entries since
448-
// calls to AfterUnbondingInitiated are not idempotent
449-
if isNewUbdEntry {
450-
// Add to the UBDByUnbondingOp index to look up the UBD by the UBDE ID
451-
if err = k.SetUnbondingDelegationByUnbondingID(ctx, ubd, id); err != nil {
452-
return ubd, err
453-
}
454-
455-
if err := k.Hooks().AfterUnbondingInitiated(ctx, id); err != nil {
456-
k.Logger(ctx).Error("failed to call after unbonding initiated hook", "error", err)
457-
}
458-
}
459441
return ubd, nil
460442
}
461443

@@ -655,17 +637,12 @@ func (k Keeper) SetRedelegationEntry(ctx context.Context,
655637
minTime time.Time, balance math.Int,
656638
sharesSrc, sharesDst math.LegacyDec,
657639
) (types.Redelegation, error) {
658-
id, err := k.IncrementUnbondingID(ctx)
659-
if err != nil {
660-
return types.Redelegation{}, err
661-
}
662-
663640
red, err := k.GetRedelegation(ctx, delegatorAddr, validatorSrcAddr, validatorDstAddr)
664641
if err == nil {
665-
red.AddEntry(creationHeight, minTime, balance, sharesDst, id)
642+
red.AddEntry(creationHeight, minTime, balance, sharesDst)
666643
} else if errors.Is(err, types.ErrNoRedelegation) {
667644
red = types.NewRedelegation(delegatorAddr, validatorSrcAddr,
668-
validatorDstAddr, creationHeight, minTime, balance, sharesDst, id, k.validatorAddressCodec, k.authKeeper.AddressCodec())
645+
validatorDstAddr, creationHeight, minTime, balance, sharesDst, k.validatorAddressCodec, k.authKeeper.AddressCodec())
669646
} else {
670647
return types.Redelegation{}, err
671648
}
@@ -674,16 +651,6 @@ func (k Keeper) SetRedelegationEntry(ctx context.Context,
674651
return types.Redelegation{}, err
675652
}
676653

677-
// Add to the UBDByEntry index to look up the UBD by the UBDE ID
678-
if err = k.SetRedelegationByUnbondingID(ctx, red, id); err != nil {
679-
return types.Redelegation{}, err
680-
}
681-
682-
if err := k.Hooks().AfterUnbondingInitiated(ctx, id); err != nil {
683-
k.Logger(ctx).Error("failed to call after unbonding initiated hook", "error", err)
684-
// TODO (Facu): Should we return here? We are ignoring this error
685-
}
686-
687654
return red, nil
688655
}
689656

@@ -1124,12 +1091,9 @@ func (k Keeper) CompleteUnbonding(ctx context.Context, delAddr sdk.AccAddress, v
11241091
// loop through all the entries and complete unbonding mature entries
11251092
for i := 0; i < len(ubd.Entries); i++ {
11261093
entry := ubd.Entries[i]
1127-
if entry.IsMature(ctxTime) && !entry.OnHold() {
1094+
if entry.IsMature(ctxTime) {
11281095
ubd.RemoveEntry(int64(i))
11291096
i--
1130-
if err = k.DeleteUnbondingIndex(ctx, entry.UnbondingId); err != nil {
1131-
return nil, err
1132-
}
11331097

11341098
// track undelegation only when remaining or truncated shares are non-zero
11351099
if !entry.Balance.IsZero() {
@@ -1264,12 +1228,9 @@ func (k Keeper) CompleteRedelegation(
12641228
// loop through all the entries and complete mature redelegation entries
12651229
for i := 0; i < len(red.Entries); i++ {
12661230
entry := red.Entries[i]
1267-
if entry.IsMature(ctxTime) && !entry.OnHold() {
1231+
if entry.IsMature(ctxTime) {
12681232
red.RemoveEntry(int64(i))
12691233
i--
1270-
if err = k.DeleteUnbondingIndex(ctx, entry.UnbondingId); err != nil {
1271-
return nil, err
1272-
}
12731234

12741235
if !entry.InitialBalance.IsZero() {
12751236
balances = balances.Add(sdk.NewCoin(bondDenom, entry.InitialBalance))

0 commit comments

Comments
 (0)