/
governance_params.go
194 lines (165 loc) · 6.1 KB
/
governance_params.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright 2019 The klaytn Authors
// This file is part of the klaytn library.
//
// The klaytn library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The klaytn library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
package params
import (
"math/big"
"sync/atomic"
)
const (
// Because we need int64 type to allocate big.Int, define these parameters as int64 type.
// In addition, let's define these constants in ston instead of peb, because int64 can hold
// up to about 9*10^18 in golang.
// TODO-Klaytn-Issue1587 Decide whether to remove below three variables after discussing token economy policy for service chain and private network
rewardContractIncentiveInSton int64 = 3200000000 // 3.2 KLAY for Reward contract (Unit: ston)
kirContractIncentiveInSton int64 = 3200000000 // 3.2 KLAY for KIR contract (Unit: ston)
pocContractIncentiveInSton int64 = 3200000000 // 3.2 KLAY for PoC contract (Unit: ston)
defaultMintedKLAYInSton int64 = 9600000000 // Default amount of minted KLAY. 9.6 KLAY for block reward (Unit: ston)
defaultMinimumStakingAmountInKlay int64 = 5000000 // Default amount of minimum staking (Unit: KLAY)
DefaultCNRewardRatio = 34 // Default CN reward ratio 34%
DefaultPoCRewardRatio = 54 // Default PoC ratio 54%
DefaultKIRRewardRatio = 12 // Default KIR ratio 12%
)
var (
// TODO-Klaytn-Issue1587 Decide whether to remove below three variables after discussing token economy policy for service chain and private network
RewardContractIncentive = big.NewInt(0).Mul(big.NewInt(rewardContractIncentiveInSton), big.NewInt(Ston))
KIRContractIncentive = big.NewInt(0).Mul(big.NewInt(kirContractIncentiveInSton), big.NewInt(Ston))
PoCContractIncentive = big.NewInt(0).Mul(big.NewInt(pocContractIncentiveInSton), big.NewInt(Ston))
DefaultMintedKLAY = big.NewInt(0).Mul(big.NewInt(defaultMintedKLAYInSton), big.NewInt(Ston))
// TODO-Governance remove below minimum staking amount parameter
defaultMinimumStakingAmount = big.NewInt(0).Mul(big.NewInt(defaultMinimumStakingAmountInKlay), big.NewInt(KLAY))
minimumStakingAmount atomic.Value
stakingUpdateInterval uint64 = 86400 // About 1 day. 86400 blocks = (24 hrs) * (3600 secs/hr) * (1 block/sec)
proposerUpdateInterval uint64 = 3600 // About 1 hour. 3600 blocks = (1 hr) * (3600 secs/hr) * (1 block/sec)
)
const (
// Block reward will be separated by three pieces and distributed
RewardSliceCount = 3
// GovernanceConfig is stored in a cache which has below capacity
GovernanceCacheLimit = 512
GovernanceIdxCacheLimit = 1000
// The prefix for governance cache
GovernanceCachePrefix = "governance"
)
type EngineType int
const (
// Engine type
UseIstanbul EngineType = iota
UseClique
Unknown
)
const (
// Governance Key
GovernanceMode int = iota
GoverningNode
Epoch
Policy
CommitteeSize
UnitPrice
MintingAmount
Ratio
UseGiniCoeff
DeferredTxFee
MinimumStake
AddValidator
RemoveValidator
StakeUpdateInterval
ProposerRefreshInterval
ConstTxGasHumanReadable
CliqueEpoch
Timeout
)
const (
GovernanceMode_None = iota
GovernanceMode_Single
GovernanceMode_Ballot
)
const (
// Proposer policy
// At the moment this is duplicated in istanbul/config.go, not to make a cross reference
// TODO-Klatn-Governance: Find a way to manage below constants at single location
RoundRobin = iota
Sticky
WeightedRandom
)
const (
// Default Values: Constants used for getting default values for configuration
DefaultGovernanceMode = "none"
DefaultGoverningNode = "0x0000000000000000000000000000000000000000"
DefaultEpoch = uint64(604800)
DefaultProposerPolicy = uint64(0)
DefaultSubGroupSize = uint64(21)
DefaultMintingAmount = 0
DefaultRatio = "100/0/0"
DefaultUseGiniCoeff = false
DefaultDefferedTxFee = false
DefaultUnitPrice = uint64(250000000000)
DefaultPeriod = 1
)
func IsStakingUpdateInterval(blockNum uint64) bool {
return (blockNum % StakingUpdateInterval()) == 0
}
// CalcStakingBlockNumber returns number of block which contains staking information required to make a new block with blockNum.
func CalcStakingBlockNumber(blockNum uint64) uint64 {
stakingInterval := StakingUpdateInterval()
if blockNum <= 2*stakingInterval {
// Just return genesis block number.
return 0
}
var number uint64
if (blockNum % stakingInterval) == 0 {
number = blockNum - 2*stakingInterval
} else {
number = blockNum - stakingInterval - (blockNum % stakingInterval)
}
return number
}
func IsProposerUpdateInterval(blockNum uint64) (bool, uint64) {
proposerInterval := ProposerUpdateInterval()
return (blockNum % proposerInterval) == 0, proposerInterval
}
// CalcProposerBlockNumber returns number of block where list of proposers is updated for block blockNum
func CalcProposerBlockNumber(blockNum uint64) uint64 {
var number uint64
if isInterval, proposerInterval := IsProposerUpdateInterval(blockNum); isInterval {
number = blockNum - proposerInterval
} else {
number = blockNum - (blockNum % proposerInterval)
}
return number
}
func SetStakingUpdateInterval(num uint64) {
atomic.StoreUint64(&stakingUpdateInterval, num)
}
func StakingUpdateInterval() uint64 {
ret := atomic.LoadUint64(&stakingUpdateInterval)
return ret
}
func SetProposerUpdateInterval(num uint64) {
atomic.StoreUint64(&proposerUpdateInterval, num)
}
func ProposerUpdateInterval() uint64 {
ret := atomic.LoadUint64(&proposerUpdateInterval)
return ret
}
func SetMinimumStakingAmount(val *big.Int) {
minimumStakingAmount.Store(val)
}
func MinimumStakingAmount() *big.Int {
if m, ok := minimumStakingAmount.Load().(*big.Int); ok {
return m
}
return defaultMinimumStakingAmount
}