github.com/Unheilbar/quorum@v1.0.0/eth/ethconfig/config.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package ethconfig contains the configuration of the ETH and LES protocols. 18 package ethconfig 19 20 import ( 21 "math/big" 22 "os" 23 "os/user" 24 "path/filepath" 25 "runtime" 26 "strings" 27 "time" 28 29 "github.com/ethereum/go-ethereum/common" 30 "github.com/ethereum/go-ethereum/consensus" 31 "github.com/ethereum/go-ethereum/consensus/clique" 32 "github.com/ethereum/go-ethereum/consensus/ethash" 33 "github.com/ethereum/go-ethereum/consensus/istanbul" 34 istanbulBackend "github.com/ethereum/go-ethereum/consensus/istanbul/backend" 35 "github.com/ethereum/go-ethereum/core" 36 "github.com/ethereum/go-ethereum/eth/downloader" 37 "github.com/ethereum/go-ethereum/eth/gasprice" 38 "github.com/ethereum/go-ethereum/ethdb" 39 "github.com/ethereum/go-ethereum/log" 40 "github.com/ethereum/go-ethereum/miner" 41 "github.com/ethereum/go-ethereum/node" 42 "github.com/ethereum/go-ethereum/params" 43 ) 44 45 // FullNodeGPO contains default gasprice oracle settings for full node. 46 var FullNodeGPO = gasprice.Config{ 47 Blocks: 20, 48 Percentile: 60, 49 MaxPrice: gasprice.DefaultMaxPrice, 50 } 51 52 // LightClientGPO contains default gasprice oracle settings for light client. 53 var LightClientGPO = gasprice.Config{ 54 Blocks: 2, 55 Percentile: 60, 56 MaxPrice: gasprice.DefaultMaxPrice, 57 } 58 59 // Defaults contains default settings for use on the Ethereum main net. 60 var Defaults = Config{ 61 // Quorum - make full sync the default sync mode in quorum (as opposed to upstream geth) 62 SyncMode: downloader.FullSync, 63 // End Quorum 64 Ethash: ethash.Config{ 65 CacheDir: "ethash", 66 CachesInMem: 2, 67 CachesOnDisk: 3, 68 CachesLockMmap: false, 69 DatasetsInMem: 1, 70 DatasetsOnDisk: 2, 71 DatasetsLockMmap: false, 72 }, 73 NetworkId: 1337, 74 TxLookupLimit: 2350000, 75 LightPeers: 100, 76 UltraLightFraction: 75, 77 DatabaseCache: 768, 78 TrieCleanCache: 154, 79 TrieCleanCacheJournal: "triecache", 80 TrieCleanCacheRejournal: 60 * time.Minute, 81 TrieDirtyCache: 256, 82 TrieTimeout: 60 * time.Minute, 83 SnapshotCache: 102, 84 Miner: miner.Config{ 85 GasFloor: params.DefaultMinGasLimit, 86 GasCeil: params.GenesisGasLimit, 87 GasPrice: big.NewInt(params.GWei), 88 Recommit: 3 * time.Second, 89 }, 90 TxPool: core.DefaultTxPoolConfig, 91 RPCGasCap: 25000000, 92 GPO: FullNodeGPO, 93 RPCTxFeeCap: 1, // 1 ether 94 95 // Quorum 96 Istanbul: *istanbul.DefaultConfig, // Quorum 97 } 98 99 func init() { 100 home := os.Getenv("HOME") 101 if home == "" { 102 if user, err := user.Current(); err == nil { 103 home = user.HomeDir 104 } 105 } 106 if runtime.GOOS == "darwin" { 107 Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") 108 } else if runtime.GOOS == "windows" { 109 localappdata := os.Getenv("LOCALAPPDATA") 110 if localappdata != "" { 111 Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") 112 } else { 113 Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") 114 } 115 } else { 116 Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash") 117 } 118 } 119 120 //go:generate gencodec -type Config -formats toml -out gen_config.go 121 122 // Config contains configuration options for of the ETH and LES protocols. 123 type Config struct { 124 // The genesis block, which is inserted if the database is empty. 125 // If nil, the Ethereum main net block is used. 126 Genesis *core.Genesis `toml:",omitempty"` 127 128 // Protocol options 129 NetworkId uint64 // Network ID to use for selecting peers to connect to 130 SyncMode downloader.SyncMode 131 132 // This can be set to list of enrtree:// URLs which will be queried for 133 // for nodes to connect to. 134 EthDiscoveryURLs []string 135 SnapDiscoveryURLs []string 136 137 NoPruning bool // Whether to disable pruning and flush everything to disk 138 NoPrefetch bool // Whether to disable prefetching and only load state on demand 139 140 TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. 141 142 // AuthorizationList of required block number -> hash values to accept 143 AuthorizationList map[uint64]common.Hash `toml:"-"` // not in the TOML configuration 144 145 // Light client options 146 LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests 147 LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers 148 LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers 149 LightPeers int `toml:",omitempty"` // Maximum number of LES client peers 150 LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning 151 LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing 152 SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint 153 154 // Ultra Light client options 155 UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers 156 UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement 157 UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them 158 159 // Database options 160 SkipBcVersionCheck bool `toml:"-"` 161 DatabaseHandles int `toml:"-"` 162 DatabaseCache int 163 DatabaseFreezer string 164 165 TrieCleanCache int 166 TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts 167 TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache 168 TrieDirtyCache int 169 TrieTimeout time.Duration `toml:",omitempty"` // Cumulative Time interval spent on gc, after which to flush trie cache to disk 170 SnapshotCache int 171 Preimages bool 172 173 // Mining options 174 Miner miner.Config 175 176 // Ethash options 177 Ethash ethash.Config 178 179 // Transaction pool options 180 TxPool core.TxPoolConfig 181 182 // Gas Price Oracle options 183 GPO gasprice.Config 184 185 // Enables tracking of SHA3 preimages in the VM 186 EnablePreimageRecording bool 187 188 // Miscellaneous options 189 DocRoot string `toml:"-"` 190 191 // Type of the EWASM interpreter ("" for default) 192 EWASMInterpreter string 193 194 // Type of the EVM interpreter ("" for default) 195 EVMInterpreter string 196 197 // RPCGasCap is the global gas cap for eth-call variants. 198 RPCGasCap uint64 199 200 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 201 // send-transction variants. The unit is ether. 202 RPCTxFeeCap float64 203 204 // Checkpoint is a hardcoded checkpoint which can be nil. 205 Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` 206 207 // CheckpointOracle is the configuration for checkpoint oracle. 208 CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` 209 210 // Berlin block override (TODO: remove after the fork) 211 OverrideBerlin *big.Int `toml:",omitempty"` 212 213 // Quorum 214 215 RaftMode bool 216 EnableNodePermission bool 217 // Istanbul options 218 Istanbul istanbul.Config 219 220 // timeout value for call 221 EVMCallTimeOut time.Duration 222 223 // Quorum 224 core.QuorumChainConfig `toml:"-"` 225 226 // QuorumLight 227 QuorumLightServer bool `toml:",omitempty"` 228 QuorumLightClient *QuorumLightClient `toml:",omitempty"` 229 } 230 231 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 232 func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { 233 // If proof-of-authority is requested, set it up 234 if chainConfig.Clique != nil { 235 chainConfig.Clique.AllowedFutureBlockTime = config.Miner.AllowedFutureBlockTime //Quorum 236 return clique.New(chainConfig.Clique, db) 237 } 238 if len(chainConfig.Transitions) > 0 { 239 config.Istanbul.Transitions = chainConfig.Transitions 240 } 241 // If Istanbul is requested, set it up 242 if chainConfig.Istanbul != nil { 243 log.Warn("WARNING: The attribute config.istanbul is deprecated and will be removed in the future, please use config.ibft on genesis file") 244 if chainConfig.Istanbul.Epoch != 0 { 245 config.Istanbul.Epoch = chainConfig.Istanbul.Epoch 246 } 247 config.Istanbul.ProposerPolicy = istanbul.NewProposerPolicy(istanbul.ProposerPolicyId(chainConfig.Istanbul.ProposerPolicy)) 248 config.Istanbul.Ceil2Nby3Block = chainConfig.Istanbul.Ceil2Nby3Block 249 config.Istanbul.AllowedFutureBlockTime = config.Miner.AllowedFutureBlockTime //Quorum 250 config.Istanbul.TestQBFTBlock = chainConfig.Istanbul.TestQBFTBlock 251 return istanbulBackend.New(&config.Istanbul, stack.GetNodeKey(), db) 252 } 253 if chainConfig.IBFT == nil && len(chainConfig.Transitions) > 0 { 254 chainConfig.GetTransitionValue(big.NewInt(0), func(t params.Transition) { 255 if strings.EqualFold(t.Algorithm, params.IBFT) { 256 chainConfig.IBFT = ¶ms.IBFTConfig{ 257 BFTConfig: ¶ms.BFTConfig{ 258 EpochLength: t.EpochLength, 259 BlockPeriodSeconds: t.BlockPeriodSeconds, 260 EmptyBlockPeriodSeconds: t.EmptyBlockPeriodSeconds, 261 ValidatorContractAddress: t.ValidatorContractAddress, 262 RequestTimeoutSeconds: t.RequestTimeoutSeconds, 263 }, 264 } 265 log.Info("new chain config with", "ibft", *chainConfig.IBFT) 266 } 267 }) 268 } 269 if chainConfig.IBFT != nil { 270 setBFTConfig(&config.Istanbul, chainConfig.IBFT.BFTConfig) 271 config.Istanbul.TestQBFTBlock = nil 272 if chainConfig.IBFT.ValidatorContractAddress != (common.Address{}) { 273 config.Istanbul.ValidatorContract = chainConfig.IBFT.ValidatorContractAddress 274 } 275 return istanbulBackend.New(&config.Istanbul, stack.GetNodeKey(), db) 276 } 277 if chainConfig.QBFT == nil && len(chainConfig.Transitions) > 0 { 278 chainConfig.GetTransitionValue(big.NewInt(0), func(t params.Transition) { 279 if strings.EqualFold(t.Algorithm, params.QBFT) { 280 chainConfig.QBFT = ¶ms.QBFTConfig{ 281 BFTConfig: ¶ms.BFTConfig{ 282 EpochLength: t.EpochLength, 283 BlockPeriodSeconds: t.BlockPeriodSeconds, 284 EmptyBlockPeriodSeconds: t.EmptyBlockPeriodSeconds, 285 ValidatorContractAddress: t.ValidatorContractAddress, 286 RequestTimeoutSeconds: t.RequestTimeoutSeconds, 287 }, 288 } 289 log.Info("new chain config with", "qbft", *chainConfig.QBFT) 290 } 291 }) 292 } 293 if chainConfig.QBFT != nil { 294 setBFTConfig(&config.Istanbul, chainConfig.QBFT.BFTConfig) 295 config.Istanbul.TestQBFTBlock = big.NewInt(0) 296 if chainConfig.QBFT.ValidatorContractAddress != (common.Address{}) { 297 config.Istanbul.ValidatorContract = chainConfig.QBFT.ValidatorContractAddress 298 } 299 config.Istanbul.BlockReward = chainConfig.QBFT.BlockReward 300 config.Istanbul.BeneficiaryMode = chainConfig.QBFT.BeneficiaryMode 301 config.Istanbul.MiningBeneficiary = chainConfig.QBFT.MiningBeneficiary 302 config.Istanbul.ValidatorSelectionMode = chainConfig.QBFT.ValidatorSelectionMode 303 config.Istanbul.Validators = chainConfig.QBFT.Validators 304 305 if chainConfig.QBFT.MaxRequestTimeoutSeconds != nil && *chainConfig.QBFT.MaxRequestTimeoutSeconds > 0 { 306 config.Istanbul.MaxRequestTimeoutSeconds = *chainConfig.QBFT.MaxRequestTimeoutSeconds 307 } 308 309 return istanbulBackend.New(&config.Istanbul, stack.GetNodeKey(), db) 310 } 311 // For Quorum, Raft run as a separate service, so 312 // the Ethereum service still needs a consensus engine, 313 // use the consensus with the lightest overhead 314 engine := ethash.NewFullFaker() 315 engine.SetThreads(-1) // Disable CPU Mining 316 return engine 317 } 318 319 // Quorum 320 321 type QuorumLightClient struct { 322 Use bool `toml:",omitempty"` 323 PSI string `toml:",omitempty"` 324 TokenEnabled bool `toml:",omitempty"` 325 TokenValue string `toml:",omitempty"` 326 TokenManagement string `toml:",omitempty"` 327 RPCTLS bool `toml:",omitempty"` 328 RPCTLSInsecureSkipVerify bool `toml:",omitempty"` 329 RPCTLSCACert string `toml:",omitempty"` 330 RPCTLSCert string `toml:",omitempty"` 331 RPCTLSKey string `toml:",omitempty"` 332 ServerNode string `toml:",omitempty"` 333 ServerNodeRPC string `toml:",omitempty"` 334 } 335 336 func (q *QuorumLightClient) Enabled() bool { 337 return q != nil && q.Use 338 } 339 340 func setBFTConfig(istanbulConfig *istanbul.Config, bftConfig *params.BFTConfig) { 341 if bftConfig.BlockPeriodSeconds != 0 { 342 istanbulConfig.BlockPeriod = bftConfig.BlockPeriodSeconds 343 } 344 if bftConfig.EmptyBlockPeriodSeconds != nil { 345 istanbulConfig.EmptyBlockPeriod = *bftConfig.EmptyBlockPeriodSeconds 346 } 347 if bftConfig.RequestTimeoutSeconds != 0 { 348 istanbulConfig.RequestTimeout = bftConfig.RequestTimeoutSeconds * 1000 349 } 350 if bftConfig.EpochLength != 0 { 351 istanbulConfig.Epoch = bftConfig.EpochLength 352 } 353 if bftConfig.ProposerPolicy != 0 { 354 istanbulConfig.ProposerPolicy = istanbul.NewProposerPolicy(istanbul.ProposerPolicyId(bftConfig.ProposerPolicy)) 355 } 356 if bftConfig.Ceil2Nby3Block != nil { 357 istanbulConfig.Ceil2Nby3Block = bftConfig.Ceil2Nby3Block 358 } 359 }