keeper

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Keys for store prefixes
	ParamKey                         = []byte{0x00} // key for parameters relating to staking
	PoolKey                          = []byte{0x01} // key for the staking pools
	ValidatorsKey                    = []byte{0x02} // prefix for each key to a validator
	ValidatorsByPubKeyIndexKey       = []byte{0x03} // prefix for each key to a validator index, by pubkey
	ValidatorsBondedIndexKey         = []byte{0x04} // prefix for each key to a validator index, for bonded validators
	ValidatorsByPowerIndexKey        = []byte{0x05} // prefix for each key to a validator index, sorted by power
	ValidatorCliffIndexKey           = []byte{0x06} // key for the validator index of the cliff validator
	ValidatorPowerCliffKey           = []byte{0x07} // key for the power of the validator on the cliff
	TendermintUpdatesKey             = []byte{0x08} // prefix for each key to a validator which is being updated
	IntraTxCounterKey                = []byte{0x09} // key for intra-block tx index
	DelegationKey                    = []byte{0x0A} // key for a delegation
	UnbondingDelegationKey           = []byte{0x0B} // key for an unbonding-delegation
	UnbondingDelegationByValIndexKey = []byte{0x0C} // prefix for each key for an unbonding-delegation, by validator owner
	RedelegationKey                  = []byte{0x0D} // key for a redelegation
	RedelegationByValSrcIndexKey     = []byte{0x0E} // prefix for each key for an redelegation, by source validator owner
	RedelegationByValDstIndexKey     = []byte{0x0F} // prefix for each key for an redelegation, by destination validator owner
)

nolint

View Source
var (
	Addrs = createTestAddrs(100)
	PKs   = createTestPubKeys(100)
)

dummy addresses used for testing

Functions

func GetAddressFromValBondedIndexKey

func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte

Get the validator owner address from ValBondedIndexKey

func GetDelegationKey

func GetDelegationKey(delegatorAddr, validatorAddr sdk.AccAddress) []byte

get the key for delegator bond with validator. VALUE: stake/types.Delegation

func GetDelegationsKey

func GetDelegationsKey(delegatorAddr sdk.AccAddress) []byte

get the prefix for a delegator for all validators

func GetREDByValDstIndexKey

func GetREDByValDstIndexKey(delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.AccAddress) []byte

get the index-key for a redelegation, stored by destination-validator-index VALUE: none (key rearrangement used)

func GetREDByValSrcIndexKey

func GetREDByValSrcIndexKey(delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.AccAddress) []byte

get the index-key for a redelegation, stored by source-validator-index VALUE: none (key rearrangement used)

func GetREDKey

func GetREDKey(delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.AccAddress) []byte

get the key for a redelegation VALUE: stake/types.RedelegationKey

func GetREDKeyFromValDstIndexKey

func GetREDKeyFromValDstIndexKey(IndexKey []byte) []byte

rearrange the ValDstIndexKey to get the REDKey

func GetREDKeyFromValSrcIndexKey

func GetREDKeyFromValSrcIndexKey(IndexKey []byte) []byte

rearrange the ValSrcIndexKey to get the REDKey

func GetREDsByDelToValDstIndexKey

func GetREDsByDelToValDstIndexKey(delegatorAddr, validatorDstAddr sdk.AccAddress) []byte

get the prefix keyspace for all redelegations redelegating towards a destination validator from a particular delegator

func GetREDsFromValSrcIndexKey

func GetREDsFromValSrcIndexKey(validatorSrcAddr sdk.AccAddress) []byte

get the prefix keyspace for all redelegations redelegating away from a source validator

func GetREDsKey

func GetREDsKey(delegatorAddr sdk.AccAddress) []byte

get the prefix keyspace for redelegations from a delegator

func GetREDsToValDstIndexKey

func GetREDsToValDstIndexKey(validatorDstAddr sdk.AccAddress) []byte

get the prefix keyspace for all redelegations redelegating towards a destination validator

func GetTendermintUpdatesKey

func GetTendermintUpdatesKey(ownerAddr sdk.AccAddress) []byte

get the key for the accumulated update validators. VALUE: abci.Validator note records using these keys should never persist between blocks

func GetUBDByValIndexKey

func GetUBDByValIndexKey(delegatorAddr, validatorAddr sdk.AccAddress) []byte

get the index-key for an unbonding delegation, stored by validator-index VALUE: none (key rearrangement used)

func GetUBDKey

func GetUBDKey(delegatorAddr, validatorAddr sdk.AccAddress) []byte

get the key for an unbonding delegation by delegator and validator addr. VALUE: stake/types.UnbondingDelegation

func GetUBDKeyFromValIndexKey

func GetUBDKeyFromValIndexKey(IndexKey []byte) []byte

rearrange the ValIndexKey to get the UBDKey

func GetUBDsByValIndexKey

func GetUBDsByValIndexKey(validatorAddr sdk.AccAddress) []byte

get the prefix keyspace for the indexes of unbonding delegations for a validator

func GetUBDsKey

func GetUBDsKey(delegatorAddr sdk.AccAddress) []byte

get the prefix for all unbonding delegations from a delegator

func GetValidatorByPubKeyIndexKey

func GetValidatorByPubKeyIndexKey(pubkey crypto.PubKey) []byte

get the key for the validator with pubkey. VALUE: validator owner address ([]byte)

func GetValidatorKey

func GetValidatorKey(ownerAddr sdk.AccAddress) []byte

get the key for the validator with address. VALUE: stake/types.Validator

func GetValidatorsBondedIndexKey

func GetValidatorsBondedIndexKey(ownerAddr sdk.AccAddress) []byte

get the key for the current validator group VALUE: none (key rearrangement with GetValKeyFromValBondedIndexKey)

func GetValidatorsByPowerIndexKey

func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []byte

get the validator by power index. power index is the key used in the power-store, and represents the relative power ranking of the validator. VALUE: validator owner address ([]byte)

func MakeTestCodec

func MakeTestCodec() *wire.Codec

create a codec used only for testing

func NewPubKey

func NewPubKey(pk string) (res crypto.PubKey)

func ParamsNoInflation

func ParamsNoInflation() types.Params

default params without inflation

func TestAddr

func TestAddr(addr string, bech string) sdk.AccAddress

for incode address generation

func ValEq

intended to be used with require/assert: require.True(ValEq(...))

func ValidatorByPowerIndexExists

func ValidatorByPowerIndexExists(ctx sdk.Context, keeper Keeper, power []byte) bool

does a certain by-power index record exist

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

keeper of the stake store

func CreateTestInput

func CreateTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context, auth.AccountMapper, Keeper)

hogpodge of all sorts of input required for testing

func NewKeeper

func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper

func (Keeper) BeginRedelegation

func (k Keeper) BeginRedelegation(ctx sdk.Context, delegatorAddr, validatorSrcAddr,
	validatorDstAddr sdk.AccAddress, sharesAmount sdk.Rat) sdk.Error

complete unbonding an unbonding record

func (Keeper) BeginUnbonding

func (k Keeper) BeginUnbonding(ctx sdk.Context, delegatorAddr, validatorAddr sdk.AccAddress, sharesAmount sdk.Rat) sdk.Error

complete unbonding an unbonding record

func (Keeper) ClearTendermintUpdates

func (k Keeper) ClearTendermintUpdates(ctx sdk.Context)

remove all validator update entries after applied to Tendermint

func (Keeper) Codespace

func (k Keeper) Codespace() sdk.CodespaceType

return the codespace

func (Keeper) CompleteRedelegation

func (k Keeper) CompleteRedelegation(ctx sdk.Context, delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.AccAddress) sdk.Error

complete unbonding an ongoing redelegation

func (Keeper) CompleteUnbonding

func (k Keeper) CompleteUnbonding(ctx sdk.Context, delegatorAddr, validatorAddr sdk.AccAddress) sdk.Error

complete unbonding an unbonding record

func (Keeper) Delegate

func (k Keeper) Delegate(ctx sdk.Context, delegatorAddr sdk.AccAddress, bondAmt sdk.Coin,
	validator types.Validator, subtractAccount bool) (newShares sdk.Rat, err sdk.Error)

Perform a delegation, set/update everything necessary within the store.

func (Keeper) Delegation

func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.AccAddress) sdk.Delegation

get the delegation for a particular set of delegator and validator addresses

func (Keeper) GetAllDelegations

func (k Keeper) GetAllDelegations(ctx sdk.Context) (delegations []types.Delegation)

load all delegations used during genesis dump

func (Keeper) GetAllValidators

func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []types.Validator)

Get the set of all validators with no limits, used during genesis dump

func (Keeper) GetCliffValidator

func (k Keeper) GetCliffValidator(ctx sdk.Context) []byte

get the current validator on the cliff

func (Keeper) GetCliffValidatorPower

func (k Keeper) GetCliffValidatorPower(ctx sdk.Context) []byte

get the current power of the validator on the cliff

func (Keeper) GetDelegation

func (k Keeper) GetDelegation(ctx sdk.Context,
	delegatorAddr, validatorAddr sdk.AccAddress) (delegation types.Delegation, found bool)

load a delegation

func (Keeper) GetDelegations

func (k Keeper) GetDelegations(ctx sdk.Context, delegator sdk.AccAddress,
	maxRetrieve int16) (delegations []types.Delegation)

load all delegations for a delegator

func (Keeper) GetIntraTxCounter

func (k Keeper) GetIntraTxCounter(ctx sdk.Context) int16

get the current in-block validator operation counter

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

load/save the global staking params

func (Keeper) GetPool

func (k Keeper) GetPool(ctx sdk.Context) (pool types.Pool)

load/save the pool

func (Keeper) GetRedelegation

func (k Keeper) GetRedelegation(ctx sdk.Context,
	DelegatorAddr, ValidatorSrcAddr, ValidatorDstAddr sdk.AccAddress) (red types.Redelegation, found bool)

load a redelegation

func (Keeper) GetRedelegationsFromValidator

func (k Keeper) GetRedelegationsFromValidator(ctx sdk.Context, valAddr sdk.AccAddress) (reds []types.Redelegation)

load all redelegations from a particular validator

func (Keeper) GetTendermintUpdates

func (k Keeper) GetTendermintUpdates(ctx sdk.Context) (updates []abci.Validator)

get the most recently updated validators

func (Keeper) GetUnbondingDelegation

func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
	DelegatorAddr, ValidatorAddr sdk.AccAddress) (ubd types.UnbondingDelegation, found bool)

load a unbonding delegation

func (Keeper) GetUnbondingDelegationsFromValidator

func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sdk.AccAddress) (ubds []types.UnbondingDelegation)

load all unbonding delegations from a particular validator

func (Keeper) GetValidator

func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.AccAddress) (validator types.Validator, found bool)

get a single validator

func (Keeper) GetValidatorByPubKey

func (k Keeper) GetValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) (validator types.Validator, found bool)

get a single validator by pubkey

func (Keeper) GetValidatorSet

func (k Keeper) GetValidatorSet() sdk.ValidatorSet

Returns self as it is both a validatorset and delegationset

func (Keeper) GetValidators

func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve int16) (validators []types.Validator)

Get the set of all validators, retrieve a maxRetrieve number of records

func (Keeper) GetValidatorsBonded

func (k Keeper) GetValidatorsBonded(ctx sdk.Context) (validators []types.Validator)

get the group of the bonded validators

func (Keeper) GetValidatorsByPower

func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []types.Validator

get the group of bonded validators sorted by power-rank

func (Keeper) HasReceivingRedelegation

func (k Keeper) HasReceivingRedelegation(ctx sdk.Context,
	DelegatorAddr, ValidatorDstAddr sdk.AccAddress) bool

has a redelegation

func (Keeper) InitIntraTxCounter

func (k Keeper) InitIntraTxCounter(ctx sdk.Context)

get the current in-block validator operation counter

func (Keeper) IterateDelegations

func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress, fn func(index int64, delegation sdk.Delegation) (stop bool))

iterate through the active validator set and perform the provided function

func (Keeper) IterateValidators

func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validator sdk.Validator) (stop bool))

iterate through the active validator set and perform the provided function

func (Keeper) IterateValidatorsBonded

func (k Keeper) IterateValidatorsBonded(ctx sdk.Context, fn func(index int64, validator sdk.Validator) (stop bool))

iterate through the active validator set and perform the provided function

func (Keeper) RemoveDelegation

func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation)

remove the delegation

func (Keeper) RemoveRedelegation

func (k Keeper) RemoveRedelegation(ctx sdk.Context, red types.Redelegation)

remove a redelegation object and associated index

func (Keeper) RemoveUnbondingDelegation

func (k Keeper) RemoveUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDelegation)

remove the unbonding delegation object and associated index

func (Keeper) RemoveValidator

func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.AccAddress)

remove the validator record and associated indexes

func (Keeper) Revoke

func (k Keeper) Revoke(ctx sdk.Context, pubkey crypto.PubKey)

revoke a validator

func (Keeper) SetDelegation

func (k Keeper) SetDelegation(ctx sdk.Context, delegation types.Delegation)

set the delegation

func (Keeper) SetIntraTxCounter

func (k Keeper) SetIntraTxCounter(ctx sdk.Context, counter int16)

set the current in-block validator operation counter

func (Keeper) SetNewParams

func (k Keeper) SetNewParams(ctx sdk.Context, params types.Params)

Need a distinct function because setParams depends on an existing previous record of params to exist (to check if maxValidators has changed) - and we panic on retrieval if it doesn't exist - hence if we use setParams for the very first params set it will panic.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

set the params

func (Keeper) SetPool

func (k Keeper) SetPool(ctx sdk.Context, pool types.Pool)

set the pool

func (Keeper) SetRedelegation

func (k Keeper) SetRedelegation(ctx sdk.Context, red types.Redelegation)

set a redelegation and associated index

func (Keeper) SetUnbondingDelegation

func (k Keeper) SetUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDelegation)

set the unbonding delegation and associated index

func (Keeper) SetValidator

func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator)

set the main record holding validator details

func (Keeper) SetValidatorBondedIndex

func (k Keeper) SetValidatorBondedIndex(ctx sdk.Context, validator types.Validator)

validator index

func (Keeper) SetValidatorByPowerIndex

func (k Keeper) SetValidatorByPowerIndex(ctx sdk.Context, validator types.Validator, pool types.Pool)

validator index

func (Keeper) SetValidatorByPubKeyIndex

func (k Keeper) SetValidatorByPubKeyIndex(ctx sdk.Context, validator types.Validator)

validator index

func (Keeper) Slash

func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight int64, power int64, slashFactor sdk.Rat)

Slash a validator for an infraction committed at a known height Find the contributing stake at that height and burn the specified slashFactor of it, updating unbonding delegation & redelegations appropriately

CONTRACT:

slashFactor is non-negative

CONTRACT:

Infraction committed equal to or less than an unbonding period in the past,
so all unbonding delegations and redelegations from that height are stored

CONTRACT:

Infraction committed at the current height or at a past height,
not at a height in the future

func (Keeper) TotalPower

func (k Keeper) TotalPower(ctx sdk.Context) sdk.Rat

total power from the bond

func (Keeper) Unrevoke

func (k Keeper) Unrevoke(ctx sdk.Context, pubkey crypto.PubKey)

unrevoke a validator

func (Keeper) UpdateBondedValidators

func (k Keeper) UpdateBondedValidators(ctx sdk.Context,
	affectedValidator types.Validator) (updatedVal types.Validator, updated bool)

Update the bonded validator group based on a change to the validator affectedValidator. This function potentially adds the affectedValidator to the bonded validator group which kicks out the cliff validator. Under this situation this function returns the updated affectedValidator.

The correct bonded subset of validators is retrieved by iterating through an index of the validators sorted by power, stored using the ValidatorsByPowerIndexKey. Simultaneously the current validator records are updated in store with the ValidatorsBondedIndexKey. This store is used to determine if a validator is a validator without needing to iterate over all validators.

nolint: gocyclo TODO: Remove the above golint

func (Keeper) UpdateBondedValidatorsFull

func (k Keeper) UpdateBondedValidatorsFull(ctx sdk.Context)

full update of the bonded validator set, many can be added/kicked

func (Keeper) UpdateValidator

func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator

Perfom all the nessisary steps for when a validator changes its power. This function updates all validator stores as well as tendermint update store. It may kick out validators if new validator is entering the bonded validator group.

nolint: gocyclo TODO: Remove above nolint, function needs to be simplified

func (Keeper) Validator

func (k Keeper) Validator(ctx sdk.Context, address sdk.AccAddress) sdk.Validator

get the sdk.validator for a particular address

func (Keeper) ValidatorByPubKey added in v0.23.0

func (k Keeper) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator

get the sdk.validator for a particular pubkey

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL