Use enum instead of int32 for BondStatus (#7499)
* Migrate staking module * Add gov legacy * Add comments * Add x/distrib * x/crisis * x/mint * Fix test * migrate x/genutil * Fix lint * Fix staking constants * Fix test * Update x/genutil/legacy/v040/migrate.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Add migrate script instead of change BondStatus constants * Change staking bondStatus to enum * Fix test * Fix another test * Remove staking exported * fix references * Better constants * Fix build * Fix lint * Remove buf version * Fix tests * Fix test Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
7474a19bb9
commit
33e7297c79
|
@ -65,6 +65,7 @@ older clients.
|
|||
* (server) [\#5982](https://github.com/cosmos/cosmos-sdk/pull/5982) `--pruning` now must be set to `custom` if you want to customise the granular options.
|
||||
* (x/gov) [\#7000](https://github.com/cosmos/cosmos-sdk/pull/7000) [\#6859](https://github.com/cosmos/cosmos-sdk/pull/6859) `ProposalStatus` and `VoteOption` are now JSON serialized using its protobuf name, so expect names like `PROPOSAL_STATUS_DEPOSIT_PERIOD` as opposed to `DepositPeriod`.
|
||||
* (x/auth/vesting) [\#6859](https://github.com/cosmos/cosmos-sdk/pull/6859) Custom JSON marshaling of vesting accounts was removed. Vesting accounts are now marshaled using their default proto or amino JSON representation.
|
||||
* (x/staking) [\#7499](https://github.com/cosmos/cosmos-sdk/pull/7499) `BondStatus` is now a protobuf `enum` instead of an `int32`, and JSON serialized using its protobuf name, so expect names like `BOND_STATUS_UNBONDING` as opposed to `Unbonding`.
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ message Validator {
|
|||
string operator_address = 1 [(gogoproto.moretags) = "yaml:\"operator_address\""];
|
||||
string consensus_pubkey = 2 [(gogoproto.moretags) = "yaml:\"consensus_pubkey\""];
|
||||
bool jailed = 3;
|
||||
int32 status = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.BondStatus"];
|
||||
BondStatus status = 4;
|
||||
string tokens = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
|
||||
string delegator_shares = 6 [
|
||||
(gogoproto.moretags) = "yaml:\"delegator_shares\"",
|
||||
|
@ -94,6 +94,20 @@ message Validator {
|
|||
];
|
||||
}
|
||||
|
||||
// BondStatus is the status of a validator.
|
||||
enum BondStatus {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
|
||||
// UNSPECIFIED defines an invalid validator status.
|
||||
BOND_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "Unspecified"];
|
||||
// UNBONDED defines a validator that is not bonded.
|
||||
BOND_STATUS_UNBONDED = 1 [(gogoproto.enumvalue_customname) = "Unbonded"];
|
||||
// UNBONDING defines a validator that is unbonding.
|
||||
BOND_STATUS_UNBONDING = 2 [(gogoproto.enumvalue_customname) = "Unbonding"];
|
||||
// BONDED defines a validator that is bonded.
|
||||
BOND_STATUS_BONDED = 3 [(gogoproto.enumvalue_customname) = "Bonded"];
|
||||
}
|
||||
|
||||
// ValAddresses defines a repeated set of validator addresses.
|
||||
message ValAddresses {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
@ -72,7 +71,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
|
|||
/* Handle fee distribution state. */
|
||||
|
||||
// withdraw all validator commission
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
|
||||
return false
|
||||
})
|
||||
|
@ -103,7 +102,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
|
|||
ctx = ctx.WithBlockHeight(0)
|
||||
|
||||
// reinitialize all validators
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
|
||||
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
|
||||
feePool := app.DistrKeeper.GetFeePool(ctx)
|
||||
|
|
|
@ -96,7 +96,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
|
|||
OperatorAddress: sdk.ValAddress(val.Address).String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, val.PubKey),
|
||||
Jailed: false,
|
||||
Status: sdk.Bonded,
|
||||
Status: stakingtypes.Bonded,
|
||||
Tokens: bondAmt,
|
||||
DelegatorShares: sdk.OneDec(),
|
||||
Description: stakingtypes.Description{},
|
||||
|
|
|
@ -34,39 +34,3 @@ func TokensToConsensusPower(tokens Int) int64 {
|
|||
func TokensFromConsensusPower(power int64) Int {
|
||||
return NewInt(power).Mul(PowerReduction)
|
||||
}
|
||||
|
||||
// BondStatus is the status of a validator
|
||||
type BondStatus int32
|
||||
|
||||
// staking constants
|
||||
const (
|
||||
Unbonded BondStatus = 1
|
||||
Unbonding BondStatus = 2
|
||||
Bonded BondStatus = 3
|
||||
|
||||
BondStatusUnbonded = "Unbonded"
|
||||
BondStatusUnbonding = "Unbonding"
|
||||
BondStatusBonded = "Bonded"
|
||||
)
|
||||
|
||||
// Equal compares two BondStatus instances
|
||||
func (b BondStatus) Equal(b2 BondStatus) bool {
|
||||
return byte(b) == byte(b2)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for BondStatus.
|
||||
func (b BondStatus) String() string {
|
||||
switch b {
|
||||
case Unbonded:
|
||||
return BondStatusUnbonded
|
||||
|
||||
case Unbonding:
|
||||
return BondStatusUnbonding
|
||||
|
||||
case Bonded:
|
||||
return BondStatusBonded
|
||||
|
||||
default:
|
||||
panic("invalid bond status")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,6 @@ func (s *stakingTestSuite) SetupSuite() {
|
|||
s.T().Parallel()
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) TestBondStatus() {
|
||||
s.Require().False(sdk.Unbonded.Equal(sdk.Bonded))
|
||||
s.Require().False(sdk.Unbonded.Equal(sdk.Unbonding))
|
||||
s.Require().False(sdk.Bonded.Equal(sdk.Unbonding))
|
||||
s.Require().Panicsf(func() { sdk.BondStatus(0).String() }, "invalid bond status") // nolint:govet
|
||||
s.Require().Equal(sdk.BondStatusUnbonded, sdk.Unbonded.String())
|
||||
s.Require().Equal(sdk.BondStatusBonded, sdk.Bonded.String())
|
||||
s.Require().Equal(sdk.BondStatusUnbonding, sdk.Unbonding.String())
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) TestTokensToConsensusPower() {
|
||||
s.Require().Equal(int64(0), sdk.TokensToConsensusPower(sdk.NewInt(999_999)))
|
||||
s.Require().Equal(int64(1), sdk.TokensToConsensusPower(sdk.NewInt(1_000_000)))
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// AllocateTokens handles distribution of the collected fees
|
||||
|
@ -100,7 +100,7 @@ func (k Keeper) AllocateTokens(
|
|||
}
|
||||
|
||||
// AllocateTokensToValidator allocate tokens to a particular validator, splitting according to commission
|
||||
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val exported.ValidatorI, tokens sdk.DecCoins) {
|
||||
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) {
|
||||
// split tokens between validator and delegators according to commission
|
||||
commission := tokens.MulDec(val.GetCommission())
|
||||
shared := tokens.Sub(commission)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// initialize starting info for a new delegation
|
||||
|
@ -28,7 +28,7 @@ func (k Keeper) initializeDelegation(ctx sdk.Context, val sdk.ValAddress, del sd
|
|||
}
|
||||
|
||||
// calculate the rewards accrued by a delegation between two periods
|
||||
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val exported.ValidatorI,
|
||||
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val stakingtypes.ValidatorI,
|
||||
startingPeriod, endingPeriod uint64, stake sdk.Dec) (rewards sdk.DecCoins) {
|
||||
// sanity check
|
||||
if startingPeriod > endingPeriod {
|
||||
|
@ -53,7 +53,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val exported.
|
|||
}
|
||||
|
||||
// calculate the total rewards accrued by a delegation
|
||||
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val exported.ValidatorI, del exported.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
|
||||
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
|
||||
// fetch starting info for delegation
|
||||
startingInfo := k.GetDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr())
|
||||
|
||||
|
@ -136,7 +136,7 @@ func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val exported.Validat
|
|||
return rewards
|
||||
}
|
||||
|
||||
func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val exported.ValidatorI, del exported.DelegationI) (sdk.Coins, error) {
|
||||
func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI) (sdk.Coins, error) {
|
||||
// check existence of delegator starting info
|
||||
if !k.HasDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) {
|
||||
return nil, types.ErrEmptyDelegationDistInfo
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
|
@ -178,7 +178,7 @@ func (k Keeper) DelegationTotalRewards(c context.Context, req *types.QueryDelega
|
|||
|
||||
k.stakingKeeper.IterateDelegations(
|
||||
ctx, delAdr,
|
||||
func(_ int64, del exported.DelegationI) (stop bool) {
|
||||
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
|
||||
valAddr := del.GetValidatorAddr()
|
||||
val := k.stakingKeeper.Validator(ctx, valAddr)
|
||||
endingPeriod := k.IncrementValidatorPeriod(ctx, val)
|
||||
|
@ -212,7 +212,7 @@ func (k Keeper) DelegatorValidators(c context.Context, req *types.QueryDelegator
|
|||
|
||||
k.stakingKeeper.IterateDelegations(
|
||||
ctx, delAdr,
|
||||
func(_ int64, del exported.DelegationI) (stop bool) {
|
||||
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
|
||||
validators = append(validators, del.GetValidatorAddr().String())
|
||||
return false
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// register all distribution invariants
|
||||
|
@ -77,7 +77,7 @@ func CanWithdrawInvariant(k Keeper) sdk.Invariant {
|
|||
}
|
||||
|
||||
// iterate over all validators
|
||||
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
|
||||
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
_, _ = k.WithdrawValidatorCommission(ctx, val.GetOperator())
|
||||
|
||||
delegationAddrs, ok := valDelegationAddrs[val.GetOperator().String()]
|
||||
|
@ -108,7 +108,7 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant {
|
|||
return func(ctx sdk.Context) (string, bool) {
|
||||
|
||||
valCount := uint64(0)
|
||||
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
|
||||
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
valCount++
|
||||
return false
|
||||
})
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
||||
|
@ -172,7 +172,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue
|
|||
|
||||
k.stakingKeeper.IterateDelegations(
|
||||
ctx, params.DelegatorAddress,
|
||||
func(_ int64, del exported.DelegationI) (stop bool) {
|
||||
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
|
||||
valAddr := del.GetValidatorAddr()
|
||||
val := k.stakingKeeper.Validator(ctx, valAddr)
|
||||
endingPeriod := k.IncrementValidatorPeriod(ctx, val)
|
||||
|
@ -208,7 +208,7 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery
|
|||
|
||||
k.stakingKeeper.IterateDelegations(
|
||||
ctx, params.DelegatorAddress,
|
||||
func(_ int64, del exported.DelegationI) (stop bool) {
|
||||
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
|
||||
validators = append(validators, del.GetValidatorAddr())
|
||||
return false
|
||||
},
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// initialize rewards for a new validator
|
||||
func (k Keeper) initializeValidator(ctx sdk.Context, val exported.ValidatorI) {
|
||||
func (k Keeper) initializeValidator(ctx sdk.Context, val stakingtypes.ValidatorI) {
|
||||
// set initial historical rewards (period 0) with reference count of 1
|
||||
k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), 0, types.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
|
||||
|
||||
|
@ -25,7 +25,7 @@ func (k Keeper) initializeValidator(ctx sdk.Context, val exported.ValidatorI) {
|
|||
}
|
||||
|
||||
// increment validator period, returning the period just ended
|
||||
func (k Keeper) IncrementValidatorPeriod(ctx sdk.Context, val exported.ValidatorI) uint64 {
|
||||
func (k Keeper) IncrementValidatorPeriod(ctx sdk.Context, val stakingtypes.ValidatorI) uint64 {
|
||||
// fetch current rewards
|
||||
rewards := k.GetValidatorCurrentRewards(ctx, val.GetOperator())
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package types
|
|||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
@ -35,18 +34,18 @@ type BankKeeper interface {
|
|||
type StakingKeeper interface {
|
||||
// iterate through validators by operator address, execute func for each validator
|
||||
IterateValidators(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
|
||||
|
||||
// iterate through bonded validators by operator address, execute func for each validator
|
||||
IterateBondedValidatorsByPower(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
|
||||
|
||||
// iterate through the consensus validator set of the last block by operator address, execute func for each validator
|
||||
IterateLastValidators(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
|
||||
|
||||
Validator(sdk.Context, sdk.ValAddress) stakingexported.ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI // get a particular validator by consensus address
|
||||
Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address
|
||||
|
||||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
||||
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
|
||||
|
@ -55,13 +54,13 @@ type StakingKeeper interface {
|
|||
|
||||
// Delegation allows for getting a particular delegation for a given validator
|
||||
// and delegator outside the scope of the staking module.
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingtypes.DelegationI
|
||||
|
||||
// MaxValidators returns the maximum amount of bonded validators
|
||||
MaxValidators(sdk.Context) uint32
|
||||
|
||||
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
|
||||
fn func(index int64, delegation stakingtypes.DelegationI) (stop bool))
|
||||
|
||||
GetLastTotalPower(ctx sdk.Context) sdk.Int
|
||||
GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) int64
|
||||
|
|
|
@ -6,14 +6,14 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
type (
|
||||
// StakingKeeper defines the staking module interface contract needed by the
|
||||
// evidence module.
|
||||
StakingKeeper interface {
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI
|
||||
}
|
||||
|
||||
// SlashingKeeper defines the slashing module interface contract needed by the
|
||||
|
|
|
@ -41,9 +41,9 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd
|
|||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2)
|
||||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3)
|
||||
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), sdk.Unbonded, val1, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), sdk.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), sdk.Unbonded, val3, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), stakingtypes.Unbonded, val1, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), stakingtypes.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), stakingtypes.Unbonded, val3, true)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package keeper
|
|||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// TODO: Break into several smaller functions for clarity
|
||||
|
@ -21,7 +21,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
|
|||
currValidators := make(map[string]types.ValidatorGovInfo)
|
||||
|
||||
// fetch all the bonded validators, insert them into currValidators
|
||||
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator exported.ValidatorI) (stop bool) {
|
||||
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
|
||||
currValidators[validator.GetOperator().String()] = types.NewValidatorGovInfo(
|
||||
validator.GetOperator(),
|
||||
validator.GetBondedTokens(),
|
||||
|
@ -48,7 +48,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
|
|||
}
|
||||
|
||||
// iterate over all delegations from voter, deduct from any delegated-to validators
|
||||
keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation exported.DelegationI) (stop bool) {
|
||||
keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation stakingtypes.DelegationI) (stop bool) {
|
||||
valAddrStr := delegation.GetValidatorAddr().String()
|
||||
|
||||
if val, ok := currValidators[valAddrStr]; ok {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func TestTallyNoOneVotes(t *testing.T) {
|
||||
|
@ -248,7 +249,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
|
|||
val1, found := app.StakingKeeper.GetValidator(ctx, valAddrs[0])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[4], delTokens, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[4], delTokens, stakingtypes.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -284,7 +285,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
|
|||
val3, found := app.StakingKeeper.GetValidator(ctx, vals[2])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val3, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -321,9 +322,9 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
|||
val2, found := app.StakingKeeper.GetValidator(ctx, vals[1])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val2, true)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -363,9 +364,9 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
|||
val3, found := app.StakingKeeper.GetValidator(ctx, vals[2])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val2, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val3, true)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -402,9 +403,9 @@ func TestTallyJailedValidator(t *testing.T) {
|
|||
val3, found := app.StakingKeeper.GetValidator(ctx, valAddrs[2])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val2, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val3, true)
|
||||
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
@ -441,7 +442,7 @@ func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
|||
val2, found := app.StakingKeeper.GetValidator(ctx, valAddrs[1])
|
||||
require.True(t, found)
|
||||
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrs[0], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
tp := TestProposal
|
||||
|
|
|
@ -3,7 +3,7 @@ package types
|
|||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// ParamSubspace defines the expected Subspace interface for parameters (noalias)
|
||||
|
@ -16,13 +16,13 @@ type ParamSubspace interface {
|
|||
type StakingKeeper interface {
|
||||
// iterate through bonded validators by operator address, execute func for each validator
|
||||
IterateBondedValidatorsByPower(
|
||||
sdk.Context, func(index int64, validator stakingexported.ValidatorI) (stop bool),
|
||||
sdk.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool),
|
||||
)
|
||||
|
||||
TotalBondedTokens(sdk.Context) sdk.Int // total bonded tokens within the validator set
|
||||
IterateDelegations(
|
||||
ctx sdk.Context, delegator sdk.AccAddress,
|
||||
fn func(index int64, delegation stakingexported.DelegationI) (stop bool),
|
||||
fn func(index int64, delegation stakingtypes.DelegationI) (stop bool),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
|||
pk, err := privVal.GetPubKey()
|
||||
suite.Require().NoError(err)
|
||||
val := stakingtypes.NewValidator(sdk.ValAddress(pk.Address()), pk, stakingtypes.Description{})
|
||||
val.Status = sdk.Bonded
|
||||
val.Status = stakingtypes.Bonded
|
||||
val.Tokens = sdk.NewInt(rand.Int63())
|
||||
validators = append(validators, val)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func TestBeginBlocker(t *testing.T) {
|
||||
|
@ -100,5 +101,5 @@ func TestBeginBlocker(t *testing.T) {
|
|||
// validator should be jailed
|
||||
validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk))
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func TestSlashingMsgs(t *testing.T) {
|
|||
|
||||
validator := checkValidator(t, app, addr1, true)
|
||||
require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
||||
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(addr1).String()}
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// InitGenesis initialize default parameters
|
||||
// and the keeper's address to pubkey map
|
||||
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
|
||||
stakingKeeper.IterateValidators(ctx,
|
||||
func(index int64, validator exported.ValidatorI) bool {
|
||||
func(index int64, validator stakingtypes.ValidatorI) bool {
|
||||
keeper.AddPubkey(ctx, validator.GetConsPubKey())
|
||||
return false
|
||||
},
|
||||
|
|
|
@ -231,7 +231,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
|
||||
// validator should be bonded still
|
||||
validator, _ := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
|
||||
bondPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
require.True(sdk.IntEq(t, amt, app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount))
|
||||
|
@ -250,7 +250,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
|
||||
// validator should have been jailed
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
|
||||
slashAmt := amt.ToDec().Mul(app.SlashingKeeper.SlashFractionDowntime(ctx)).RoundInt64()
|
||||
|
||||
|
@ -289,7 +289,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
|
||||
// validator should be rebonded now
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
require.Equal(t, amt.Int64()-slashAmt, app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount.Int64())
|
||||
|
@ -306,7 +306,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
ctx = ctx.WithBlockHeight(height)
|
||||
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), power, false)
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
|
||||
// 500 signed blocks
|
||||
nextHeight := height + app.SlashingKeeper.MinSignedPerWindow(ctx) + 1
|
||||
|
@ -329,5 +329,5 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func TestUnJailNotBonded(t *testing.T) {
|
|||
validator, ok := app.StakingKeeper.GetValidator(ctx, addr)
|
||||
require.True(t, ok)
|
||||
require.False(t, validator.Jailed)
|
||||
require.Equal(t, sdk.BondStatusUnbonded, validator.GetStatus().String())
|
||||
require.Equal(t, stakingtypes.BondStatusUnbonded, validator.GetStatus().String())
|
||||
|
||||
// unbond below minimum self-delegation
|
||||
msgUnbond := stakingtypes.NewMsgUndelegate(sdk.AccAddress(addr), addr, sdk.NewCoin(p.BondDenom, sdk.TokensFromConsensusPower(1)))
|
||||
|
@ -137,7 +137,7 @@ func TestHandleNewValidator(t *testing.T) {
|
|||
|
||||
// validator should be bonded still, should not have been jailed or slashed
|
||||
validator, _ := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Bonded, validator.GetStatus())
|
||||
bondPool := app.StakingKeeper.GetBondedPool(ctx)
|
||||
expTokens := sdk.TokensFromConsensusPower(100)
|
||||
require.Equal(t, expTokens.Int64(), app.BankKeeper.GetBalance(ctx, bondPool.GetAddress(), app.StakingKeeper.BondDenom(ctx)).Amount.Int64())
|
||||
|
@ -182,7 +182,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
|||
|
||||
// validator should have been jailed and slashed
|
||||
validator, _ := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
resultingTokens := amt.Sub(sdk.TokensFromConsensusPower(1))
|
||||
|
@ -242,7 +242,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
validatorUpdates := staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
require.Equal(t, 2, len(validatorUpdates))
|
||||
validator, _ := app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.Status)
|
||||
|
||||
// 600 more blocks happened
|
||||
height = int64(700)
|
||||
|
@ -257,7 +257,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
validatorUpdates = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
require.Equal(t, 2, len(validatorUpdates))
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
||||
newPower := int64(150)
|
||||
|
||||
// validator misses a block
|
||||
|
@ -266,7 +266,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
|
||||
// shouldn't be jailed/kicked yet
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
||||
|
||||
// validator misses 500 more blocks, 501 total
|
||||
latest := height
|
||||
|
@ -278,7 +278,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
// should now be jailed & kicked
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.Status)
|
||||
|
||||
// check all the signing information
|
||||
signInfo, found := app.SlashingKeeper.GetValidatorSigningInfo(ctx, consAddr)
|
||||
|
@ -303,7 +303,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
// validator should not be kicked since we reset counter/array when it was jailed
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
||||
|
||||
// validator misses 501 blocks
|
||||
latest = height
|
||||
|
@ -315,6 +315,5 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
|||
// validator should now be jailed & kicked
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addr))
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
|
||||
require.Equal(t, stakingtypes.Unbonding, validator.Status)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// AccountKeeper expected account keeper
|
||||
|
@ -37,10 +37,10 @@ type ParamSubspace interface {
|
|||
type StakingKeeper interface {
|
||||
// iterate through validators by operator address, execute func for each validator
|
||||
IterateValidators(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
|
||||
|
||||
Validator(sdk.Context, sdk.ValAddress) stakingexported.ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI // get a particular validator by consensus address
|
||||
Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address
|
||||
|
||||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
||||
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
|
||||
|
@ -49,7 +49,7 @@ type StakingKeeper interface {
|
|||
|
||||
// Delegation allows for getting a particular delegation for a given validator
|
||||
// and delegator outside the scope of the staking module.
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingtypes.DelegationI
|
||||
|
||||
// MaxValidators returns the maximum amount of bonded validators
|
||||
MaxValidators(sdk.Context) uint32
|
||||
|
|
|
@ -80,7 +80,7 @@ func TestStakingMsgs(t *testing.T) {
|
|||
|
||||
validator := checkValidator(t, app, sdk.ValAddress(addr1), true)
|
||||
require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
|
||||
header = tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
|
|
|
@ -83,7 +83,7 @@ func (s *IntegrationTestSuite) TestQueryValidatorsGRPCHandler() {
|
|||
},
|
||||
{
|
||||
"test query validators gRPC route with valid status",
|
||||
fmt.Sprintf("%s/cosmos/staking/v1beta1/validators?status=%s", baseURL, sdk.Bonded.String()),
|
||||
fmt.Sprintf("%s/cosmos/staking/v1beta1/validators?status=%s", baseURL, types.Bonded.String()),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ func validatorsHandlerFn(clientCtx client.Context) http.HandlerFunc {
|
|||
|
||||
status := r.FormValue("status")
|
||||
if status == "" {
|
||||
status = sdk.BondStatusBonded
|
||||
status = types.BondStatusBonded
|
||||
}
|
||||
|
||||
params := types.NewQueryValidatorsParams(page, limit, status)
|
||||
|
|
|
@ -1,38 +1 @@
|
|||
package exported
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// DelegationI delegation bond for a delegated proof of stake system
|
||||
type DelegationI interface {
|
||||
GetDelegatorAddr() sdk.AccAddress // delegator sdk.AccAddress for the bond
|
||||
GetValidatorAddr() sdk.ValAddress // validator operator address
|
||||
GetShares() sdk.Dec // amount of validator's shares held in this delegation
|
||||
}
|
||||
|
||||
// ValidatorI expected validator functions
|
||||
type ValidatorI interface {
|
||||
IsJailed() bool // whether the validator is jailed
|
||||
GetMoniker() string // moniker of the validator
|
||||
GetStatus() sdk.BondStatus // status of the validator
|
||||
IsBonded() bool // check if has a bonded status
|
||||
IsUnbonded() bool // check if has status unbonded
|
||||
IsUnbonding() bool // check if has status unbonding
|
||||
GetOperator() sdk.ValAddress // operator address to receive/return validators coins
|
||||
GetConsPubKey() crypto.PubKey // validation consensus pubkey
|
||||
GetConsAddr() sdk.ConsAddress // validation consensus address
|
||||
GetTokens() sdk.Int // validation tokens
|
||||
GetBondedTokens() sdk.Int // validator bonded tokens
|
||||
GetConsensusPower() int64 // validation power in tendermint
|
||||
GetCommission() sdk.Dec // validator commission rate
|
||||
GetMinSelfDelegation() sdk.Int // validator minimum self delegation
|
||||
GetDelegatorShares() sdk.Dec // total outstanding delegator shares
|
||||
TokensFromShares(sdk.Dec) sdk.Dec // token worth of provided delegator shares
|
||||
TokensFromSharesTruncated(sdk.Dec) sdk.Dec // token worth of provided delegator shares, truncated
|
||||
TokensFromSharesRoundUp(sdk.Dec) sdk.Dec // token worth of provided delegator shares, rounded up
|
||||
SharesFromTokens(amt sdk.Int) (sdk.Dec, error) // shares worth of delegator's bond
|
||||
SharesFromTokensTruncated(amt sdk.Int) (sdk.Dec, error) // truncated shares worth of delegator's bond
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
@ -52,9 +51,9 @@ func InitGenesis(
|
|||
}
|
||||
|
||||
switch validator.GetStatus() {
|
||||
case sdk.Bonded:
|
||||
case types.Bonded:
|
||||
bondedTokens = bondedTokens.Add(validator.GetTokens())
|
||||
case sdk.Unbonding, sdk.Unbonded:
|
||||
case types.Unbonding, types.Unbonded:
|
||||
notBondedTokens = notBondedTokens.Add(validator.GetTokens())
|
||||
default:
|
||||
panic("invalid validator status")
|
||||
|
@ -192,7 +191,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
|
|||
|
||||
// WriteValidators returns a slice of bonded genesis validators.
|
||||
func WriteValidators(ctx sdk.Context, keeper keeper.Keeper) (vals []tmtypes.GenesisValidator) {
|
||||
keeper.IterateLastValidators(ctx, func(_ int64, validator exported.ValidatorI) (stop bool) {
|
||||
keeper.IterateLastValidators(ctx, func(_ int64, validator types.ValidatorI) (stop bool) {
|
||||
vals = append(vals, tmtypes.GenesisValidator{
|
||||
Address: validator.GetConsAddr().Bytes(),
|
||||
PubKey: validator.GetConsPubKey(),
|
||||
|
|
|
@ -53,13 +53,13 @@ func TestInitGenesis(t *testing.T) {
|
|||
validators[0].OperatorAddress = sdk.ValAddress(addrs[0]).String()
|
||||
validators[0].ConsensusPubkey = pk0
|
||||
validators[0].Description = types.NewDescription("hoop", "", "", "", "")
|
||||
validators[0].Status = sdk.Bonded
|
||||
validators[0].Status = types.Bonded
|
||||
validators[0].Tokens = valTokens
|
||||
validators[0].DelegatorShares = valTokens.ToDec()
|
||||
validators[1].OperatorAddress = sdk.ValAddress(addrs[1]).String()
|
||||
validators[1].ConsensusPubkey = pk1
|
||||
validators[1].Description = types.NewDescription("bloop", "", "", "", "")
|
||||
validators[1].Status = sdk.Bonded
|
||||
validators[1].Status = types.Bonded
|
||||
validators[1].Tokens = valTokens
|
||||
validators[1].DelegatorShares = valTokens.ToDec()
|
||||
|
||||
|
@ -79,11 +79,11 @@ func TestInitGenesis(t *testing.T) {
|
|||
// now make sure the validators are bonded and intra-tx counters are correct
|
||||
resVal, found := app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addrs[0]))
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, resVal.Status)
|
||||
require.Equal(t, types.Bonded, resVal.Status)
|
||||
|
||||
resVal, found = app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addrs[1]))
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, resVal.Status)
|
||||
require.Equal(t, types.Bonded, resVal.Status)
|
||||
|
||||
abcivals := make([]abci.ValidatorUpdate, len(vals))
|
||||
for i, val := range validators {
|
||||
|
@ -107,7 +107,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
|||
validators[i] = types.NewValidator(sdk.ValAddress(addrs[i]),
|
||||
PKs[i], types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""))
|
||||
|
||||
validators[i].Status = sdk.Bonded
|
||||
validators[i].Status = types.Bonded
|
||||
|
||||
tokens := sdk.TokensFromConsensusPower(1)
|
||||
if i < 100 {
|
||||
|
@ -153,7 +153,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
{"jailed and bonded validator", func(data *types.GenesisState) {
|
||||
data.Validators = genValidators1
|
||||
data.Validators[0].Jailed = true
|
||||
data.Validators[0].Status = sdk.Bonded
|
||||
data.Validators[0].Status = types.Bonded
|
||||
}, true},
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k
|
|||
// move coins from the msg.Address account to a (self-delegation) delegator account
|
||||
// the validator account and global shares are updated within here
|
||||
// NOTE source will always be from a wallet which are unbonded
|
||||
_, err = k.Delegate(ctx, delegatorAddress, msg.Value.Amount, sdk.Unbonded, validator, true)
|
||||
_, err = k.Delegate(ctx, delegatorAddress, msg.Value.Amount, types.Unbonded, validator, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ func handleMsgDelegate(ctx sdk.Context, msg *types.MsgDelegate, k keeper.Keeper)
|
|||
}
|
||||
|
||||
// NOTE: source funds are always unbonded
|
||||
_, err = k.Delegate(ctx, delegatorAddress, msg.Amount.Amount, sdk.Unbonded, validator, true)
|
||||
_, err = k.Delegate(ctx, delegatorAddress, msg.Amount.Amount, types.Unbonded, validator, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestValidatorByPowerIndex(t *testing.T) {
|
|||
|
||||
validator, found = app.StakingKeeper.GetValidator(ctx, validatorAddr)
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Unbonding, validator.Status) // ensure is unbonding
|
||||
require.Equal(t, types.Unbonding, validator.Status) // ensure is unbonding
|
||||
require.Equal(t, initBond.QuoRaw(2), validator.Tokens) // ensure tokens slashed
|
||||
app.StakingKeeper.Unjail(ctx, consAddr0)
|
||||
|
||||
|
@ -152,7 +152,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
|||
|
||||
validator, found := app.StakingKeeper.GetValidator(ctx, addr1)
|
||||
require.True(t, found)
|
||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||
assert.Equal(t, types.Bonded, validator.Status)
|
||||
assert.Equal(t, addr1.String(), validator.OperatorAddress)
|
||||
assert.Equal(t, pk1.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
|
||||
assert.Equal(t, valTokens, validator.BondedTokens())
|
||||
|
@ -184,7 +184,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
|||
validator, found = app.StakingKeeper.GetValidator(ctx, addr2)
|
||||
|
||||
require.True(t, found)
|
||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||
assert.Equal(t, types.Bonded, validator.Status)
|
||||
assert.Equal(t, addr2.String(), validator.OperatorAddress)
|
||||
assert.Equal(t, pk2.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
|
||||
assert.True(sdk.IntEq(t, valTokens, validator.Tokens))
|
||||
|
@ -231,7 +231,7 @@ func TestLegacyValidatorDelegations(t *testing.T) {
|
|||
// verify the validator exists and has the correct attributes
|
||||
validator, found := app.StakingKeeper.GetValidator(ctx, valAddr)
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
require.Equal(t, bondAmount, validator.DelegatorShares.RoundInt())
|
||||
require.Equal(t, bondAmount, validator.BondedTokens())
|
||||
|
||||
|
@ -332,7 +332,7 @@ func TestIncrementsMsgDelegate(t *testing.T) {
|
|||
|
||||
validator, found := app.StakingKeeper.GetValidator(ctx, validatorAddr)
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
require.Equal(t, bondAmount, validator.DelegatorShares.RoundInt())
|
||||
require.Equal(t, bondAmount, validator.BondedTokens(), "validator: %v", validator)
|
||||
|
||||
|
@ -1318,7 +1318,7 @@ func TestUnbondingWhenExcessValidators(t *testing.T) {
|
|||
require.Equal(t, 2, len(vals), "vals %v", vals)
|
||||
val1, found := app.StakingKeeper.GetValidator(ctx, validatorAddr1)
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, val1.Status, "%v", val1)
|
||||
require.Equal(t, types.Bonded, val1.Status, "%v", val1)
|
||||
}
|
||||
|
||||
func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
|
||||
|
@ -1426,7 +1426,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
|
|||
// validator power should have been reduced to zero
|
||||
// validator should be in unbonding state
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, valA)
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
}
|
||||
|
||||
func TestInvalidMsg(t *testing.T) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
@ -12,7 +11,7 @@ import (
|
|||
// Validator Set
|
||||
|
||||
// iterate through the validator set and perform the provided function
|
||||
func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validator exported.ValidatorI) (stop bool)) {
|
||||
func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(store, types.ValidatorsKey)
|
||||
|
@ -32,7 +31,7 @@ func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validato
|
|||
}
|
||||
|
||||
// iterate through the bonded validator set and perform the provided function
|
||||
func (k Keeper) IterateBondedValidatorsByPower(ctx sdk.Context, fn func(index int64, validator exported.ValidatorI) (stop bool)) {
|
||||
func (k Keeper) IterateBondedValidatorsByPower(ctx sdk.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
maxValidators := k.MaxValidators(ctx)
|
||||
|
||||
|
@ -55,7 +54,7 @@ func (k Keeper) IterateBondedValidatorsByPower(ctx sdk.Context, fn func(index in
|
|||
}
|
||||
|
||||
// iterate through the active validator set and perform the provided function
|
||||
func (k Keeper) IterateLastValidators(ctx sdk.Context, fn func(index int64, validator exported.ValidatorI) (stop bool)) {
|
||||
func (k Keeper) IterateLastValidators(ctx sdk.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) {
|
||||
iterator := k.LastValidatorsIterator(ctx)
|
||||
defer iterator.Close()
|
||||
|
||||
|
@ -78,7 +77,7 @@ func (k Keeper) IterateLastValidators(ctx sdk.Context, fn func(index int64, vali
|
|||
}
|
||||
|
||||
// Validator gets the Validator interface for a particular address
|
||||
func (k Keeper) Validator(ctx sdk.Context, address sdk.ValAddress) exported.ValidatorI {
|
||||
func (k Keeper) Validator(ctx sdk.Context, address sdk.ValAddress) types.ValidatorI {
|
||||
val, found := k.GetValidator(ctx, address)
|
||||
if !found {
|
||||
return nil
|
||||
|
@ -88,7 +87,7 @@ func (k Keeper) Validator(ctx sdk.Context, address sdk.ValAddress) exported.Vali
|
|||
}
|
||||
|
||||
// ValidatorByConsAddr gets the validator interface for a particular pubkey
|
||||
func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) exported.ValidatorI {
|
||||
func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) types.ValidatorI {
|
||||
val, found := k.GetValidatorByConsAddr(ctx, addr)
|
||||
if !found {
|
||||
return nil
|
||||
|
@ -106,7 +105,7 @@ func (k Keeper) GetValidatorSet() types.ValidatorSet {
|
|||
}
|
||||
|
||||
// Delegation get the delegation interface for a particular set of delegator and validator addresses
|
||||
func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) exported.DelegationI {
|
||||
func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) types.DelegationI {
|
||||
bond, ok := k.GetDelegation(ctx, addrDel, addrVal)
|
||||
if !ok {
|
||||
return nil
|
||||
|
@ -117,7 +116,7 @@ func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.
|
|||
|
||||
// iterate through all of the delegations from a delegator
|
||||
func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
fn func(index int64, del exported.DelegationI) (stop bool)) {
|
||||
fn func(index int64, del types.DelegationI) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := types.GetDelegationsKey(delAddr)
|
||||
|
||||
|
|
|
@ -545,7 +545,7 @@ func (k Keeper) DequeueAllMatureRedelegationQueue(ctx sdk.Context, currTime time
|
|||
// Delegate performs a delegation, set/update everything necessary within the store.
|
||||
// tokenSrc indicates the bond status of the incoming funds.
|
||||
func (k Keeper) Delegate(
|
||||
ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Int, tokenSrc sdk.BondStatus,
|
||||
ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Int, tokenSrc types.BondStatus,
|
||||
validator types.Validator, subtractAccount bool,
|
||||
) (newShares sdk.Dec, err error) {
|
||||
// In some situations, the exchange rate becomes invalid, e.g. if
|
||||
|
@ -577,7 +577,7 @@ func (k Keeper) Delegate(
|
|||
// performing a delegation and not a redelegation, thus the source tokens are
|
||||
// all non bonded
|
||||
if subtractAccount {
|
||||
if tokenSrc == sdk.Bonded {
|
||||
if tokenSrc == types.Bonded {
|
||||
panic("delegation token source cannot be bonded")
|
||||
}
|
||||
|
||||
|
@ -599,14 +599,14 @@ func (k Keeper) Delegate(
|
|||
} else {
|
||||
// potentially transfer tokens between pools, if
|
||||
switch {
|
||||
case tokenSrc == sdk.Bonded && validator.IsBonded():
|
||||
case tokenSrc == types.Bonded && validator.IsBonded():
|
||||
// do nothing
|
||||
case (tokenSrc == sdk.Unbonded || tokenSrc == sdk.Unbonding) && !validator.IsBonded():
|
||||
case (tokenSrc == types.Unbonded || tokenSrc == types.Unbonding) && !validator.IsBonded():
|
||||
// do nothing
|
||||
case (tokenSrc == sdk.Unbonded || tokenSrc == sdk.Unbonding) && validator.IsBonded():
|
||||
case (tokenSrc == types.Unbonded || tokenSrc == types.Unbonding) && validator.IsBonded():
|
||||
// transfer pools
|
||||
k.notBondedTokensToBonded(ctx, bondAmt)
|
||||
case tokenSrc == sdk.Bonded && !validator.IsBonded():
|
||||
case tokenSrc == types.Bonded && !validator.IsBonded():
|
||||
// transfer pools
|
||||
k.bondedTokensToNotBonded(ctx, bondAmt)
|
||||
default:
|
||||
|
|
|
@ -367,7 +367,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
|
|||
validator, found := app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.TokensFromConsensusPower(14), validator.Tokens)
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
require.Equal(t, types.Unbonding, validator.Status)
|
||||
require.True(t, validator.Jailed)
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) {
|
|||
// Make sure validator is still in state because there is still an outstanding delegation
|
||||
validator, found = app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
require.True(t, found)
|
||||
require.Equal(t, validator.Status, sdk.Unbonded)
|
||||
require.Equal(t, validator.Status, types.Unbonded)
|
||||
|
||||
// unbond some of the other delegation's shares
|
||||
unbondTokens := sdk.TokensFromConsensusPower(6)
|
||||
|
@ -615,7 +615,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
|
|||
// validator should still be in state and still be in unbonding state
|
||||
validator, found := app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
require.True(t, found)
|
||||
require.Equal(t, validator.Status, sdk.Unbonding)
|
||||
require.Equal(t, validator.Status, types.Unbonding)
|
||||
|
||||
// unbond the validator
|
||||
ctx = ctx.WithBlockTime(validator.UnbondingTime)
|
||||
|
@ -780,7 +780,7 @@ func TestRedelegationMaxEntries(t *testing.T) {
|
|||
require.Equal(t, valTokens, issuedShares.RoundInt())
|
||||
|
||||
validator2 = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator2, true)
|
||||
require.Equal(t, sdk.Bonded, validator2.Status)
|
||||
require.Equal(t, types.Bonded, validator2.Status)
|
||||
|
||||
maxEntries := app.StakingKeeper.MaxEntries(ctx)
|
||||
|
||||
|
@ -841,7 +841,7 @@ func TestRedelegateSelfDelegation(t *testing.T) {
|
|||
validator2, issuedShares = validator2.AddTokensFromDel(valTokens)
|
||||
require.Equal(t, valTokens, issuedShares.RoundInt())
|
||||
validator2 = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator2, true)
|
||||
require.Equal(t, sdk.Bonded, validator2.Status)
|
||||
require.Equal(t, types.Bonded, validator2.Status)
|
||||
|
||||
// create a second delegation to validator 1
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
|
@ -862,7 +862,7 @@ func TestRedelegateSelfDelegation(t *testing.T) {
|
|||
validator, found := app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
require.True(t, found)
|
||||
require.Equal(t, valTokens, validator.Tokens)
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
require.Equal(t, types.Unbonding, validator.Status)
|
||||
}
|
||||
|
||||
func TestRedelegateFromUnbondingValidator(t *testing.T) {
|
||||
|
@ -992,7 +992,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) {
|
|||
validator2, issuedShares = validator2.AddTokensFromDel(valTokens)
|
||||
require.Equal(t, valTokens, issuedShares.RoundInt())
|
||||
validator2 = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator2, true)
|
||||
require.Equal(t, sdk.Bonded, validator2.Status)
|
||||
require.Equal(t, types.Bonded, validator2.Status)
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
ctx = ctx.WithBlockTime(time.Unix(333, 0))
|
||||
|
|
|
@ -27,7 +27,7 @@ func (k Querier) Validators(c context.Context, req *types.QueryValidatorsRequest
|
|||
}
|
||||
|
||||
// validate the provided status, return all the validators if the status is empty
|
||||
if req.Status != "" && !(req.Status == sdk.Bonded.String() || req.Status == sdk.Unbonded.String() || req.Status == sdk.Unbonding.String()) {
|
||||
if req.Status != "" && !(req.Status == types.Bonded.String() || req.Status == types.Unbonded.String() || req.Status == types.Unbonding.String()) {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid validator status %s", req.Status)
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() {
|
|||
},
|
||||
{"valid request",
|
||||
func() {
|
||||
req = &types.QueryValidatorsRequest{Status: sdk.Bonded.String(),
|
||||
req = &types.QueryValidatorsRequest{Status: types.Bonded.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
},
|
||||
true,
|
||||
|
@ -589,7 +589,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegation() {
|
|||
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
||||
val1, val2, val3, val4 := vals[0], vals[1], valAddrs[3], valAddrs[4]
|
||||
delAmount := sdk.TokensFromConsensusPower(1)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc1, delAmount, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc1, delAmount, types.Unbonded, val1, true)
|
||||
suite.NoError(err)
|
||||
_ = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
|
@ -749,9 +749,9 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd
|
|||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1)
|
||||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2)
|
||||
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), sdk.Unbonded, val1, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), sdk.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[2]), sdk.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), types.Unbonded, val1, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), types.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[2]), types.Unbonded, val2, true)
|
||||
app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
return addrs, valAddrs, vals
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
@ -53,11 +52,11 @@ func ModuleAccountInvariants(k Keeper) sdk.Invariant {
|
|||
notBondedPool := k.GetNotBondedPool(ctx)
|
||||
bondDenom := k.BondDenom(ctx)
|
||||
|
||||
k.IterateValidators(ctx, func(_ int64, validator exported.ValidatorI) bool {
|
||||
k.IterateValidators(ctx, func(_ int64, validator types.ValidatorI) bool {
|
||||
switch validator.GetStatus() {
|
||||
case sdk.Bonded:
|
||||
case types.Bonded:
|
||||
bonded = bonded.Add(validator.GetTokens())
|
||||
case sdk.Unbonding, sdk.Unbonded:
|
||||
case types.Unbonding, types.Unbonded:
|
||||
notBonded = notBonded.Add(validator.GetTokens())
|
||||
default:
|
||||
panic("invalid validator status")
|
||||
|
|
|
@ -143,7 +143,7 @@ func TestQueryValidators(t *testing.T) {
|
|||
|
||||
// Create Validators
|
||||
amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)}
|
||||
status := []sdk.BondStatus{sdk.Bonded, sdk.Unbonded, sdk.Unbonding}
|
||||
status := []types.BondStatus{types.Bonded, types.Unbonded, types.Unbonding}
|
||||
var validators [3]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = types.NewValidator(sdk.ValAddress(addrs[i]), PKs[i], types.Description{})
|
||||
|
@ -224,7 +224,7 @@ func TestQueryDelegation(t *testing.T) {
|
|||
app.StakingKeeper.SetValidatorByPowerIndex(ctx, val2)
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(20)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc2, delTokens, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc2, delTokens, types.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// apply TM updates
|
||||
|
@ -473,7 +473,7 @@ func TestQueryValidatorDelegations_Pagination(t *testing.T) {
|
|||
}
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(20)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addr, delTokens, sdk.Unbonded, validator, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addr, delTokens, types.Unbonded, validator, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -552,7 +552,7 @@ func TestQueryRedelegations(t *testing.T) {
|
|||
app.StakingKeeper.SetValidator(ctx, val2)
|
||||
|
||||
delAmount := sdk.TokensFromConsensusPower(100)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc2, delAmount, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc2, delAmount, types.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_ = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
|
@ -623,7 +623,7 @@ func TestQueryUnbondingDelegation(t *testing.T) {
|
|||
|
||||
// delegate
|
||||
delAmount := sdk.TokensFromConsensusPower(100)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc1, delAmount, sdk.Unbonded, val1, true)
|
||||
_, err := app.StakingKeeper.Delegate(ctx, addrAcc1, delAmount, types.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_ = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
|
|
|
@ -120,11 +120,11 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
|
|||
validator = k.RemoveValidatorTokens(ctx, validator, tokensToBurn)
|
||||
|
||||
switch validator.GetStatus() {
|
||||
case sdk.Bonded:
|
||||
case types.Bonded:
|
||||
if err := k.burnBondedTokens(ctx, tokensToBurn); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
case sdk.Unbonding, sdk.Unbonded:
|
||||
case types.Unbonding, types.Unbonded:
|
||||
if err := k.burnNotBondedTokens(ctx, tokensToBurn); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -385,7 +385,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
|||
// power decreased by 1 again, validator is out of stake
|
||||
// validator should be in unbonding period
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
}
|
||||
|
||||
//_________________________________________________________________________________
|
||||
|
@ -515,14 +515,14 @@ func TestSlashWithRedelegation(t *testing.T) {
|
|||
// read updated validator
|
||||
// validator decreased to zero power, should be in unbonding period
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
|
||||
// slash the validator again, by 100%
|
||||
// no stake remains to be slashed
|
||||
ctx = ctx.WithBlockHeight(12)
|
||||
// validator still in unbonding period
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
|
||||
require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec()) })
|
||||
|
||||
|
@ -542,7 +542,7 @@ func TestSlashWithRedelegation(t *testing.T) {
|
|||
// read updated validator
|
||||
// power still zero, still in unbonding period
|
||||
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
}
|
||||
|
||||
// tests Slash at a previous height with both an unbonding delegation and a redelegation
|
||||
|
|
|
@ -265,7 +265,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
|
|||
// delete the validator by power index, as the key will change
|
||||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||
|
||||
validator = validator.UpdateStatus(sdk.Bonded)
|
||||
validator = validator.UpdateStatus(types.Bonded)
|
||||
|
||||
// save the now bonded validator record to the two referenced stores
|
||||
k.SetValidator(ctx, validator)
|
||||
|
@ -288,11 +288,11 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
|||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||
|
||||
// sanity check
|
||||
if validator.Status != sdk.Bonded {
|
||||
if validator.Status != types.Bonded {
|
||||
panic(fmt.Sprintf("should not already be unbonded or unbonding, validator: %v\n", validator))
|
||||
}
|
||||
|
||||
validator = validator.UpdateStatus(sdk.Unbonding)
|
||||
validator = validator.UpdateStatus(types.Unbonding)
|
||||
|
||||
// set the unbonding completion time and completion height appropriately
|
||||
validator.UnbondingTime = ctx.BlockHeader().Time.Add(params.UnbondingTime)
|
||||
|
@ -313,7 +313,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
|||
|
||||
// perform all the store operations for when a validator status becomes unbonded
|
||||
func (k Keeper) completeUnbondingValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
||||
validator = validator.UpdateStatus(sdk.Unbonded)
|
||||
validator = validator.UpdateStatus(types.Unbonded)
|
||||
k.SetValidator(ctx, validator)
|
||||
|
||||
return validator
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestSetValidator(t *testing.T) {
|
|||
// test how the validator is set from a purely unbonbed pool
|
||||
validator := types.NewValidator(valAddr, valPubKey, types.Description{})
|
||||
validator, _ = validator.AddTokensFromDel(valTokens)
|
||||
require.Equal(t, sdk.Unbonded, validator.Status)
|
||||
require.Equal(t, types.Unbonded, validator.Status)
|
||||
assert.Equal(t, valTokens, validator.Tokens)
|
||||
assert.Equal(t, valTokens, validator.DelegatorShares.RoundInt())
|
||||
app.StakingKeeper.SetValidator(ctx, validator)
|
||||
|
@ -58,7 +58,7 @@ func TestSetValidator(t *testing.T) {
|
|||
require.Equal(t, validator.ABCIValidatorUpdate(), updates[0])
|
||||
|
||||
// after the save the validator should be bonded
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
assert.Equal(t, valTokens, validator.Tokens)
|
||||
assert.Equal(t, valTokens, validator.DelegatorShares.RoundInt())
|
||||
|
||||
|
@ -106,7 +106,7 @@ func TestUpdateValidatorByPowerIndex(t *testing.T) {
|
|||
// add a validator
|
||||
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
|
||||
validator, delSharesCreated := validator.AddTokensFromDel(sdk.TokensFromConsensusPower(100))
|
||||
require.Equal(t, sdk.Unbonded, validator.Status)
|
||||
require.Equal(t, types.Unbonded, validator.Status)
|
||||
require.Equal(t, sdk.TokensFromConsensusPower(100), validator.Tokens)
|
||||
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
|
||||
validator, found := app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
|
@ -175,9 +175,9 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
|||
nextCliffVal, _ = nextCliffVal.RemoveDelShares(shares.ToDec())
|
||||
nextCliffVal = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, nextCliffVal, true)
|
||||
|
||||
expectedValStatus := map[int]sdk.BondStatus{
|
||||
9: sdk.Bonded, 8: sdk.Bonded, 7: sdk.Bonded, 5: sdk.Bonded, 4: sdk.Bonded,
|
||||
0: sdk.Unbonding, 1: sdk.Unbonding, 2: sdk.Unbonding, 3: sdk.Unbonding, 6: sdk.Unbonding,
|
||||
expectedValStatus := map[int]types.BondStatus{
|
||||
9: types.Bonded, 8: types.Bonded, 7: types.Bonded, 5: types.Bonded, 4: types.Bonded,
|
||||
0: types.Unbonding, 1: types.Unbonding, 2: types.Unbonding, 3: types.Unbonding, 6: types.Unbonding,
|
||||
}
|
||||
|
||||
// require all the validators have their respective statuses
|
||||
|
@ -210,7 +210,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
|
|||
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
|
||||
|
||||
validator, _ = validator.AddTokensFromDel(valTokens)
|
||||
require.Equal(t, sdk.Unbonded, validator.Status)
|
||||
require.Equal(t, types.Unbonded, validator.Status)
|
||||
require.Equal(t, valTokens, validator.Tokens)
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
|
||||
|
@ -222,7 +222,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
|
|||
app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
// validator should be unbonding
|
||||
validator, _ = app.StakingKeeper.GetValidator(ctx, addrVals[0])
|
||||
require.Equal(t, validator.GetStatus(), sdk.Unbonding)
|
||||
require.Equal(t, validator.GetStatus(), types.Unbonding)
|
||||
}
|
||||
|
||||
// This function tests UpdateValidator, GetValidator, GetLastValidators, RemoveValidator
|
||||
|
@ -234,7 +234,7 @@ func TestValidatorBasics(t *testing.T) {
|
|||
powers := []int64{9, 8, 7}
|
||||
for i, power := range powers {
|
||||
validators[i] = types.NewValidator(addrVals[i], PKs[i], types.Description{})
|
||||
validators[i].Status = sdk.Unbonded
|
||||
validators[i].Status = types.Unbonded
|
||||
validators[i].Tokens = sdk.ZeroInt()
|
||||
tokens := sdk.TokensFromConsensusPower(power)
|
||||
|
||||
|
@ -271,11 +271,11 @@ func TestValidatorBasics(t *testing.T) {
|
|||
resVals = app.StakingKeeper.GetLastValidators(ctx)
|
||||
require.Equal(t, 1, len(resVals))
|
||||
assert.True(ValEq(t, validators[0], resVals[0]))
|
||||
assert.Equal(t, sdk.Bonded, validators[0].Status)
|
||||
assert.Equal(t, types.Bonded, validators[0].Status)
|
||||
assert.True(sdk.IntEq(t, sdk.TokensFromConsensusPower(9), validators[0].BondedTokens()))
|
||||
|
||||
// modify a records, save, and retrieve
|
||||
validators[0].Status = sdk.Bonded
|
||||
validators[0].Status = types.Bonded
|
||||
validators[0].Tokens = sdk.TokensFromConsensusPower(10)
|
||||
validators[0].DelegatorShares = validators[0].Tokens.ToDec()
|
||||
validators[0] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[0], true)
|
||||
|
@ -311,7 +311,7 @@ func TestValidatorBasics(t *testing.T) {
|
|||
func() { app.StakingKeeper.RemoveValidator(ctx, validators[1].GetOperator()) })
|
||||
|
||||
// shouldn't be able to remove if there are still tokens left
|
||||
validators[1].Status = sdk.Unbonded
|
||||
validators[1].Status = types.Unbonded
|
||||
app.StakingKeeper.SetValidator(ctx, validators[1])
|
||||
assert.PanicsWithValue(t,
|
||||
"attempting to remove a validator which still contains tokens",
|
||||
|
@ -339,7 +339,7 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
|||
var validators [5]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = types.NewValidator(sdk.ValAddress(addrs[i]), PKs[i], types.Description{})
|
||||
validators[i].Status = sdk.Bonded
|
||||
validators[i].Status = types.Bonded
|
||||
validators[i].Tokens = sdk.NewInt(amt)
|
||||
validators[i].DelegatorShares = sdk.NewDec(amt)
|
||||
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
|
||||
|
@ -436,7 +436,7 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
|||
for i, amt := range amts {
|
||||
validators[i] = types.NewValidator(sdk.ValAddress(addrs[i]), PKs[i], types.Description{})
|
||||
validators[i].DelegatorShares = sdk.NewDec(amt)
|
||||
validators[i].Status = sdk.Bonded
|
||||
validators[i].Status = types.Bonded
|
||||
validators[i].Tokens = sdk.NewInt(amt)
|
||||
keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
|
||||
}
|
||||
|
@ -451,11 +451,11 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
|||
require.True(t, found)
|
||||
val4, found := app.StakingKeeper.GetValidator(ctx, sdk.ValAddress(addrs[4]))
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Bonded, val0.Status)
|
||||
require.Equal(t, sdk.Unbonding, val1.Status)
|
||||
require.Equal(t, sdk.Unbonding, val2.Status)
|
||||
require.Equal(t, sdk.Bonded, val3.Status)
|
||||
require.Equal(t, sdk.Bonded, val4.Status)
|
||||
require.Equal(t, types.Bonded, val0.Status)
|
||||
require.Equal(t, types.Unbonding, val1.Status)
|
||||
require.Equal(t, types.Unbonding, val2.Status)
|
||||
require.Equal(t, types.Bonded, val3.Status)
|
||||
require.Equal(t, types.Bonded, val4.Status)
|
||||
|
||||
// first make sure everything made it in to the gotValidator group
|
||||
resValidators := app.StakingKeeper.GetBondedValidatorsByPower(ctx)
|
||||
|
@ -654,11 +654,11 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
|
|||
validators[i], found = app.StakingKeeper.GetValidator(ctx, validators[i].GetOperator())
|
||||
require.True(t, found)
|
||||
}
|
||||
assert.Equal(t, sdk.Unbonded, validators[0].Status)
|
||||
assert.Equal(t, sdk.Unbonding, validators[1].Status)
|
||||
assert.Equal(t, sdk.Bonded, validators[2].Status)
|
||||
assert.Equal(t, sdk.Bonded, validators[3].Status)
|
||||
assert.Equal(t, sdk.Unbonded, validators[4].Status)
|
||||
assert.Equal(t, types.Unbonded, validators[0].Status)
|
||||
assert.Equal(t, types.Unbonding, validators[1].Status)
|
||||
assert.Equal(t, types.Bonded, validators[2].Status)
|
||||
assert.Equal(t, types.Bonded, validators[3].Status)
|
||||
assert.Equal(t, types.Unbonded, validators[4].Status)
|
||||
resValidators := app.StakingKeeper.GetBondedValidatorsByPower(ctx)
|
||||
assert.Equal(t, max, len(resValidators))
|
||||
assert.True(ValEq(t, validators[2], resValidators[0])) // in the order of txs
|
||||
|
@ -747,7 +747,7 @@ func TestApplyAndReturnValidatorSetUpdatesSingleValueChange(t *testing.T) {
|
|||
|
||||
// test single value change
|
||||
// tendermintUpdate set: {} -> {c1'}
|
||||
validators[0].Status = sdk.Bonded
|
||||
validators[0].Status = types.Bonded
|
||||
validators[0].Tokens = sdk.TokensFromConsensusPower(600)
|
||||
validators[0] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[0], false)
|
||||
|
||||
|
|
|
@ -9,16 +9,16 @@ import (
|
|||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func migrateBondStatus(oldStatus v034staking.BondStatus) sdk.BondStatus {
|
||||
func migrateBondStatus(oldStatus v034staking.BondStatus) v040staking.BondStatus {
|
||||
switch oldStatus {
|
||||
case v034staking.Unbonded:
|
||||
return sdk.Unbonded
|
||||
return v040staking.Unbonded
|
||||
|
||||
case v034staking.Unbonding:
|
||||
return sdk.Unbonding
|
||||
return v040staking.Unbonding
|
||||
|
||||
case v034staking.Bonded:
|
||||
return sdk.Bonded
|
||||
return v040staking.Bonded
|
||||
|
||||
default:
|
||||
panic(fmt.Errorf("invalid bond status %d", oldStatus))
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestMigrate(t *testing.T) {
|
|||
"jailed": false,
|
||||
"min_self_delegation": "0",
|
||||
"operator_address": "",
|
||||
"status": 1,
|
||||
"status": "BOND_STATUS_UNBONDED",
|
||||
"tokens": "0",
|
||||
"unbonding_height": "0",
|
||||
"unbonding_time": "0001-01-01T00:00:00Z"
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestRandomizedGenState(t *testing.T) {
|
|||
require.Equal(t, "cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", stakingGenesis.Validators[2].GetOperator().String())
|
||||
require.Equal(t, "cosmosvalconspub1zcjduepq280tm686ma80cva9z620dmknd9a858pd2zmq9ackfenfllecjxds0hg9n7", stakingGenesis.Validators[2].ConsensusPubkey)
|
||||
require.Equal(t, false, stakingGenesis.Validators[2].Jailed)
|
||||
require.Equal(t, "Unbonded", stakingGenesis.Validators[2].Status.String())
|
||||
require.Equal(t, "BOND_STATUS_UNBONDED", stakingGenesis.Validators[2].Status.String())
|
||||
require.Equal(t, "1000", stakingGenesis.Validators[2].Tokens.String())
|
||||
require.Equal(t, "1000.000000000000000000", stakingGenesis.Validators[2].DelegatorShares.String())
|
||||
require.Equal(t, "0.292059246265731326", stakingGenesis.Validators[2].Commission.CommissionRates.Rate.String())
|
||||
|
|
|
@ -19,9 +19,9 @@ consensus layer. Operations are as following:
|
|||
validators retrieved from the ValidatorsByPower index
|
||||
- the previous validator set is compared with the new validator set:
|
||||
- missing validators begin unbonding and their `Tokens` are transferred from the
|
||||
`BondedPool` to the `NotBondedPool` `ModuleAccount`
|
||||
`BondedPool` to the `NotBondedPool` `ModuleAccount`
|
||||
- new validators are instantly bonded and their `Tokens` are transferred from the
|
||||
`NotBondedPool` to the `BondedPool` `ModuleAccount`
|
||||
`NotBondedPool` to the `BondedPool` `ModuleAccount`
|
||||
|
||||
In all cases, any validators leaving or entering the bonded validator set or
|
||||
changing balances and staying within the bonded validator set incur an update
|
||||
|
@ -48,8 +48,8 @@ Each block the validator queue is to be checked for mature unbonding validators
|
|||
(namely with a completion time <= current time). At this point any mature
|
||||
validators which do not have any delegations remaining are deleted from state.
|
||||
For all other mature unbonding validators that still have remaining
|
||||
delegations, the `validator.Status` is switched from `sdk.Unbonding` to
|
||||
`sdk.Unbonded`.
|
||||
delegations, the `validator.Status` is switched from `types.Unbonding` to
|
||||
`types.Unbonded`.
|
||||
|
||||
### Unbonding Delegations
|
||||
|
||||
|
|
|
@ -10,11 +10,10 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
)
|
||||
|
||||
// Implements Delegation interface
|
||||
var _ exported.DelegationI = Delegation{}
|
||||
var _ DelegationI = Delegation{}
|
||||
|
||||
// String implements the Stringer interface for a DVPair object.
|
||||
func (dv DVPair) String() string {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
|
||||
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
)
|
||||
|
||||
// DistributionKeeper expected distribution keeper (noalias)
|
||||
|
@ -46,20 +45,20 @@ type BankKeeper interface {
|
|||
type ValidatorSet interface {
|
||||
// iterate through validators by operator address, execute func for each validator
|
||||
IterateValidators(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator ValidatorI) (stop bool))
|
||||
|
||||
// iterate through bonded validators by operator address, execute func for each validator
|
||||
IterateBondedValidatorsByPower(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator ValidatorI) (stop bool))
|
||||
|
||||
// iterate through the consensus validator set of the last block by operator address, execute func for each validator
|
||||
IterateLastValidators(sdk.Context,
|
||||
func(index int64, validator stakingexported.ValidatorI) (stop bool))
|
||||
func(index int64, validator ValidatorI) (stop bool))
|
||||
|
||||
Validator(sdk.Context, sdk.ValAddress) stakingexported.ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI // get a particular validator by consensus address
|
||||
TotalBondedTokens(sdk.Context) sdk.Int // total bonded tokens within the validator set
|
||||
StakingTokenSupply(sdk.Context) sdk.Int // total staking token supply
|
||||
Validator(sdk.Context, sdk.ValAddress) ValidatorI // get a particular validator by operator address
|
||||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) ValidatorI // get a particular validator by consensus address
|
||||
TotalBondedTokens(sdk.Context) sdk.Int // total bonded tokens within the validator set
|
||||
StakingTokenSupply(sdk.Context) sdk.Int // total staking token supply
|
||||
|
||||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
||||
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
|
||||
|
@ -68,7 +67,7 @@ type ValidatorSet interface {
|
|||
|
||||
// Delegation allows for getting a particular delegation for a given validator
|
||||
// and delegator outside the scope of the staking module.
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) DelegationI
|
||||
|
||||
// MaxValidators returns the maximum amount of bonded validators
|
||||
MaxValidators(sdk.Context) uint32
|
||||
|
@ -81,7 +80,7 @@ type DelegationSet interface {
|
|||
// iterate through all delegations from one delegator by validator-AccAddress,
|
||||
// execute func for each validator
|
||||
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
|
||||
fn func(index int64, delegation DelegationI) (stop bool))
|
||||
}
|
||||
|
||||
//_______________________________________________________________________________
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
// DelegationI delegation bond for a delegated proof of stake system
|
||||
type DelegationI interface {
|
||||
GetDelegatorAddr() sdk.AccAddress // delegator sdk.AccAddress for the bond
|
||||
GetValidatorAddr() sdk.ValAddress // validator operator address
|
||||
GetShares() sdk.Dec // amount of validator's shares held in this delegation
|
||||
}
|
||||
|
||||
// ValidatorI expected validator functions
|
||||
type ValidatorI interface {
|
||||
IsJailed() bool // whether the validator is jailed
|
||||
GetMoniker() string // moniker of the validator
|
||||
GetStatus() BondStatus // status of the validator
|
||||
IsBonded() bool // check if has a bonded status
|
||||
IsUnbonded() bool // check if has status unbonded
|
||||
IsUnbonding() bool // check if has status unbonding
|
||||
GetOperator() sdk.ValAddress // operator address to receive/return validators coins
|
||||
GetConsPubKey() crypto.PubKey // validation consensus pubkey
|
||||
GetConsAddr() sdk.ConsAddress // validation consensus address
|
||||
GetTokens() sdk.Int // validation tokens
|
||||
GetBondedTokens() sdk.Int // validator bonded tokens
|
||||
GetConsensusPower() int64 // validation power in tendermint
|
||||
GetCommission() sdk.Dec // validator commission rate
|
||||
GetMinSelfDelegation() sdk.Int // validator minimum self delegation
|
||||
GetDelegatorShares() sdk.Dec // total outstanding delegator shares
|
||||
TokensFromShares(sdk.Dec) sdk.Dec // token worth of provided delegator shares
|
||||
TokensFromSharesTruncated(sdk.Dec) sdk.Dec // token worth of provided delegator shares, truncated
|
||||
TokensFromSharesRoundUp(sdk.Dec) sdk.Dec // token worth of provided delegator shares, rounded up
|
||||
SharesFromTokens(amt sdk.Int) (sdk.Dec, error) // shares worth of delegator's bond
|
||||
SharesFromTokensTruncated(amt sdk.Int) (sdk.Dec, error) // truncated shares worth of delegator's bond
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -17,7 +17,6 @@ import (
|
|||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -29,7 +28,14 @@ const (
|
|||
MaxDetailsLength = 280
|
||||
)
|
||||
|
||||
var _ exported.ValidatorI = Validator{}
|
||||
var (
|
||||
BondStatusUnspecified = BondStatus_name[int32(Unspecified)]
|
||||
BondStatusUnbonded = BondStatus_name[int32(Unbonded)]
|
||||
BondStatusUnbonding = BondStatus_name[int32(Unbonding)]
|
||||
BondStatusBonded = BondStatus_name[int32(Bonded)]
|
||||
)
|
||||
|
||||
var _ ValidatorI = Validator{}
|
||||
|
||||
// NewValidator constructs a new Validator
|
||||
//nolint:interfacer
|
||||
|
@ -43,7 +49,7 @@ func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Des
|
|||
OperatorAddress: operator.String(),
|
||||
ConsensusPubkey: pkStr,
|
||||
Jailed: false,
|
||||
Status: sdk.Unbonded,
|
||||
Status: Unbonded,
|
||||
Tokens: sdk.ZeroInt(),
|
||||
DelegatorShares: sdk.ZeroDec(),
|
||||
Description: description,
|
||||
|
@ -72,7 +78,7 @@ func (v Validators) String() (out string) {
|
|||
}
|
||||
|
||||
// ToSDKValidators - convenience function convert []Validators to []sdk.Validators
|
||||
func (v Validators) ToSDKValidators() (validators []exported.ValidatorI) {
|
||||
func (v Validators) ToSDKValidators() (validators []ValidatorI) {
|
||||
for _, val := range v {
|
||||
validators = append(validators, val)
|
||||
}
|
||||
|
@ -135,17 +141,17 @@ func UnmarshalValidator(cdc codec.BinaryMarshaler, value []byte) (v Validator, e
|
|||
|
||||
// IsBonded checks if the validator status equals Bonded
|
||||
func (v Validator) IsBonded() bool {
|
||||
return v.GetStatus().Equal(sdk.Bonded)
|
||||
return v.GetStatus() == Bonded
|
||||
}
|
||||
|
||||
// IsUnbonded checks if the validator status equals Unbonded
|
||||
func (v Validator) IsUnbonded() bool {
|
||||
return v.GetStatus().Equal(sdk.Unbonded)
|
||||
return v.GetStatus() == Unbonded
|
||||
}
|
||||
|
||||
// IsUnbonding checks if the validator status equals Unbonding
|
||||
func (v Validator) IsUnbonding() bool {
|
||||
return v.GetStatus().Equal(sdk.Unbonding)
|
||||
return v.GetStatus() == Unbonding
|
||||
}
|
||||
|
||||
// constant used in flags to indicate that description field should not be updated
|
||||
|
@ -338,7 +344,7 @@ func (v Validator) PotentialConsensusPower() int64 {
|
|||
|
||||
// UpdateStatus updates the location of the shares within a validator
|
||||
// to reflect the new status
|
||||
func (v Validator) UpdateStatus(newStatus sdk.BondStatus) Validator {
|
||||
func (v Validator) UpdateStatus(newStatus BondStatus) Validator {
|
||||
v.Status = newStatus
|
||||
return v
|
||||
}
|
||||
|
@ -412,16 +418,16 @@ func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, sdk.Int) {
|
|||
func (v Validator) MinEqual(other Validator) bool {
|
||||
return v.ConsensusPubkey == other.ConsensusPubkey &&
|
||||
(v.OperatorAddress == other.OperatorAddress) &&
|
||||
v.Status.Equal(other.Status) &&
|
||||
v.Status == other.Status &&
|
||||
v.Tokens.Equal(other.Tokens) &&
|
||||
v.DelegatorShares.Equal(other.DelegatorShares) &&
|
||||
v.Description == other.Description &&
|
||||
v.Commission.Equal(other.Commission)
|
||||
}
|
||||
|
||||
func (v Validator) IsJailed() bool { return v.Jailed }
|
||||
func (v Validator) GetMoniker() string { return v.Description.Moniker }
|
||||
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
|
||||
func (v Validator) IsJailed() bool { return v.Jailed }
|
||||
func (v Validator) GetMoniker() string { return v.Description.Moniker }
|
||||
func (v Validator) GetStatus() BondStatus { return v.Status }
|
||||
func (v Validator) GetOperator() sdk.ValAddress {
|
||||
if v.OperatorAddress == "" {
|
||||
return nil
|
||||
|
|
|
@ -83,7 +83,7 @@ func TestShareTokens(t *testing.T) {
|
|||
validator := Validator{
|
||||
OperatorAddress: valAddr1.String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||
Status: sdk.Bonded,
|
||||
Status: Bonded,
|
||||
Tokens: sdk.NewInt(100),
|
||||
DelegatorShares: sdk.NewDec(100),
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func TestRemoveTokens(t *testing.T) {
|
|||
validator := Validator{
|
||||
OperatorAddress: valAddr.String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
|
||||
Status: sdk.Bonded,
|
||||
Status: Bonded,
|
||||
Tokens: sdk.NewInt(100),
|
||||
DelegatorShares: sdk.NewDec(100),
|
||||
}
|
||||
|
@ -111,8 +111,8 @@ func TestRemoveTokens(t *testing.T) {
|
|||
require.Equal(t, int64(90), validator.Tokens.Int64())
|
||||
|
||||
// update validator to from bonded -> unbonded
|
||||
validator = validator.UpdateStatus(sdk.Unbonded)
|
||||
require.Equal(t, sdk.Unbonded, validator.Status)
|
||||
validator = validator.UpdateStatus(Unbonded)
|
||||
require.Equal(t, Unbonded, validator.Status)
|
||||
|
||||
validator = validator.RemoveTokens(sdk.NewInt(10))
|
||||
require.Panics(t, func() { validator.RemoveTokens(sdk.NewInt(-1)) })
|
||||
|
@ -121,7 +121,7 @@ func TestRemoveTokens(t *testing.T) {
|
|||
|
||||
func TestAddTokensValidatorBonded(t *testing.T) {
|
||||
validator := NewValidator(sdk.ValAddress(pk1.Address().Bytes()), pk1, Description{})
|
||||
validator = validator.UpdateStatus(sdk.Bonded)
|
||||
validator = validator.UpdateStatus(Bonded)
|
||||
validator, delShares := validator.AddTokensFromDel(sdk.NewInt(10))
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
|
@ -131,11 +131,11 @@ func TestAddTokensValidatorBonded(t *testing.T) {
|
|||
|
||||
func TestAddTokensValidatorUnbonding(t *testing.T) {
|
||||
validator := NewValidator(sdk.ValAddress(pk1.Address().Bytes()), pk1, Description{})
|
||||
validator = validator.UpdateStatus(sdk.Unbonding)
|
||||
validator = validator.UpdateStatus(Unbonding)
|
||||
validator, delShares := validator.AddTokensFromDel(sdk.NewInt(10))
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
assert.Equal(t, sdk.Unbonding, validator.Status)
|
||||
assert.Equal(t, Unbonding, validator.Status)
|
||||
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||
}
|
||||
|
@ -143,11 +143,11 @@ func TestAddTokensValidatorUnbonding(t *testing.T) {
|
|||
func TestAddTokensValidatorUnbonded(t *testing.T) {
|
||||
|
||||
validator := NewValidator(sdk.ValAddress(pk1.Address().Bytes()), pk1, Description{})
|
||||
validator = validator.UpdateStatus(sdk.Unbonded)
|
||||
validator = validator.UpdateStatus(Unbonded)
|
||||
validator, delShares := validator.AddTokensFromDel(sdk.NewInt(10))
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
assert.Equal(t, sdk.Unbonded, validator.Status)
|
||||
assert.Equal(t, Unbonded, validator.Status)
|
||||
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ func TestRemoveDelShares(t *testing.T) {
|
|||
valA := Validator{
|
||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()).String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||
Status: sdk.Bonded,
|
||||
Status: Bonded,
|
||||
Tokens: sdk.NewInt(100),
|
||||
DelegatorShares: sdk.NewDec(100),
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ func TestRemoveDelShares(t *testing.T) {
|
|||
validator := Validator{
|
||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()).String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||
Status: sdk.Bonded,
|
||||
Status: Bonded,
|
||||
Tokens: poolTokens,
|
||||
DelegatorShares: delShares,
|
||||
}
|
||||
|
@ -202,20 +202,20 @@ func TestAddTokensFromDel(t *testing.T) {
|
|||
func TestUpdateStatus(t *testing.T) {
|
||||
validator := NewValidator(sdk.ValAddress(pk1.Address().Bytes()), pk1, Description{})
|
||||
validator, _ = validator.AddTokensFromDel(sdk.NewInt(100))
|
||||
require.Equal(t, sdk.Unbonded, validator.Status)
|
||||
require.Equal(t, Unbonded, validator.Status)
|
||||
require.Equal(t, int64(100), validator.Tokens.Int64())
|
||||
|
||||
// Unbonded to Bonded
|
||||
validator = validator.UpdateStatus(sdk.Bonded)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
validator = validator.UpdateStatus(Bonded)
|
||||
require.Equal(t, Bonded, validator.Status)
|
||||
|
||||
// Bonded to Unbonding
|
||||
validator = validator.UpdateStatus(sdk.Unbonding)
|
||||
require.Equal(t, sdk.Unbonding, validator.Status)
|
||||
validator = validator.UpdateStatus(Unbonding)
|
||||
require.Equal(t, Unbonding, validator.Status)
|
||||
|
||||
// Unbonding to Bonded
|
||||
validator = validator.UpdateStatus(sdk.Bonded)
|
||||
require.Equal(t, sdk.Bonded, validator.Status)
|
||||
validator = validator.UpdateStatus(Bonded)
|
||||
require.Equal(t, Bonded, validator.Status)
|
||||
}
|
||||
|
||||
func TestPossibleOverflow(t *testing.T) {
|
||||
|
@ -223,7 +223,7 @@ func TestPossibleOverflow(t *testing.T) {
|
|||
validator := Validator{
|
||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()).String(),
|
||||
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||
Status: sdk.Bonded,
|
||||
Status: Bonded,
|
||||
Tokens: sdk.NewInt(2159),
|
||||
DelegatorShares: delShares,
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ func TestValidatorToTm(t *testing.T) {
|
|||
for i := range vals {
|
||||
pk := ed25519.GenPrivKey().PubKey()
|
||||
val := NewValidator(sdk.ValAddress(pk.Address()), pk, Description{})
|
||||
val.Status = sdk.Bonded
|
||||
val.Status = Bonded
|
||||
val.Tokens = sdk.NewInt(rand.Int63())
|
||||
vals[i] = val
|
||||
expected[i] = tmtypes.NewValidator(pk.(cryptotypes.IntoTmPubKey).AsTmPubKey(), val.ConsensusPower())
|
||||
|
@ -323,3 +323,14 @@ func TestValidatorToTm(t *testing.T) {
|
|||
|
||||
require.Equal(t, expected, vals.ToTmValidators())
|
||||
}
|
||||
|
||||
func TestBondStatus(t *testing.T) {
|
||||
require.False(t, Unbonded == Bonded)
|
||||
require.False(t, Unbonded == Unbonding)
|
||||
require.False(t, Bonded == Unbonding)
|
||||
require.Equal(t, BondStatus(4).String(), "4")
|
||||
require.Equal(t, BondStatusUnspecified, Unspecified.String())
|
||||
require.Equal(t, BondStatusUnbonded, Unbonded.String())
|
||||
require.Equal(t, BondStatusBonded, Bonded.String())
|
||||
require.Equal(t, BondStatusUnbonding, Unbonding.String())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue