stake

package
v0.19.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const MsgType = "stake"

name to idetify transaction types

View Source
const StakingToken = "steak"

XXX remove: think it makes more sense belonging with the Params so we can initialize at genesis - to allow for the same tests we should should make the ValidateBasic() function a return from an initializable function ValidateBasic(bondDenom string) function

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 by pubkey
	ValidatorsBondedKey        = []byte{0x04} // prefix for each key to bonded/actively validating validators
	ValidatorsByPowerKey       = []byte{0x05} // prefix for each key to a validator sorted by power
	ValidatorCliffKey          = []byte{0x06} // key for block-local tx index
	ValidatorPowerCliffKey     = []byte{0x07} // key for block-local tx index
	TendermintUpdatesKey       = []byte{0x08} // prefix for each key to a validator which is being updated
	DelegationKey              = []byte{0x09} // prefix for each key to a delegator's bond
	IntraTxCounterKey          = []byte{0x10} // key for block-local tx index
)

nolint

Functions

func EndBlocker added in v0.18.0

func EndBlocker(ctx sdk.Context, k Keeper) (ValidatorUpdates []abci.Validator)

Called every block, process inflation, update validator set

func ErrBadBondingAmount

func ErrBadBondingAmount(codespace sdk.CodespaceType) sdk.Error

func ErrBadBondingDenom

func ErrBadBondingDenom(codespace sdk.CodespaceType) sdk.Error

func ErrBadDelegatorAddr

func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBadRemoveValidator

func ErrBadRemoveValidator(codespace sdk.CodespaceType) sdk.Error

func ErrBadShares

func ErrBadShares(codespace sdk.CodespaceType) sdk.Error

func ErrBadValidatorAddr

func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error

func ErrBondNotNominated

func ErrBondNotNominated(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionHuge

func ErrCommissionHuge(codespace sdk.CodespaceType) sdk.Error

func ErrCommissionNegative

func ErrCommissionNegative(codespace sdk.CodespaceType) sdk.Error

func ErrInsufficientFunds

func ErrInsufficientFunds(codespace sdk.CodespaceType) sdk.Error

func ErrMissingSignature

func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error

func ErrNoBondingAcct

func ErrNoBondingAcct(codespace sdk.CodespaceType) sdk.Error

func ErrNoDelegatorForAddress

func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error

func ErrNoValidatorForAddress added in v0.18.0

func ErrNoValidatorForAddress(codespace sdk.CodespaceType) sdk.Error

func ErrNotEnoughBondShares

func ErrNotEnoughBondShares(codespace sdk.CodespaceType, shares string) sdk.Error

func ErrValidatorEmpty added in v0.18.0

func ErrValidatorEmpty(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorExistsAddr added in v0.18.0

func ErrValidatorExistsAddr(codespace sdk.CodespaceType) sdk.Error

func ErrValidatorRevoked added in v0.18.0

func ErrValidatorRevoked(codespace sdk.CodespaceType) sdk.Error

func GetDelegationKey added in v0.18.0

func GetDelegationKey(delegatorAddr, validatorAddr sdk.Address, cdc *wire.Codec) []byte

get the key for delegator bond with validator

func GetDelegationsKey added in v0.18.0

func GetDelegationsKey(delegatorAddr sdk.Address, cdc *wire.Codec) []byte

get the prefix for a delegator for all validators

func GetTendermintUpdatesKey added in v0.18.0

func GetTendermintUpdatesKey(ownerAddr sdk.Address) []byte

get the key for the accumulated update validators

func GetValidatorByPubKeyIndexKey added in v0.18.0

func GetValidatorByPubKeyIndexKey(pubkey crypto.PubKey) []byte

get the key for the validator with pubkey

func GetValidatorKey

func GetValidatorKey(ownerAddr sdk.Address) []byte

get the key for the validator with address

func GetValidatorsBondedKey added in v0.18.0

func GetValidatorsBondedKey(pk crypto.PubKey) []byte

get the key for the current validator group, ordered like tendermint

func GetValidatorsByPowerKey added in v0.18.0

func GetValidatorsByPowerKey(validator Validator, pool Pool) []byte

get the key for the validator used in the power-store

func InitGenesis added in v0.16.0

func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState)

InitGenesis - store genesis parameters

func NewHandler

func NewHandler(k Keeper) sdk.Handler

func RegisterWire

func RegisterWire(cdc *wire.Codec)

Register concrete types on wire codec

func ValEq added in v0.18.0

func ValEq(t *testing.T, exp, got Validator) (*testing.T, bool, string, Validator, Validator)

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

func WriteValidators added in v0.19.0

func WriteValidators(ctx sdk.Context, k Keeper) (vals []tmtypes.GenesisValidator)

WriteValidators - output current validator set

Types

type CodeType

type CodeType = sdk.CodeType
const (
	DefaultCodespace sdk.CodespaceType = 4

	// Gaia errors reserve 200 ~ 299.
	CodeInvalidValidator CodeType = 201
	CodeInvalidBond      CodeType = 202
	CodeInvalidInput     CodeType = 203
	CodeValidatorJailed  CodeType = 204
	CodeUnauthorized     CodeType = sdk.CodeUnauthorized
	CodeInternal         CodeType = sdk.CodeInternal
	CodeUnknownRequest   CodeType = sdk.CodeUnknownRequest
)

type Delegation added in v0.18.0

type Delegation struct {
	DelegatorAddr sdk.Address `json:"delegator_addr"`
	ValidatorAddr sdk.Address `json:"validator_addr"`
	Shares        sdk.Rat     `json:"shares"`
	Height        int64       `json:"height"` // Last height bond updated
}

Delegation represents the bond with tokens held by an account. It is owned by one delegator, and is associated with the voting power of one pubKey. TODO better way of managing space

func (Delegation) GetBondShares added in v0.18.0

func (b Delegation) GetBondShares() sdk.Rat

func (Delegation) GetDelegator added in v0.18.0

func (b Delegation) GetDelegator() sdk.Address

nolint - for sdk.Delegation

func (Delegation) GetValidator added in v0.18.0

func (b Delegation) GetValidator() sdk.Address

func (Delegation) HumanReadableString added in v0.18.0

func (b Delegation) HumanReadableString() (string, error)

Human Friendly pretty printer

type Description

type Description struct {
	Moniker  string `json:"moniker"`
	Identity string `json:"identity"`
	Website  string `json:"website"`
	Details  string `json:"details"`
}

Description - description fields for a validator

func NewDescription

func NewDescription(moniker, identity, website, details string) Description

type GenesisState

type GenesisState struct {
	Pool       Pool         `json:"pool"`
	Params     Params       `json:"params"`
	Validators []Validator  `json:"validators"`
	Bonds      []Delegation `json:"bonds"`
}

GenesisState - all staking state that must be provided at genesis

func DefaultGenesisState added in v0.18.0

func DefaultGenesisState() GenesisState

get raw genesis raw message for testing

func NewGenesisState added in v0.18.0

func NewGenesisState(pool Pool, params Params, validators []Validator, bonds []Delegation) GenesisState

func WriteGenesis added in v0.16.0

func WriteGenesis(ctx sdk.Context, k Keeper) GenesisState

WriteGenesis - output genesis parameters

type Keeper

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

keeper of the staking store

func NewKeeper

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

func (Keeper) Delegation added in v0.18.0

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

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

func (Keeper) GetDelegation added in v0.18.0

func (k Keeper) GetDelegation(ctx sdk.Context,
	delegatorAddr, validatorAddr sdk.Address) (bond Delegation, found bool)

load a delegator bond

func (Keeper) GetDelegations added in v0.18.0

func (k Keeper) GetDelegations(ctx sdk.Context, delegator sdk.Address, maxRetrieve int16) (bonds []Delegation)

load all bonds of a delegator

func (Keeper) GetParams

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

load/save the global staking params

func (Keeper) GetPool

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

load/save the pool

func (Keeper) GetValidator added in v0.18.0

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

get a single validator

func (Keeper) GetValidatorByPubKey added in v0.18.0

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

get a single validator by pubkey

func (Keeper) GetValidators

func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve int16) (validators Validators)

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

func (Keeper) GetValidatorsBonded added in v0.18.0

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

get the group of the bonded validators

func (Keeper) GetValidatorsByPower added in v0.18.0

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

get the group of bonded validators sorted by power-rank

func (Keeper) IterateDelegators added in v0.18.0

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

iterate through the active validator set and perform the provided function

func (Keeper) IterateValidators added in v0.18.0

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 added in v0.18.0

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) Revoke added in v0.18.0

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

revoke a validator

func (Keeper) Slash added in v0.18.0

func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, fraction sdk.Rat)

slash a validator

func (Keeper) TotalPower added in v0.18.0

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

total power from the bond

func (Keeper) Unrevoke added in v0.18.0

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

unrevoke a validator

func (Keeper) Validator added in v0.18.0

func (k Keeper) Validator(ctx sdk.Context, addr sdk.Address) sdk.Validator

get the sdk.validator for a particular address

type MsgCreateValidator added in v0.18.0

type MsgCreateValidator struct {
	Description
	ValidatorAddr sdk.Address   `json:"address"`
	PubKey        crypto.PubKey `json:"pubkey"`
	Bond          sdk.Coin      `json:"bond"`
}

MsgCreateValidator - struct for unbonding transactions

func NewMsgCreateValidator added in v0.18.0

func NewMsgCreateValidator(validatorAddr sdk.Address, pubkey crypto.PubKey,
	bond sdk.Coin, description Description) MsgCreateValidator

func (MsgCreateValidator) GetSignBytes added in v0.18.0

func (msg MsgCreateValidator) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgCreateValidator) GetSigners added in v0.18.0

func (msg MsgCreateValidator) GetSigners() []sdk.Address

func (MsgCreateValidator) Type added in v0.18.0

func (msg MsgCreateValidator) Type() string

nolint

func (MsgCreateValidator) ValidateBasic added in v0.18.0

func (msg MsgCreateValidator) ValidateBasic() sdk.Error

quick validity check

type MsgDelegate

type MsgDelegate struct {
	DelegatorAddr sdk.Address `json:"delegator_addr"`
	ValidatorAddr sdk.Address `json:"validator_addr"`
	Bond          sdk.Coin    `json:"bond"`
}

MsgDelegate - struct for bonding transactions

func NewMsgDelegate

func NewMsgDelegate(delegatorAddr, validatorAddr sdk.Address, bond sdk.Coin) MsgDelegate

func (MsgDelegate) GetSignBytes

func (msg MsgDelegate) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgDelegate) GetSigners

func (msg MsgDelegate) GetSigners() []sdk.Address

func (MsgDelegate) Type

func (msg MsgDelegate) Type() string

nolint

func (MsgDelegate) ValidateBasic

func (msg MsgDelegate) ValidateBasic() sdk.Error

quick validity check

type MsgEditValidator added in v0.18.0

type MsgEditValidator struct {
	Description
	ValidatorAddr sdk.Address `json:"address"`
}

MsgEditValidator - struct for editing a validator

func NewMsgEditValidator added in v0.18.0

func NewMsgEditValidator(validatorAddr sdk.Address, description Description) MsgEditValidator

func (MsgEditValidator) GetSignBytes added in v0.18.0

func (msg MsgEditValidator) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgEditValidator) GetSigners added in v0.18.0

func (msg MsgEditValidator) GetSigners() []sdk.Address

func (MsgEditValidator) Type added in v0.18.0

func (msg MsgEditValidator) Type() string

nolint

func (MsgEditValidator) ValidateBasic added in v0.18.0

func (msg MsgEditValidator) ValidateBasic() sdk.Error

quick validity check

type MsgUnbond

type MsgUnbond struct {
	DelegatorAddr sdk.Address `json:"delegator_addr"`
	ValidatorAddr sdk.Address `json:"validator_addr"`
	Shares        string      `json:"shares"`
}

MsgUnbond - struct for unbonding transactions

func NewMsgUnbond

func NewMsgUnbond(delegatorAddr, validatorAddr sdk.Address, shares string) MsgUnbond

func (MsgUnbond) GetSignBytes

func (msg MsgUnbond) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgUnbond) GetSigners

func (msg MsgUnbond) GetSigners() []sdk.Address

func (MsgUnbond) Type

func (msg MsgUnbond) Type() string

nolint

func (MsgUnbond) ValidateBasic

func (msg MsgUnbond) ValidateBasic() sdk.Error

quick validity check

type Params

type Params struct {
	InflationRateChange sdk.Rat `json:"inflation_rate_change"` // maximum annual change in inflation rate
	InflationMax        sdk.Rat `json:"inflation_max"`         // maximum inflation rate
	InflationMin        sdk.Rat `json:"inflation_min"`         // minimum inflation rate
	GoalBonded          sdk.Rat `json:"goal_bonded"`           // Goal of percent bonded atoms

	MaxValidators uint16 `json:"max_validators"` // maximum number of validators
	BondDenom     string `json:"bond_denom"`     // bondable coin denomination
}

Params defines the high level settings for staking

func DefaultParams added in v0.18.0

func DefaultParams() Params

default params

type Pool

type Pool struct {
	LooseUnbondedTokens int64   `json:"loose_unbonded_tokens"` // tokens not associated with any validator
	UnbondedTokens      int64   `json:"unbonded_tokens"`       // reserve of unbonded tokens held with validators
	UnbondingTokens     int64   `json:"unbonding_tokens"`      // tokens moving from bonded to unbonded pool
	BondedTokens        int64   `json:"bonded_tokens"`         // reserve of bonded tokens
	UnbondedShares      sdk.Rat `json:"unbonded_shares"`       // sum of all shares distributed for the Unbonded Pool
	UnbondingShares     sdk.Rat `json:"unbonding_shares"`      // shares moving from Bonded to Unbonded Pool
	BondedShares        sdk.Rat `json:"bonded_shares"`         // sum of all shares distributed for the Bonded Pool
	InflationLastTime   int64   `json:"inflation_last_time"`   // block which the last inflation was processed // TODO make time
	Inflation           sdk.Rat `json:"inflation"`             // current annual inflation rate

	DateLastCommissionReset int64 `json:"date_last_commission_reset"` // unix timestamp for last commission accounting reset (daily)

	// Fee Related
	PrevBondedShares sdk.Rat `json:"prev_bonded_shares"` // last recorded bonded shares - for fee calcualtions
}

Pool - dynamic parameters of the current state

func InitialPool added in v0.18.0

func InitialPool() Pool

initial pool for testing

func (Pool) TokenSupply added in v0.18.0

func (p Pool) TokenSupply() int64

Sum total of all staking tokens in the pool

type PoolShareKind added in v0.18.0

type PoolShareKind byte

kind of shares

type PoolShares added in v0.18.0

type PoolShares struct {
	Status sdk.BondStatus `json:"status"`
	Amount sdk.Rat        `json:"amount"` // total shares of type ShareKind
}

pool shares held by a validator

func NewBondedShares added in v0.18.0

func NewBondedShares(amount sdk.Rat) PoolShares

func NewUnbondedShares added in v0.18.0

func NewUnbondedShares(amount sdk.Rat) PoolShares

func NewUnbondingShares added in v0.18.0

func NewUnbondingShares(amount sdk.Rat) PoolShares

func (PoolShares) Bonded added in v0.18.0

func (s PoolShares) Bonded() sdk.Rat

amount of bonded shares

func (PoolShares) Equal added in v0.18.0

func (s PoolShares) Equal(s2 PoolShares) bool

only the vitals - does not check bond height of IntraTxCounter

func (PoolShares) ToBonded added in v0.18.0

func (s PoolShares) ToBonded(p Pool) PoolShares

equivalent amount of shares if the shares were bonded

func (PoolShares) ToUnbonded added in v0.18.0

func (s PoolShares) ToUnbonded(p Pool) PoolShares

equivalent amount of shares if the shares were unbonded

func (PoolShares) ToUnbonding added in v0.18.0

func (s PoolShares) ToUnbonding(p Pool) PoolShares

equivalent amount of shares if the shares were unbonding

func (PoolShares) Tokens added in v0.18.0

func (s PoolShares) Tokens(p Pool) sdk.Rat

TODO better tests get the equivalent amount of tokens contained by the shares

func (PoolShares) Unbonded added in v0.18.0

func (s PoolShares) Unbonded() sdk.Rat

amount of unbonded shares

func (PoolShares) Unbonding added in v0.18.0

func (s PoolShares) Unbonding() sdk.Rat

amount of unbonding shares

type Validator

type Validator struct {
	Owner   sdk.Address   `json:"owner"`   // sender of BondTx - UnbondTx returns here
	PubKey  crypto.PubKey `json:"pub_key"` // pubkey of validator
	Revoked bool          `json:"revoked"` // has the validator been revoked from bonded status?

	PoolShares      PoolShares `json:"pool_shares"`      // total shares for tokens held in the pool
	DelegatorShares sdk.Rat    `json:"delegator_shares"` // total shares issued to a validator's delegators

	Description        Description `json:"description"`           // description terms for the validator
	BondHeight         int64       `json:"bond_height"`           // earliest height as a bonded validator
	BondIntraTxCounter int16       `json:"bond_intra_tx_counter"` // block-local tx index of validator change
	ProposerRewardPool sdk.Coins   `json:"proposer_reward_pool"`  // XXX reward pool collected from being the proposer

	Commission            sdk.Rat `json:"commission"`              // XXX the commission rate of fees charged to any delegators
	CommissionMax         sdk.Rat `json:"commission_max"`          // XXX maximum commission rate which this validator can ever charge
	CommissionChangeRate  sdk.Rat `json:"commission_change_rate"`  // XXX maximum daily increase of the validator commission
	CommissionChangeToday sdk.Rat `json:"commission_change_today"` // XXX commission rate change today, reset each day (UTC time)

	// fee related
	PrevBondedShares sdk.Rat `json:"prev_bonded_shares"` // total shares of a global hold pools
}

Validator defines the total amount of bond shares and their exchange rate to coins. Accumulation of interest is modelled as an in increase in the exchange rate, and slashing as a decrease. When coins are delegated to this validator, the validator is credited with a Delegation whose number of bond shares is based on the amount of coins delegated divided by the current exchange rate. Voting power can be calculated as total bonds multiplied by exchange rate.

func NewValidator added in v0.18.0

func NewValidator(owner sdk.Address, pubKey crypto.PubKey, description Description) Validator

NewValidator - initialize a new validator

func (Validator) DelegatorShareExRate added in v0.18.0

func (v Validator) DelegatorShareExRate(pool Pool) sdk.Rat

get the exchange rate of tokens over delegator shares UNITS: eq-val-bonded-shares/delegator-shares

func (Validator) EquivalentBondedShares added in v0.18.0

func (v Validator) EquivalentBondedShares(pool Pool) (eqBondedShares sdk.Rat)

XXX TEST get the power or potential power for a validator if bonded, the power is the BondedShares if not bonded, the power is the amount of bonded shares which the

the validator would have it was bonded

func (Validator) GetBondHeight added in v0.18.0

func (v Validator) GetBondHeight() int64

func (Validator) GetMoniker added in v0.19.0

func (v Validator) GetMoniker() string

nolint - for sdk.Validator

func (Validator) GetOwner added in v0.18.0

func (v Validator) GetOwner() sdk.Address

func (Validator) GetPower added in v0.18.0

func (v Validator) GetPower() sdk.Rat

func (Validator) GetPubKey added in v0.18.0

func (v Validator) GetPubKey() crypto.PubKey

func (Validator) GetStatus added in v0.18.0

func (v Validator) GetStatus() sdk.BondStatus

func (Validator) HumanReadableString added in v0.18.0

func (v Validator) HumanReadableString() (string, error)

Human Friendly pretty printer

func (Validator) Status added in v0.18.0

func (v Validator) Status() sdk.BondStatus

abci validator from stake validator type

func (Validator) UpdateStatus added in v0.18.0

func (v Validator) UpdateStatus(pool Pool, NewStatus sdk.BondStatus) (Validator, Pool)

update the location of the shares within a validator if its bond status has changed

type Validators added in v0.18.0

type Validators []Validator

Validators - list of Validators

type ViewSlashKeeper added in v0.16.0

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

keeper to view information & slash validators will be used by governance module

func NewViewSlashKeeper added in v0.16.0

func NewViewSlashKeeper(k Keeper) ViewSlashKeeper

NewViewSlashKeeper creates a keeper restricted to viewing information & slashing validators

func (ViewSlashKeeper) GetDelegation added in v0.18.0

func (v ViewSlashKeeper) GetDelegation(ctx sdk.Context,
	delegatorAddr sdk.Address, validatorAddr sdk.Address) (bond Delegation, found bool)

load a delegator bond

func (ViewSlashKeeper) GetDelegations added in v0.18.0

func (v ViewSlashKeeper) GetDelegations(ctx sdk.Context,
	delegator sdk.Address, maxRetrieve int16) (bonds []Delegation)

load n delegator bonds

Directories

Path Synopsis
client
cli

Jump to

Keyboard shortcuts

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