github.com/klaytn/klaytn@v1.10.2/params/governance_params.go (about) 1 // Copyright 2019 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The klaytn library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package params 18 19 import ( 20 "math/big" 21 "sync/atomic" 22 ) 23 24 var ( 25 stakingUpdateInterval uint64 = DefaultStakeUpdateInterval 26 proposerUpdateInterval uint64 = DefaultProposerRefreshInterval 27 ) 28 29 const ( 30 // Block reward will be separated by three pieces and distributed 31 RewardSliceCount = 3 32 RewardKip82SliceCount = 2 33 // GovernanceConfig is stored in a cache which has below capacity 34 GovernanceCacheLimit = 512 35 GovernanceIdxCacheLimit = 1000 36 // The prefix for governance cache 37 GovernanceCachePrefix = "governance" 38 ) 39 40 const ( 41 // Governance Key 42 GovernanceMode int = iota 43 GoverningNode 44 Epoch 45 Policy 46 CommitteeSize 47 UnitPrice 48 MintingAmount 49 Ratio 50 UseGiniCoeff 51 DeferredTxFee 52 MinimumStake 53 AddValidator 54 RemoveValidator 55 StakeUpdateInterval 56 ProposerRefreshInterval 57 ConstTxGasHumanReadable 58 CliqueEpoch 59 Timeout 60 LowerBoundBaseFee 61 UpperBoundBaseFee 62 GasTarget 63 MaxBlockGasUsedForBaseFee 64 BaseFeeDenominator 65 GovParamContract 66 Kip82Ratio 67 DeriveShaImpl 68 ) 69 70 const ( 71 GovernanceMode_None = iota 72 GovernanceMode_Single 73 GovernanceMode_Ballot 74 ) 75 76 const ( 77 // Proposer policy 78 // At the moment this is duplicated in istanbul/config.go, not to make a cross reference 79 // TODO-Klatn-Governance: Find a way to manage below constants at single location 80 RoundRobin = iota 81 Sticky 82 WeightedRandom 83 ) 84 85 var ( 86 // Default Values: Constants used for getting default values for configuration 87 DefaultGovernanceMode = "none" 88 DefaultGoverningNode = "0x0000000000000000000000000000000000000000" 89 DefaultGovParamContract = "0x0000000000000000000000000000000000000000" 90 DefaultEpoch = uint64(604800) 91 DefaultProposerPolicy = uint64(RoundRobin) 92 DefaultSubGroupSize = uint64(21) 93 DefaultUnitPrice = uint64(250000000000) 94 DefaultLowerBoundBaseFee = uint64(25000000000) 95 DefaultUpperBoundBaseFee = uint64(750000000000) 96 DefaultGasTarget = uint64(30000000) 97 DefaultMaxBlockGasUsedForBaseFee = uint64(60000000) 98 DefaultBaseFeeDenominator = uint64(20) 99 DefaultMintingAmount = big.NewInt(0) 100 DefaultRatio = "100/0/0" 101 DefaultKip82Ratio = "20/80" 102 DefaultUseGiniCoeff = false 103 DefaultDefferedTxFee = false 104 DefaultMinimumStake = big.NewInt(2000000) 105 DefaultStakeUpdateInterval = uint64(86400) // 1 day 106 DefaultProposerRefreshInterval = uint64(3600) // 1 hour 107 DefaultPeriod = uint64(1) 108 DefaultDeriveShaImpl = uint64(0) // Orig 109 ) 110 111 func IsStakingUpdateInterval(blockNum uint64) bool { 112 return (blockNum % StakingUpdateInterval()) == 0 113 } 114 115 // CalcStakingBlockNumber returns number of block which contains staking information required to make a new block with blockNum. 116 func CalcStakingBlockNumber(blockNum uint64) uint64 { 117 stakingInterval := StakingUpdateInterval() 118 if blockNum <= 2*stakingInterval { 119 // Just return genesis block number. 120 return 0 121 } 122 123 var number uint64 124 if (blockNum % stakingInterval) == 0 { 125 number = blockNum - 2*stakingInterval 126 } else { 127 number = blockNum - stakingInterval - (blockNum % stakingInterval) 128 } 129 return number 130 } 131 132 func IsProposerUpdateInterval(blockNum uint64) (bool, uint64) { 133 proposerInterval := ProposerUpdateInterval() 134 return (blockNum % proposerInterval) == 0, proposerInterval 135 } 136 137 // CalcProposerBlockNumber returns number of block where list of proposers is updated for block blockNum 138 func CalcProposerBlockNumber(blockNum uint64) uint64 { 139 var number uint64 140 if isInterval, proposerInterval := IsProposerUpdateInterval(blockNum); isInterval { 141 number = blockNum - proposerInterval 142 } else { 143 number = blockNum - (blockNum % proposerInterval) 144 } 145 return number 146 } 147 148 func SetStakingUpdateInterval(num uint64) { 149 atomic.StoreUint64(&stakingUpdateInterval, num) 150 } 151 152 func StakingUpdateInterval() uint64 { 153 ret := atomic.LoadUint64(&stakingUpdateInterval) 154 return ret 155 } 156 157 func SetProposerUpdateInterval(num uint64) { 158 atomic.StoreUint64(&proposerUpdateInterval, num) 159 } 160 161 func ProposerUpdateInterval() uint64 { 162 ret := atomic.LoadUint64(&proposerUpdateInterval) 163 return ret 164 }