Remove redundant staking APIs (#5755)
This commit is contained in:
parent
c5b2abd814
commit
88d01a9869
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue