keeper

package
v0.0.0-...-b5e13e0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultParamspace = types.ModuleName
)

Default parameter namespace

Variables

View Source
var (
	// Keys for store prefixes
	PoolKey = []byte{0x00} // key for the staking pools

	// Last* values are constant during a block.
	/**
	TODO 查不出来是哪里 存入DB的 ??????
	最新的验证人的权重信息 key前缀
	*/
	LastValidatorPowerKey = []byte{0x11} // prefix for each key to a validator index, for bonded validators
	/**
	TODO 查不出来是哪里 存入DB的 ??????
	最新的验证人 总权重信息 key
	*/
	LastTotalPowerKey = []byte{0x12} // prefix for the total power

	/**
	验证人的key前缀
	*/
	ValidatorsKey = []byte{0x21} // prefix for each key to a validator
	/**
	验证人的公钥索引做的key前缀
	*/
	ValidatorsByConsAddrKey = []byte{0x22} // prefix for each key to a validator index, by pubkey

	/**
	TODO 重要的 key
	验证人的权重key前缀
	*/
	ValidatorsByPowerIndexKey = []byte{0x23} // prefix for each key to a validator index, sorted by power

	/**
	当前节点上所有委托人的信息的
	*/
	DelegationKey          = []byte{0x31} // key for a delegation
	UnbondingDelegationKey = []byte{0x32} // key for an unbonding-delegation
	/*
		单个验证人身上的所有解除委托的委托信息的Key
	*/
	UnbondingDelegationByValIndexKey = []byte{0x33} // prefix for each key for an unbonding-delegation, by validator operator
	RedelegationKey                  = []byte{0x34} // key for a redelegation
	RedelegationByValSrcIndexKey     = []byte{0x35} // prefix for each key for an redelegation, by source validator operator
	RedelegationByValDstIndexKey     = []byte{0x36} // prefix for each key for an redelegation, by destination validator operator

	/**
	unbonding队列中时间戳的前缀
	*/
	UnbondingQueueKey = []byte{0x41} // prefix for the timestamps in unbonding queue

	/**
	重新授权委托队列中时间戳的前缀
	*/
	RedelegationQueueKey = []byte{0x42} // prefix for the timestamps in redelegations queue

	/**
	验证器队列中时间戳的前缀
	*/
	ValidatorQueueKey = []byte{0x43} // prefix for the timestamps in validator queue
)

nolint * ############## 存储在DB中的Key的前缀 定义 #############

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

dummy addresses used for testing

Functions

func AddressFromLastValidatorPowerKey

func AddressFromLastValidatorPowerKey(key []byte) []byte

Get the validator operator address from LastValidatorPowerKey

func GetDelegationKey

func GetDelegationKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

gets the key for delegator bond with validator VALUE: staking/types.Delegation

func GetDelegationsKey

func GetDelegationsKey(delAddr sdk.AccAddress) []byte

gets the prefix for a delegator for all validators

func GetLastValidatorPowerKey

func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte

get the bonded validator index key for an operator address

func GetREDByValDstIndexKey

func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) []byte

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

func GetREDByValSrcIndexKey

func GetREDByValSrcIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) []byte

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

func GetREDKey

func GetREDKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) []byte

gets the key for a redelegation VALUE: staking/types.RedelegationKey

组装 重置委托的 key

func GetREDKeyFromValDstIndexKey

func GetREDKeyFromValDstIndexKey(indexKey []byte) []byte

GetREDKeyFromValDstIndexKey rearranges the ValDstIndexKey to get the REDKey

func GetREDKeyFromValSrcIndexKey

func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte

GetREDKeyFromValSrcIndexKey rearranges the ValSrcIndexKey to get the REDKey

func GetREDsByDelToValDstIndexKey

func GetREDsByDelToValDstIndexKey(delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) []byte

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

func GetREDsFromValSrcIndexKey

func GetREDsFromValSrcIndexKey(valSrcAddr sdk.ValAddress) []byte

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

func GetREDsKey

func GetREDsKey(delAddr sdk.AccAddress) []byte

gets the prefix keyspace for redelegations from a delegator

func GetREDsToValDstIndexKey

func GetREDsToValDstIndexKey(valDstAddr sdk.ValAddress) []byte

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

func GetRedelegationTimeKey

func GetRedelegationTimeKey(timestamp time.Time) []byte

gets the prefix for all unbonding delegations from a delegator

func GetUBDByValIndexKey

func GetUBDByValIndexKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

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

返回某个验证人身上某个解除了委托的委托信息

prefix + val + del -> ubd info 的 key (解除了委托的委托信息的 key)

func GetUBDKey

func GetUBDKey(delAddr sdk.AccAddress, valAddr sdk.ValAddress) []byte

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

func GetUBDKeyFromValIndexKey

func GetUBDKeyFromValIndexKey(IndexKey []byte) []byte

rearranges the ValIndexKey to get the UBDKey

func GetUBDsByValIndexKey

func GetUBDsByValIndexKey(valAddr sdk.ValAddress) []byte

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

获取某个验证人的下属所有解除委托的信息的 key

prefix + val

func GetUBDsKey

func GetUBDsKey(delAddr sdk.AccAddress) []byte

gets the prefix for all unbonding delegations from a delegator

func GetUnbondingDelegationTimeKey

func GetUnbondingDelegationTimeKey(timestamp time.Time) []byte

gets the prefix for all unbonding delegations from a delegator

func GetValidatorByConsAddrKey

func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte

gets the key for the validator with pubkey VALUE: validator operator address ([]byte)

func GetValidatorKey

func GetValidatorKey(operatorAddr sdk.ValAddress) []byte

gets the key for the validator with address VALUE: staking/types.Validator

func GetValidatorQueueTimeKey

func GetValidatorQueueTimeKey(timestamp time.Time) []byte

gets the prefix for all unbonding delegations from a delegator

func GetValidatorsByPowerIndexKey

func GetValidatorsByPowerIndexKey(validator types.Validator) []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 operator address ([]byte) * 通过幂指数获得验证人。 权重索引就是在db中的key的位置?,并且表示验证人的相对权重等级。 VALUE:验证人的地址([] byte)

func MakeTestCodec

func MakeTestCodec() *codec.Codec

create a codec used only for testing

func NewPubKey

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

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamTable for staking module

func RandomBondedValidator

func RandomBondedValidator(r *rand.Rand, keeper Keeper, ctx sdk.Context) types.Validator

RandomBondedValidator returns a random bonded validator given access to the keeper and ctx

func RandomValidator

func RandomValidator(r *rand.Rand, keeper Keeper, ctx sdk.Context) types.Validator

RandomValidator returns a random validator given access to the keeper and ctx

func TestAddr

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

for incode address generation

func TestingUpdateValidator

func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator

update validator for testing

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 staking store * 经济模型的 管理器 (这个东西是全局的)

func CreateTestInput

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

Hogpodge of all sorts of input required for testing. `initPower` is converted to an amount of tokens. If `initPower` is 0, no addrs get created.

func NewKeeper

func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, bk types.BankKeeper,
	paramstore params.Subspace, codespace sdk.CodespaceType) Keeper

func (Keeper) AddValidatorTokensAndShares

func (k Keeper) AddValidatorTokensAndShares(ctx sdk.Context, validator types.Validator,
	tokensToAdd sdk.Int) (valOut types.Validator, addedShares sdk.Dec)

Update the tokens of an existing validator, update the validators power index key 追加 验证人的token 和 被委托的股权

func (Keeper) AfterDelegationModified

func (k Keeper) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

AfterDelegationModified - call hook if registered

func (Keeper) AfterValidatorBeginUnbonding

func (k Keeper) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

AfterValidatorBeginUnbonding - call hook if registered

func (Keeper) AfterValidatorBonded

func (k Keeper) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

AfterValidatorBonded - call hook if registered

func (Keeper) AfterValidatorCreated

func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress)

AfterValidatorCreated - call hook if registered

func (Keeper) AfterValidatorRemoved

func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress)

AfterValidatorRemoved - call hook if registered

func (Keeper) ApplyAndReturnValidatorSetUpdates

func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []abci.ValidatorUpdate)

Apply and return accumulated updates to the bonded validator set. Also, * Updates the active valset as keyed by LastValidatorPowerKey. * Updates the total power as keyed by LastTotalPowerKey. * Updates validator status' according to updated powers. * Updates the fee pool bonded vs not-bonded tokens. * Updates relevant indices. It gets called once after genesis, another time maybe after genesis transactions, then once at every EndBlock.

CONTRACT: Only validators with non-zero power or zero-power that were bonded at the previous block height or were removed from the validator set entirely are returned to Tendermint. * TODO 重要的 函数 【验证人更新】 将累积的更新应用并返回到绑定的验证器集。 也, * 更新LastValidatorPowerKey 为key 的活动valset (验证人集合)。 * 更新LastTotalPowerKey 为key的总权重。 * 根据更新的权力更新验证者状态。 * 更新绑定的费用池与未绑定的令牌。 * 更新相关指数。 todo 选验证人 选举验证人

func (Keeper) BeforeDelegationCreated

func (k Keeper) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

BeforeDelegationCreated - call hook if registered 创建新委托详情之前,需要做的事

func (Keeper) BeforeDelegationRemoved

func (k Keeper) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

BeforeDelegationRemoved - call hook if registered

func (Keeper) BeforeDelegationSharesModified

func (k Keeper) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)

BeforeDelegationSharesModified - call hook if registered TODO 这一步超级重要 逻辑非常多 这个函数主要处理的是 withdrawDelegationRewards

func (Keeper) BeforeValidatorModified

func (k Keeper) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress)

BeforeValidatorModified - call hook if registered

func (Keeper) BeforeValidatorSlashed

func (k Keeper) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec)

BeforeValidatorSlashed - call hook if registered

func (Keeper) BeginRedelegation

func (k Keeper) BeginRedelegation(ctx sdk.Context, delAddr sdk.AccAddress,
	valSrcAddr, valDstAddr sdk.ValAddress, sharesAmount sdk.Dec) (
	completionTime time.Time, errSdk sdk.Error)

begin unbonding / redelegation; create a redelegation record 开始解除锁定/重新授权; 创建一个重新授权记录 TODO (重置委托)

valSrcAddr: 原来的验证人 valDstAddr: 新的验证人

func (Keeper) BondDenom

func (k Keeper) BondDenom(ctx sdk.Context) (res string)

BondDenom - Bondable coin denomination 先获取 可以给予 绑定的钱的面额

func (Keeper) BondedRatio

func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec

the fraction of the staking tokens which are currently bonded

func (Keeper) Codespace

func (k Keeper) Codespace() sdk.CodespaceType

return the codespace

func (Keeper) CompleteRedelegation

func (k Keeper) CompleteRedelegation(ctx sdk.Context, delAddr sdk.AccAddress,
	valSrcAddr, valDstAddr sdk.ValAddress) sdk.Error

CompleteRedelegation completes the unbonding of all mature entries in the retrieved unbonding delegation object. * CompleteRedelegation完成取消 委托检索到的未绑定委托对象中的所有成熟条目。

func (Keeper) CompleteUnbonding

func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress,
	valAddr sdk.ValAddress) sdk.Error

CompleteUnbonding completes the unbonding of all mature entries in the retrieved unbonding delegation object. * CompleteUnbonding完成了对检索到的解除委托对象中所有成熟条目的取消委托。 TODO 真正去处理解除委托退款的

func (Keeper) Delegate

func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Int,
	validator types.Validator, subtractAccount bool) (newShares sdk.Dec, err sdk.Error)

Perform a delegation, set/update everything necessary within the store. * 执行委托,设置/更新 store 中的所需一切。

这个方法是 自委托 和被委托 都走的

func (Keeper) Delegation

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

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

func (Keeper) DeleteLastValidatorPower

func (k Keeper) DeleteLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress)

Delete the last validator power.

func (Keeper) DeleteValidatorByPowerIndex

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

validator index TODO 删除 对应权重的 验证人

func (Keeper) DeleteValidatorQueue

func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator)

Delete a validator address from the validator queue

func (Keeper) DeleteValidatorQueueTimeSlice

func (k Keeper) DeleteValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time)

Deletes a specific validator queue timeslice.

func (Keeper) DequeueAllMatureRedelegationQueue

func (k Keeper) DequeueAllMatureRedelegationQueue(ctx sdk.Context, currTime time.Time) (matureRedelegations []types.DVVTriplet)

Returns a concatenated list of all the timeslices inclusively previous to currTime, and deletes the timeslices from the queue

func (Keeper) DequeueAllMatureUBDQueue

func (k Keeper) DequeueAllMatureUBDQueue(ctx sdk.Context,
	currTime time.Time) (matureUnbonds []types.DVPair)

Returns a concatenated list of all the timeslices inclusively previous to currTime, and deletes the timeslices from the queue

func (Keeper) GetAllDelegations

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

return all delegations used during genesis dump 返回在Genesis dump期间使用的所有委托人集

func (Keeper) GetAllDelegatorDelegations

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

return all delegations for a delegator

func (Keeper) GetAllMatureValidatorQueue

func (k Keeper) GetAllMatureValidatorQueue(ctx sdk.Context, currTime time.Time) (matureValsAddrs []sdk.ValAddress)

Returns a concatenated list of all the timeslices before currTime, and deletes the timeslices from the queue

func (Keeper) GetAllRedelegations

func (k Keeper) GetAllRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
	srcValAddress, dstValAddress sdk.ValAddress) (
	redelegations []types.Redelegation)

return all redelegations for a delegator

func (Keeper) GetAllSDKDelegations

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

return all delegations used during genesis dump TODO: remove this func, change all usage for iterate functionality

func (Keeper) GetAllUnbondingDelegations

func (k Keeper) GetAllUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress) (
	unbondingDelegations []types.UnbondingDelegation)

return all unbonding-delegations for a delegator

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

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

get the current group of bonded validators sorted by power-rank

func (Keeper) GetDelegation

func (k Keeper) GetDelegation(ctx sdk.Context,
	delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
	delegation types.Delegation, found bool)

return a specific delegation 返回指定的委托人

func (Keeper) GetDelegatorDelegations

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

return a given amount of all the delegations from a delegator

func (Keeper) GetDelegatorValidator

func (k Keeper) GetDelegatorValidator(ctx sdk.Context, delegatorAddr sdk.AccAddress,
	validatorAddr sdk.ValAddress) (validator types.Validator, err sdk.Error)

return a validator that a delegator is bonded to

func (Keeper) GetDelegatorValidators

func (k Keeper) GetDelegatorValidators(ctx sdk.Context, delegatorAddr sdk.AccAddress,
	maxRetrieve uint16) (validators []types.Validator)

Return all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.

func (Keeper) GetLastTotalPower

func (k Keeper) GetLastTotalPower(ctx sdk.Context) (power sdk.Int)

Load the last total validator power.

func (Keeper) GetLastValidatorPower

func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) (power int64)

Load the last validator power. Returns zero if the operator was not a validator last block.

func (Keeper) GetLastValidators

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

get the group of the bonded validators

func (Keeper) GetParams

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

Get all parameteras as types.Params

func (Keeper) GetPool

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

get the pool 获取 Pool 实例 Pool 记录这目前与验证人锁定和未锁定的流通 币数目

func (Keeper) GetRedelegation

func (k Keeper) GetRedelegation(ctx sdk.Context,
	delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) (red types.Redelegation, found bool)

return a redelegation

func (Keeper) GetRedelegationQueueTimeSlice

func (k Keeper) GetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (dvvTriplets []types.DVVTriplet)

Gets a specific redelegation queue timeslice. A timeslice is a slice of DVVTriplets corresponding to redelegations that expire at a certain time.

func (Keeper) GetRedelegations

func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
	maxRetrieve uint16) (redelegations []types.Redelegation)

return a given amount of all the delegator redelegations

func (Keeper) GetRedelegationsFromValidator

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

return all redelegations from a particular validator

func (Keeper) GetUBDQueueTimeSlice

func (k Keeper) GetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (dvPairs []types.DVPair)

gets a specific unbonding queue timeslice. A timeslice is a slice of DVPairs corresponding to unbonding delegations that expire at a certain time.

func (Keeper) GetUnbondingDelegation

func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
	delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd types.UnbondingDelegation, found bool)

return a unbonding delegation 返回一个解锁的 委托人

func (Keeper) GetUnbondingDelegations

func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress,
	maxRetrieve uint16) (unbondingDelegations []types.UnbondingDelegation)

return a given amount of all the delegator unbonding-delegations

func (Keeper) GetUnbondingDelegationsFromValidator

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

return all unbonding delegations from a particular validator

收集 某个验证人的所有已经解除了委托的委托信息

func (Keeper) GetValidator

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

################ ################ #### 十分重要 ### get a single validator 查询单个 验证人信息

func (Keeper) GetValidatorByConsAddr

func (k Keeper) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (validator types.Validator, found bool)

get a single validator by consensus address

func (Keeper) GetValidatorDelegations

func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress) (delegations []types.Delegation)

return all delegations to a specific validator. Useful for querier.

func (Keeper) GetValidatorQueueTimeSlice

func (k Keeper) GetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (valAddrs []sdk.ValAddress)

gets a specific validator queue timeslice. A timeslice is a slice of ValAddresses corresponding to unbonding validators that expire at a certain time.

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 uint16) (validators []types.Validator)

return a given amount of all the validators

func (Keeper) HasMaxRedelegationEntries

func (k Keeper) HasMaxRedelegationEntries(ctx sdk.Context,
	delegatorAddr sdk.AccAddress, validatorSrcAddr,
	validatorDstAddr sdk.ValAddress) bool

HasMaxRedelegationEntries - redelegation has maximum number of entries redelegation具有最大条目数

func (Keeper) HasMaxUnbondingDelegationEntries

func (k Keeper) HasMaxUnbondingDelegationEntries(ctx sdk.Context,
	delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) bool

HasMaxUnbondingDelegationEntries - check if unbonding delegation has maximum number of entries 检查unbonding委托是否有最大条目数

func (Keeper) HasReceivingRedelegation

func (k Keeper) HasReceivingRedelegation(ctx sdk.Context,
	delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool

check if validator is receiving a redelegation

func (Keeper) InflateSupply

func (k Keeper) InflateSupply(ctx sdk.Context, newTokens sdk.Int)

when minting new tokens

func (Keeper) InsertRedelegationQueue

func (k Keeper) InsertRedelegationQueue(ctx sdk.Context, red types.Redelegation,
	completionTime time.Time)

Insert an redelegation delegation to the appropriate timeslice in the redelegation queue

func (Keeper) InsertUBDQueue

func (k Keeper) InsertUBDQueue(ctx sdk.Context, ubd types.UnbondingDelegation,
	completionTime time.Time)

Insert an unbonding delegation to the appropriate timeslice in the unbonding queue 将解除委托信息插根据适当时间片插入 解除委托信息 队列, 待后续使用

func (Keeper) InsertValidatorQueue

func (k Keeper) InsertValidatorQueue(ctx sdk.Context, val types.Validator)

Insert an validator address to the appropriate timeslice in the validator queue

func (Keeper) IterateBondedValidatorsByPower

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

iterate through the bonded validator set and perform the provided function

func (Keeper) IterateDelegations

func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,

	fn func(index int64, del sdk.Delegation) (stop bool))

iterate through all of the delegations from a delegator

迭代委托人的所有委托信息

func (Keeper) IterateLastValidatorPowers

func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context, handler func(operator sdk.ValAddress, power int64) (stop bool))

Iterate over last validator powers.

func (Keeper) IterateLastValidators

func (k Keeper) IterateLastValidators(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) IterateRedelegations

func (k Keeper) IterateRedelegations(ctx sdk.Context, fn func(index int64, red types.Redelegation) (stop bool))

iterate through all redelegations

func (Keeper) IterateUnbondingDelegations

func (k Keeper) IterateUnbondingDelegations(ctx sdk.Context, fn func(index int64, ubd types.UnbondingDelegation) (stop bool))

iterate through all of the unbonding delegations

func (Keeper) IterateValidators

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

iterate through the validator set and perform the provided function

func (Keeper) Jail

func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress)

jail a validator * 惩罚锁定 验证人

func (Keeper) LastValidatorsIterator

func (k Keeper) LastValidatorsIterator(ctx sdk.Context) (iterator sdk.Iterator)

returns an iterator for the consensus validators in the last block

func (Keeper) MaxEntries

func (k Keeper) MaxEntries(ctx sdk.Context) (res uint16)

MaxEntries - Maximum number of simultaneous unbonding delegations or redelegations (per pair/trio) * MaxEntries - 委托人 同时取消委托的最大数量 授权或重新授权(每对/三重奏)

func (Keeper) MaxValidators

func (k Keeper) MaxValidators(ctx sdk.Context) (res uint16)

MaxValidators - Maximum number of validators

func (Keeper) RedelegationQueueIterator

func (k Keeper) RedelegationQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

Returns all the redelegation queue timeslices from time 0 until endTime

func (Keeper) RemoveDelegation

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

remove a 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.ValAddress)

remove the validator record and associated indexes except for the bonded validator index which is only handled in ApplyAndReturnTendermintUpdates

func (Keeper) RemoveValidatorTokens

func (k Keeper) RemoveValidatorTokens(ctx sdk.Context,
	validator types.Validator, tokensToRemove sdk.Int) types.Validator

Update the tokens of an existing validator, update the validators power index key

func (Keeper) RemoveValidatorTokensAndShares

func (k Keeper) RemoveValidatorTokensAndShares(ctx sdk.Context, validator types.Validator,
	sharesToRemove sdk.Dec) (valOut types.Validator, removedTokens sdk.Int)

Update the tokens of an existing validator, update the validators power index key 更新当前 验证人身上的钱 更新当前验证人的权重索引信息

func (Keeper) SetDelegation

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

set a delegation

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(sh sdk.StakingHooks) *Keeper

Set the validator hooks

func (Keeper) SetLastTotalPower

func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int)

Set the last total validator power. 设置最新的所有验证人总权重信息

func (Keeper) SetLastValidatorPower

func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power int64)

Set the last validator power. TODO 设置 验证人的最新的权重信息

func (Keeper) SetNewValidatorByPowerIndex

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

validator index 按照 权重规则将验证人写入DB

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

func (k Keeper) SetRedelegationEntry(ctx sdk.Context,
	delegatorAddr sdk.AccAddress, validatorSrcAddr,
	validatorDstAddr sdk.ValAddress, creationHeight int64,
	minTime time.Time, balance sdk.Int,
	sharesSrc, sharesDst sdk.Dec) types.Redelegation

SetUnbondingDelegationEntry adds an entry to the unbonding delegation at the given addresses. It creates the unbonding delegation if it does not exist

func (Keeper) SetRedelegationQueueTimeSlice

func (k Keeper) SetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVVTriplet)

Sets a specific redelegation queue timeslice.

func (Keeper) SetUBDQueueTimeSlice

func (k Keeper) SetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVPair)

Sets a specific unbonding queue timeslice.

func (Keeper) SetUnbondingDelegation

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

set the unbonding delegation and associated index

func (Keeper) SetUnbondingDelegationEntry

func (k Keeper) SetUnbondingDelegationEntry(ctx sdk.Context,
	delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
	creationHeight int64, minTime time.Time, balance sdk.Int) types.UnbondingDelegation

SetUnbondingDelegationEntry adds an entry to the unbonding delegation at the given addresses. It creates the unbonding delegation if it does not exist * SetUnbondingDelegationEntry

添加一个 减持委托的条目

func (Keeper) SetValidator

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

set the main record holding validator details 设置包含验证人详细信息的主记录 (说白了就是 写入DB) TODO 奇怪, 这里不需要更新全局的 keeper 中的两个验证人相关的缓存 ??? TODO 注意: 在 GetValidator 方法 里面有从两个缓存拿 验证人的逻辑 !!! TODO 好好看看 GetValidator 就知道了,缓存是会在这个方法中更新的, key是 最新的 验证人信息的 []byte

func (Keeper) SetValidatorByConsAddr

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

validator index

func (Keeper) SetValidatorByPowerIndex

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

validator index 更新 对应权重的验证人

func (Keeper) SetValidatorQueueTimeSlice

func (k Keeper) SetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []sdk.ValAddress)

Sets a specific validator queue timeslice.

func (Keeper) Slash

func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec)

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 delegations & redelegations appropriately

CONTRACT:

slashFactor is non-negative

CONTRACT:

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

CONTRACT:

Slash will not slash unbonded validators (for the above reason)

CONTRACT:

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

TODO 惩罚 实施

TODO 惩罚所扣除的钱是直接扣减 委托人和验证人的钱,但是这部分钱并没有被转到某个还在账户,而是直接减掉(等于 销毁了)

func (Keeper) TotalBondedTokens

func (k Keeper) TotalBondedTokens(ctx sdk.Context) sdk.Int

total staking tokens supply which is bonded 返回 pool 中记录的,目前所有 staking 锁定的 token数目

func (Keeper) TotalTokens

func (k Keeper) TotalTokens(ctx sdk.Context) sdk.Int

total staking tokens supply bonded and unbonded

func (Keeper) UBDQueueIterator

func (k Keeper) UBDQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

Returns all the unbonding queue timeslices from time 0 until endTime 返回从某个时间的 解除委托的申请条目

func (Keeper) UnbondAllMatureValidatorQueue

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

Unbonds all the unbonding validators that have finished their unbonding period 解锁所有完成 需要解锁期的 需要解锁验证器

func (Keeper) UnbondingTime

func (k Keeper) UnbondingTime(ctx sdk.Context) (res time.Duration)

UnbondingTime

func (Keeper) Undelegate

func (k Keeper) Undelegate(ctx sdk.Context, delAddr sdk.AccAddress,
	valAddr sdk.ValAddress, sharesAmount sdk.Dec) (completionTime time.Time, sdkErr sdk.Error)

begin unbonding part or all of a delegation 开始解除部分或全部全部的委托 TODO 超级重要的一步

func (Keeper) Unjail

func (k Keeper) Unjail(ctx sdk.Context, consAddr sdk.ConsAddress)

unjail a validator * 解除惩罚锁定

func (Keeper) UpdateValidatorCommission

func (k Keeper) UpdateValidatorCommission(ctx sdk.Context,
	validator types.Validator, newRate sdk.Dec) (types.Commission, sdk.Error)

UpdateValidatorCommission attempts to update a validator's commission rate. An error is returned if the new commission rate is invalid. * UpdateValidatorCommission尝试更新验证者的佣金率。 如果新佣金率无效,则会返回错误。

func (Keeper) Validator

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

get the sdk.validator for a particular address 从全局 Keeper 中获取 validator 无 则拉DB 的且缓存到 Keeper 中 有 则直接返回

func (Keeper) ValidatorByConsAddr

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

get the sdk.validator for a particular pubkey

func (Keeper) ValidatorQueueIterator

func (k Keeper) ValidatorQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterator

Returns all the validator queue timeslices from time 0 until endTime

func (Keeper) ValidatorsPowerStoreIterator

func (k Keeper) ValidatorsPowerStoreIterator(ctx sdk.Context) (iterator sdk.Iterator)

returns an iterator for the current validator power store TODO 重要的函数 返回根据权重存储的所有验证人的 迭代器

Jump to

Keyboard shortcuts

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