-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
staking.go
109 lines (93 loc) · 5.16 KB
/
staking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package types
import (
"cosmossdk.io/math"
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// Delay, in blocks, between when validator updates are returned to the
// consensus-engine and when they are applied. For example, if
// ValidatorUpdateDelay is set to X, and if a validator set update is
// returned with new validators at the end of block 10, then the new
// validators are expected to sign blocks beginning at block 11+X.
//
// This value is constant as this should not change without a hard fork.
// For CometBFT this should be set to 1 block, for more details see:
// https://github.com/cometbft/cometbft/blob/main/spec/abci/abci%2B%2B_basic_concepts.md#consensusblock-execution-methods
const ValidatorUpdateDelay int64 = 1
var (
// DefaultBondDenom is the default bondable coin denomination (defaults to stake)
// Overwriting this value has the side effect of changing the default denomination in genesis
DefaultBondDenom = "stake"
// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power
DefaultPowerReduction = math.NewIntFromUint64(1000000)
// PubKeyEd25519Type is ed25519 for type the consensus params validator pub_key_types params
PubKeyEd25519Type = "ed25519"
)
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
func TokensToConsensusPower(tokens, powerReduction math.Int) int64 {
return (tokens.Quo(powerReduction)).Int64()
}
// TokensFromConsensusPower - convert input power to tokens
func TokensFromConsensusPower(power int64, powerReduction math.Int) math.Int {
return math.NewInt(power).Mul(powerReduction)
}
// ______________________________________________________________________
// Delegation & Validator Interfaces are moved here to avoid direct dependency on the staking module in expected keeper interfaces
// BondStatus is the status of a validator.
type BondStatus int32
const (
// UNSPECIFIED defines an invalid validator status.
Unspecified BondStatus = 0
// UNBONDED defines a validator that is not bonded.
Unbonded BondStatus = 1
// UNBONDING defines a validator that is unbonding.
Unbonding BondStatus = 2
// BONDED defines a validator that is bonded.
Bonded BondStatus = 3
)
// BondStatus_name is the string representation of BondStatus.
var bondStatus_name = map[int32]string{
0: "BOND_STATUS_UNSPECIFIED",
1: "BOND_STATUS_UNBONDED",
2: "BOND_STATUS_UNBONDING",
3: "BOND_STATUS_BONDED",
}
func (x BondStatus) String() string {
return bondStatus_name[int32(x)]
}
// DelegationI delegation bond for a delegated proof of stake system
type DelegationI interface {
GetDelegatorAddr() string // delegator string for the bond
GetValidatorAddr() string // validator operator address
GetShares() math.LegacyDec // amount of validator's shares held in this delegation
}
// ValidatorI expected validator functions
type ValidatorI interface {
IsJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
IsBonded() bool // check if has a bonded status
IsUnbonded() bool // check if has status unbonded
IsUnbonding() bool // check if has status unbonding
GetOperator() string // operator address to receive/return validators coins
ConsPubKey() (cryptotypes.PubKey, error) // validation consensus pubkey (cryptotypes.PubKey)
GetConsAddr() ([]byte, error) // validation consensus address
GetTokens() math.Int // validation tokens
GetBondedTokens() math.Int // validator bonded tokens
GetConsensusPower(math.Int) int64 // validation power in CometBFT
GetCommission() math.LegacyDec // validator commission rate
GetMinSelfDelegation() math.Int // validator minimum self delegation
GetDelegatorShares() math.LegacyDec // total outstanding delegator shares
TokensFromShares(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares
TokensFromSharesTruncated(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, truncated
TokensFromSharesRoundUp(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, rounded up
SharesFromTokens(amt math.Int) (math.LegacyDec, error) // shares worth of delegator's bond
SharesFromTokensTruncated(amt math.Int) (math.LegacyDec, error) // truncated shares worth of delegator's bond
}
// GenesisValidator is an initial validator.
type GenesisValidator struct {
Address ConsAddress `json:"address"`
PubKey cryptokeys.JSONPubkey `json:"pub_key"`
Power int64 `json:"power"`
Name string `json:"name"`
}