-
Notifications
You must be signed in to change notification settings - Fork 28
Staking Notes
- New
Validator
entry is created and written in store. - New
Delegation
entry is added in store. - Tokens are transfered from Delegator account to module account (
BondedPool
module account orNotBondedPool
module acount). - Delegation amount is added to
Validator.Tokens
.
x/staking/keeper/msg_server.go CreateValidator()
x/staking/keeper/delegation.go Delegate()
-
Find/Create
Delegation
from store, identifier (DelegatorAddr
,ValidatorOperator
) -
subtractAccount == true
-
k.bankKeeper.DelegateCoinsFromAccountToModule()
: Remove tokens from Delegator, add tokens to module account-
Validator.IsBonded
: Tokens from Delegator account sent toBondedPool
module account -
Validator.IsUnbonded
ORValidator.IsUnbonding
(Validator Not Bonded): Tokens from Delegator account sent toNotBondedPool
module account
-
-
k.AddValidatorTokensAndShares()
: add tokens and shares onValidator
in store -
Update
Delegation
in store
Pretty much the same as the MsgCreateValidator
. Except not doing Validator initial setup.
- New
Delegation
entry is added in store. - Tokens are transfered from Delegator account to module account (
BondedPool
module account orNotBondedPool
module acount). - Delegation amount is added to
Validator.Tokens
(AKAValidatorOperator
account).
- Delete/Update existing
Delegation
entry on SrcValidator in store. - Create/Update
Delegation
entry on DstValidator in store. - Tokens are still in module accounts, transfer may happen between these module accounts (
BondedPool
module account orNotBondedPool
module acount). - Redelegation amount is removed from source
Validator.Tokens
. - Redelegation amount is added to destination
Validator.Tokens
. - Redelegation entry is inserted to
RedelegationQueue
.
x/staking/keeper/delegation.go BeginRedelegation()
- Get
Delegation
entry from store, identifier (DelegatorAddr
,SrcValidatorOperator
) - Get
SrcValidator
from store. - Delete shares on
Delegation
entry. - Delete/Update
Delegation
in store. -
k.RemoveValidatorTokensAndShares()
: remove tokens and shares onSrcValidator
, updateSrcValidator
in store.
-
Find/Create
Delegation
from store, identifier (DelegatorAddr
,DstValidatorOperator
) -
subtractAccount == false
:
-
SrcValidator
Not Bonded ->DstValidator
Bonded: sent tokens fromNotBondedPool
toBondedPool
module account -
SrcValidator
Bonded ->DstValidator
Not Bonded: sent tokens fromBondedPool
toNotBondedPool
module account - Other cases, do nothing
- Undefined case, panic
-
k.AddValidatorTokensAndShares()
: add tokens and shares onDstValidator
in store -
Update
Delegation
in store
Calculate completion time for RedelegationQueueEntry
-
Validator.IsBonded
: Wait for A full unbonding time (longest wait) -
Validator.IsUnbonded
: Compelte right away -
Validator.IsUnbonding
: Wait until validator is unbonding is done
- Add
Redelegation
entry toRedelegationQueue
.
- Delete/Update existing
Delegation
entry on Validator in store. - Tokens are still in module accounts, transfer may happen between these module accounts (
BondedPool
module account orNotBondedPool
module acount). - Undelegation amount is removed from
Validator.Tokens
. - UnbondingDelegation entry is inserted to
UnbondingDelegationQueue
.
The tokens are removed from Validator (instantly). But only when it is complete (mature), the tokens will be sent back to delegator.
x/staking/keeper/msg_server.go Undelegate()
-
k.Keeper.Undelegate()
:x/staking/keeper/delegation.go Undelegate()
- Get
Delegation
entry from store, identifier (DelegatorAddr
,ValidatorOperator
) - Get
Validator
in store. - Delete shares on
Delegation
entry. - Delete/Update
Delegation
onValidator
in store. -
k.RemoveValidatorTokensAndShares()
: remove tokens and shares onValidator
, updateValidator
in store.
k.bondedTokensToNotBonded()
: sent tokens from BondedPool
module account to NotBondedPool
module account.
Add UnbondingDelegation
entry to UnbondingDelegationQueue
.
x/staking/abci.go EndBlocker()
x/staking/keeper/val_state_change.go BlockValidatorUpdates()
Mature UnBonding Entry will trigger transfer of tokens, from NotBondedPool
module account to Delegator
account.
x/staking/keeper/delegation.go CompleteUnbonding()
k.bankKeeper.UndelegateCoinsFromModuleToAccount()
It is just deleting those entries, not moving funds in any account.
x/staking/keeper/delegation.go CompleteRedelegation()