stake

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	GasDeclareCandidacy int64 = 20
	GasEditCandidacy    int64 = 20
	GasDelegate         int64 = 20
	GasUnbond           int64 = 20
)

nolint

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 global parameters relating to staking
	PoolKey                = []byte{0x01} // key for global parameters relating to staking
	CandidatesKey          = []byte{0x02} // prefix for each key to a candidate
	ValidatorsKey          = []byte{0x03} // prefix for each key to a validator
	AccUpdateValidatorsKey = []byte{0x04} // prefix for each key to a validator which is being updated
	RecentValidatorsKey    = []byte{0x05} // prefix for each key to the last updated validator group

	ToKickOutValidatorsKey = []byte{0x06} // prefix for each key to the last updated validator group

	DelegatorBondKeyPrefix = []byte{0x07} // prefix for each key to a delegator's bond

	CounterKey = []byte{0x08} // key for block-local tx index
)

nolint

Functions

func AddrFromKey

func AddrFromKey(key []byte) sdk.Address

reverse operation of GetRecentValidatorKey

func ErrBadBondingAmount

func ErrBadBondingAmount(codespace sdk.CodespaceType) sdk.Error

func ErrBadBondingDenom

func ErrBadBondingDenom(codespace sdk.CodespaceType) sdk.Error

func ErrBadCandidateAddr

func ErrBadCandidateAddr(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 ErrCandidateEmpty

func ErrCandidateEmpty(codespace sdk.CodespaceType) sdk.Error

func ErrCandidateExistsAddr

func ErrCandidateExistsAddr(codespace sdk.CodespaceType) sdk.Error

func ErrCandidateRevoked

func ErrCandidateRevoked(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 ErrNoCandidateForAddress

func ErrNoCandidateForAddress(codespace sdk.CodespaceType) sdk.Error

func ErrNoDelegatorForAddress

func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error

func ErrNotEnoughBondShares

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

func FeeHandler added in v0.16.0

func FeeHandler(ctx sdk.Context, tx sdk.Tx, fee sdk.Coins)

Handle fee distribution to the validators and delegators

func GetAccUpdateValidatorKey

func GetAccUpdateValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetCandidateKey

func GetCandidateKey(addr sdk.Address) []byte

get the key for the candidate with address

func GetDelegatorBondKey

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

get the key for delegator bond with candidate

func GetDelegatorBondsKey

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

get the prefix for a delegator for all candidates

func GetRecentValidatorKey

func GetRecentValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetToKickOutValidatorKey

func GetToKickOutValidatorKey(addr sdk.Address) []byte

get the key for the accumulated update validators

func GetValidatorKey

func GetValidatorKey(addr sdk.Address, power sdk.Rat, height int64, counter int16, cdc *wire.Codec) []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 NewEndBlocker

func NewEndBlocker(k Keeper) sdk.EndBlocker

NewEndBlocker generates sdk.EndBlocker Performs tick functionality

func NewHandler

func NewHandler(k Keeper) sdk.Handler

func RegisterWire

func RegisterWire(cdc *wire.Codec)

Register concrete types on wire codec

Types

type Candidate

type Candidate struct {
	Status               CandidateStatus `json:"status"`                 // Bonded status
	Address              sdk.Address     `json:"owner"`                  // Sender of BondTx - UnbondTx returns here
	PubKey               crypto.PubKey   `json:"pub_key"`                // Pubkey of candidate
	Assets               sdk.Rat         `json:"assets"`                 // total shares of a global hold pools
	Liabilities          sdk.Rat         `json:"liabilities"`            // total shares issued to a candidate's delegators
	Description          Description     `json:"description"`            // Description terms for the candidate
	ValidatorBondHeight  int64           `json:"validator_bond_height"`  // Earliest height as a bonded validator
	ValidatorBondCounter int16           `json:"validator_bond_counter"` // Block-local tx index of validator change
}

Candidate 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 candidate, the candidate is credited with a DelegatorBond 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 NewCandidate

func NewCandidate(address sdk.Address, pubKey crypto.PubKey, description Description) Candidate

NewCandidate - initialize a new candidate

type CandidateStatus

type CandidateStatus byte

CandidateStatus - status of a validator-candidate

const (
	// nolint
	Bonded   CandidateStatus = 0x00
	Unbonded CandidateStatus = 0x01
	Revoked  CandidateStatus = 0x02
)

type Candidates

type Candidates []Candidate

Candidates - list of Candidates

type CodeType

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

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

type DelegatorBond

type DelegatorBond struct {
	DelegatorAddr sdk.Address `json:"delegator_addr"`
	CandidateAddr sdk.Address `json:"candidate_addr"`
	Shares        sdk.Rat     `json:"shares"`
	Height        int64       `json:"height"` // Last height bond updated
}

DelegatorBond 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

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 candidate

func NewDescription

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

type GenesisState

type GenesisState struct {
	Pool       Pool            `json:"pool"`
	Params     Params          `json:"params"`
	Candidates []Candidate     `json:"candidates"`
	Bonds      []DelegatorBond `json:"bonds"`
}

GenesisState - all staking state that must be provided at genesis

func GetDefaultGenesisState added in v0.16.0

func GetDefaultGenesisState() GenesisState

get raw genesis raw message for testing

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) GetCandidate

func (k Keeper) GetCandidate(ctx sdk.Context, addr sdk.Address) (candidate Candidate, found bool)

get a single candidate

func (Keeper) GetCandidates

func (k Keeper) GetCandidates(ctx sdk.Context, maxRetrieve int16) (candidates Candidates)

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

func (Keeper) GetDelegatorBond added in v0.16.0

func (k Keeper) GetDelegatorBond(ctx sdk.Context,
	delegatorAddr, candidateAddr sdk.Address) (bond DelegatorBond, found bool)

load a delegator bond

func (Keeper) GetDelegatorBonds added in v0.16.0

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

load all bonds of a delegator

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params 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) GetValidators

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

Get the validator set from the candidates. The correct subset is retrieved by iterating through an index of the candidates sorted by power, stored using the ValidatorsKey. Simultaniously the most recent the validator records are updated in store with the RecentValidatorsKey. This store is used to determine if a candidate is a validator without needing to iterate over the subspace as we do in GetValidators

func (Keeper) IsRecentValidator

func (k Keeper) IsRecentValidator(ctx sdk.Context, address sdk.Address) bool

Is the address provided a part of the most recently saved validator group?

func (Keeper) Tick

func (k Keeper) Tick(ctx sdk.Context) (change []abci.Validator)

Tick - called at the end of every block

type MsgDeclareCandidacy

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

MsgDeclareCandidacy - struct for unbonding transactions

func NewMsgDeclareCandidacy

func NewMsgDeclareCandidacy(candidateAddr sdk.Address, pubkey crypto.PubKey,
	bond sdk.Coin, description Description) MsgDeclareCandidacy

func (MsgDeclareCandidacy) GetSignBytes

func (msg MsgDeclareCandidacy) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgDeclareCandidacy) GetSigners

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

func (MsgDeclareCandidacy) Type

func (msg MsgDeclareCandidacy) Type() string

nolint

func (MsgDeclareCandidacy) ValidateBasic

func (msg MsgDeclareCandidacy) ValidateBasic() sdk.Error

quick validity check

type MsgDelegate

type MsgDelegate struct {
	DelegatorAddr sdk.Address `json:"address"`
	CandidateAddr sdk.Address `json:"address"`
	Bond          sdk.Coin    `json:"bond"`
}

MsgDelegate - struct for bonding transactions

func NewMsgDelegate

func NewMsgDelegate(delegatorAddr, candidateAddr 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 MsgEditCandidacy

type MsgEditCandidacy struct {
	Description
	CandidateAddr sdk.Address `json:"address"`
}

MsgEditCandidacy - struct for editing a candidate

func NewMsgEditCandidacy

func NewMsgEditCandidacy(candidateAddr sdk.Address, description Description) MsgEditCandidacy

func (MsgEditCandidacy) GetSignBytes

func (msg MsgEditCandidacy) GetSignBytes() []byte

get the bytes for the message signer to sign on

func (MsgEditCandidacy) GetSigners

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

func (MsgEditCandidacy) Type

func (msg MsgEditCandidacy) Type() string

nolint

func (MsgEditCandidacy) ValidateBasic

func (msg MsgEditCandidacy) ValidateBasic() sdk.Error

quick validity check

type MsgUnbond

type MsgUnbond struct {
	DelegatorAddr sdk.Address `json:"address"`
	CandidateAddr sdk.Address `json:"address"`
	Shares        string      `json:"shares"`
}

MsgUnbond - struct for unbonding transactions

func NewMsgUnbond

func NewMsgUnbond(delegatorAddr, candidateAddr 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

type Pool

type Pool struct {
	TotalSupply       int64   `json:"total_supply"`        // total supply of all tokens
	BondedShares      sdk.Rat `json:"bonded_shares"`       // sum of all shares distributed for the Bonded Pool
	UnbondedShares    sdk.Rat `json:"unbonded_shares"`     // sum of all shares distributed for the Unbonded Pool
	BondedPool        int64   `json:"bonded_pool"`         // reserve of bonded tokens
	UnbondedPool      int64   `json:"unbonded_pool"`       // reserve of unbonded tokens held with candidates
	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
}

Pool - dynamic parameters of the current state

type Validator

type Validator struct {
	Address sdk.Address   `json:"address"`
	PubKey  crypto.PubKey `json:"pub_key"`
	Power   sdk.Rat       `json:"voting_power"`
	Height  int64         `json:"height"`  // Earliest height as a validator
	Counter int16         `json:"counter"` // Block-local tx index for resolving equal voting power & height
}

Validator is one of the top Candidates

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) GetDelegatorBond added in v0.16.0

func (v ViewSlashKeeper) GetDelegatorBond(ctx sdk.Context,
	delegatorAddr, candidateAddr sdk.Address) (bond DelegatorBond, found bool)

load a delegator bond

func (ViewSlashKeeper) GetDelegatorBonds added in v0.16.0

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

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