From 88d01a986974b8bac818e195b55b8b9006b111d1 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Fri, 6 Mar 2020 08:40:50 -0500 Subject: [PATCH] Remove redundant staking APIs (#5755) --- x/slashing/handler_test.go | 9 ++++----- x/staking/keeper/delegation.go | 29 ++++++---------------------- x/staking/keeper/delegation_test.go | 4 ++-- x/staking/keeper/val_state_change.go | 4 ++-- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index 955eeadb8..0759dfdf9 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -6,16 +6,15 @@ import ( "testing" "time" - "github.com/cosmos/cosmos-sdk/x/slashing/types" - - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - "github.com/stretchr/testify/require" ) func TestCannotUnjailUnlessJailed(t *testing.T) { @@ -133,7 +132,7 @@ func TestJailedValidatorDelegations(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - err = app.StakingKeeper.CompleteUnbonding(ctx, sdk.AccAddress(valAddr), valAddr) + _, err = app.StakingKeeper.CompleteUnbonding(ctx, sdk.AccAddress(valAddr), valAddr) require.Nil(t, err, "expected complete unbonding validator to be ok, got: %v", err) // verify validator still exists and is jailed diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 8b61f8abb..e5c1912da 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -671,10 +671,10 @@ func (k Keeper) Undelegate( return completionTime, nil } -// CompleteUnbondingWithAmount completes the unbonding of all mature entries in -// the retrieved unbonding delegation object and returns the total unbonding -// balance or an error upon failure. -func (k Keeper) CompleteUnbondingWithAmount(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) { +// CompleteUnbonding completes the unbonding of all mature entries in the +// retrieved unbonding delegation object and returns the total unbonding balance +// or an error upon failure. +func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) { ubd, found := k.GetUnbondingDelegation(ctx, delAddr, valAddr) if !found { return nil, types.ErrNoUnbondingDelegation @@ -716,13 +716,6 @@ func (k Keeper) CompleteUnbondingWithAmount(ctx sdk.Context, delAddr sdk.AccAddr return balances, nil } -// CompleteUnbonding performs the same logic as CompleteUnbondingWithAmount except -// it does not return the total unbonding amount. -func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { - _, err := k.CompleteUnbondingWithAmount(ctx, delAddr, valAddr) - return err -} - // begin unbonding / redelegation; create a redelegation record func (k Keeper) BeginRedelegation( ctx sdk.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, sharesAmount sdk.Dec, @@ -780,10 +773,10 @@ func (k Keeper) BeginRedelegation( return completionTime, nil } -// CompleteRedelegationWithAmount completes the redelegations of all mature entries in the +// CompleteRedelegation completes the redelegations of all mature entries in the // retrieved redelegation object and returns the total redelegation (initial) // balance or an error upon failure. -func (k Keeper) CompleteRedelegationWithAmount( +func (k Keeper) CompleteRedelegation( ctx sdk.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, ) (sdk.Coins, error) { @@ -819,16 +812,6 @@ func (k Keeper) CompleteRedelegationWithAmount( return balances, nil } -// CompleteRedelegation performs the same logic as CompleteRedelegationWithAmount -// except it does not return the total redelegation amount. -func (k Keeper) CompleteRedelegation( - ctx sdk.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, -) error { - - _, err := k.CompleteRedelegationWithAmount(ctx, delAddr, valSrcAddr, valDstAddr) - return err -} - // ValidateUnbondAmount validates that a given unbond or redelegation amount is // valied based on upon the converted shares. If the amount is valid, the total // amount of respective shares is returned, otherwise an error is returned. diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index e1f7b7de2..b89d83536 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -282,7 +282,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) { // mature unbonding delegations ctx = ctx.WithBlockTime(completionTime) - err = app.StakingKeeper.CompleteUnbonding(ctx, addrDels[0], addrVals[0]) + _, err = app.StakingKeeper.CompleteUnbonding(ctx, addrDels[0], addrVals[0]) require.NoError(t, err) newBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount @@ -794,7 +794,7 @@ func TestRedelegationMaxEntries(t *testing.T) { // mature redelegations ctx = ctx.WithBlockTime(completionTime) - err = app.StakingKeeper.CompleteRedelegation(ctx, val0AccAddr, addrVals[0], addrVals[1]) + _, err = app.StakingKeeper.CompleteRedelegation(ctx, val0AccAddr, addrVals[0], addrVals[1]) require.NoError(t, err) // redelegation should work again diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index b5f05cf9a..9927d6ed2 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -32,7 +32,7 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate { // Remove all mature unbonding delegations from the ubd queue. matureUnbonds := k.DequeueAllMatureUBDQueue(ctx, ctx.BlockHeader().Time) for _, dvPair := range matureUnbonds { - balances, err := k.CompleteUnbondingWithAmount(ctx, dvPair.DelegatorAddress, dvPair.ValidatorAddress) + balances, err := k.CompleteUnbonding(ctx, dvPair.DelegatorAddress, dvPair.ValidatorAddress) if err != nil { continue } @@ -50,7 +50,7 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate { // Remove all mature redelegations from the red queue. matureRedelegations := k.DequeueAllMatureRedelegationQueue(ctx, ctx.BlockHeader().Time) for _, dvvTriplet := range matureRedelegations { - balances, err := k.CompleteRedelegationWithAmount( + balances, err := k.CompleteRedelegation( ctx, dvvTriplet.DelegatorAddress, dvvTriplet.ValidatorSrcAddress,