github.com/klaytn/klaytn@v1.12.1/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 CheckpointInterval = 1024 40 ) 41 42 const ( 43 // Governance Key 44 GovernanceMode int = iota 45 GoverningNode 46 Epoch 47 Policy 48 CommitteeSize 49 UnitPrice 50 MintingAmount 51 Ratio 52 UseGiniCoeff 53 DeferredTxFee 54 MinimumStake 55 AddValidator 56 RemoveValidator 57 StakeUpdateInterval 58 ProposerRefreshInterval 59 ConstTxGasHumanReadable 60 CliqueEpoch 61 Timeout 62 LowerBoundBaseFee 63 UpperBoundBaseFee 64 GasTarget 65 MaxBlockGasUsedForBaseFee 66 BaseFeeDenominator 67 GovParamContract 68 Kip82Ratio 69 DeriveShaImpl 70 ) 71 72 const ( 73 GovernanceMode_None = iota 74 GovernanceMode_Single 75 GovernanceMode_Ballot 76 ) 77 78 const ( 79 // Proposer policy 80 // At the moment this is duplicated in istanbul/config.go, not to make a cross reference 81 // TODO-Klatn-Governance: Find a way to manage below constants at single location 82 RoundRobin = iota 83 Sticky 84 WeightedRandom 85 ) 86 87 var ( 88 // Default Values: Constants used for getting default values for configuration 89 DefaultGovernanceMode = "none" 90 DefaultGoverningNode = "0x0000000000000000000000000000000000000000" 91 DefaultGovParamContract = "0x0000000000000000000000000000000000000000" 92 DefaultEpoch = uint64(604800) 93 DefaultProposerPolicy = uint64(RoundRobin) 94 DefaultSubGroupSize = uint64(21) 95 DefaultUnitPrice = uint64(250000000000) 96 DefaultLowerBoundBaseFee = uint64(25000000000) 97 DefaultUpperBoundBaseFee = uint64(750000000000) 98 DefaultGasTarget = uint64(30000000) 99 DefaultMaxBlockGasUsedForBaseFee = uint64(60000000) 100 DefaultBaseFeeDenominator = uint64(20) 101 DefaultMintingAmount = big.NewInt(0) 102 DefaultRatio = "100/0/0" 103 DefaultKip82Ratio = "20/80" 104 DefaultUseGiniCoeff = false 105 DefaultDeferredTxFee = false 106 DefaultMinimumStake = big.NewInt(2000000) 107 DefaultStakeUpdateInterval = uint64(86400) // 1 day 108 DefaultProposerRefreshInterval = uint64(3600) // 1 hour 109 DefaultPeriod = uint64(1) 110 DefaultDeriveShaImpl = uint64(0) // Orig 111 ) 112 113 func IsStakingUpdateInterval(blockNum uint64) bool { 114 return (blockNum % StakingUpdateInterval()) == 0 115 } 116 117 // CalcStakingBlockNumber returns number of block which contains staking information required to make a new block with blockNum. 118 func CalcStakingBlockNumber(blockNum uint64) uint64 { 119 stakingInterval := StakingUpdateInterval() 120 if blockNum <= 2*stakingInterval { 121 // Just return genesis block number. 122 return 0 123 } 124 125 var number uint64 126 if (blockNum % stakingInterval) == 0 { 127 number = blockNum - 2*stakingInterval 128 } else { 129 number = blockNum - stakingInterval - (blockNum % stakingInterval) 130 } 131 return number 132 } 133 134 func IsProposerUpdateInterval(blockNum uint64) (bool, uint64) { 135 proposerInterval := ProposerUpdateInterval() 136 return (blockNum % proposerInterval) == 0, proposerInterval 137 } 138 139 // CalcProposerBlockNumber returns number of block where list of proposers is updated for block blockNum 140 func CalcProposerBlockNumber(blockNum uint64) uint64 { 141 var number uint64 142 if isInterval, proposerInterval := IsProposerUpdateInterval(blockNum); isInterval { 143 number = blockNum - proposerInterval 144 } else { 145 number = blockNum - (blockNum % proposerInterval) 146 } 147 return number 148 } 149 150 func SetStakingUpdateInterval(num uint64) { 151 atomic.StoreUint64(&stakingUpdateInterval, num) 152 } 153 154 func StakingUpdateInterval() uint64 { 155 ret := atomic.LoadUint64(&stakingUpdateInterval) 156 return ret 157 } 158 159 func SetProposerUpdateInterval(num uint64) { 160 atomic.StoreUint64(&proposerUpdateInterval, num) 161 } 162 163 func ProposerUpdateInterval() uint64 { 164 ret := atomic.LoadUint64(&proposerUpdateInterval) 165 return ret 166 } 167 168 func IsCheckpointInterval(blockNum uint64) bool { 169 return blockNum != 0 && blockNum%CheckpointInterval == 0 170 }