github.com/juliankolbe/go-ethereum@v1.9.992/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 "time" 27 28 "github.com/juliankolbe/go-ethereum/common" 29 "github.com/juliankolbe/go-ethereum/consensus" 30 "github.com/juliankolbe/go-ethereum/consensus/clique" 31 "github.com/juliankolbe/go-ethereum/consensus/ethash" 32 "github.com/juliankolbe/go-ethereum/core" 33 "github.com/juliankolbe/go-ethereum/eth/downloader" 34 "github.com/juliankolbe/go-ethereum/eth/gasprice" 35 "github.com/juliankolbe/go-ethereum/ethdb" 36 "github.com/juliankolbe/go-ethereum/log" 37 "github.com/juliankolbe/go-ethereum/miner" 38 "github.com/juliankolbe/go-ethereum/node" 39 "github.com/juliankolbe/go-ethereum/params" 40 ) 41 42 // FullNodeGPO contains default gasprice oracle settings for full node. 43 var FullNodeGPO = gasprice.Config{ 44 Blocks: 20, 45 Percentile: 60, 46 MaxPrice: gasprice.DefaultMaxPrice, 47 } 48 49 // LightClientGPO contains default gasprice oracle settings for light client. 50 var LightClientGPO = gasprice.Config{ 51 Blocks: 2, 52 Percentile: 60, 53 MaxPrice: gasprice.DefaultMaxPrice, 54 } 55 56 // Defaults contains default settings for use on the Ethereum main net. 57 var Defaults = Config{ 58 SyncMode: downloader.FastSync, 59 Ethash: ethash.Config{ 60 CacheDir: "ethash", 61 CachesInMem: 2, 62 CachesOnDisk: 3, 63 CachesLockMmap: false, 64 DatasetsInMem: 1, 65 DatasetsOnDisk: 2, 66 DatasetsLockMmap: false, 67 }, 68 NetworkId: 1, 69 TxLookupLimit: 2350000, 70 LightPeers: 100, 71 UltraLightFraction: 75, 72 DatabaseCache: 512, 73 TrieCleanCache: 154, 74 TrieCleanCacheJournal: "triecache", 75 TrieCleanCacheRejournal: 60 * time.Minute, 76 TrieDirtyCache: 256, 77 TrieTimeout: 60 * time.Minute, 78 SnapshotCache: 102, 79 Miner: miner.Config{ 80 GasFloor: 8000000, 81 GasCeil: 8000000, 82 GasPrice: big.NewInt(params.GWei), 83 Recommit: 3 * time.Second, 84 }, 85 TxPool: core.DefaultTxPoolConfig, 86 RPCGasCap: 25000000, 87 GPO: FullNodeGPO, 88 RPCTxFeeCap: 1, // 1 ether 89 } 90 91 func init() { 92 home := os.Getenv("HOME") 93 if home == "" { 94 if user, err := user.Current(); err == nil { 95 home = user.HomeDir 96 } 97 } 98 if runtime.GOOS == "darwin" { 99 Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") 100 } else if runtime.GOOS == "windows" { 101 localappdata := os.Getenv("LOCALAPPDATA") 102 if localappdata != "" { 103 Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") 104 } else { 105 Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") 106 } 107 } else { 108 Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash") 109 } 110 } 111 112 //go:generate gencodec -type Config -formats toml -out gen_config.go 113 114 // Config contains configuration options for of the ETH and LES protocols. 115 type Config struct { 116 // The genesis block, which is inserted if the database is empty. 117 // If nil, the Ethereum main net block is used. 118 Genesis *core.Genesis `toml:",omitempty"` 119 120 // Protocol options 121 NetworkId uint64 // Network ID to use for selecting peers to connect to 122 SyncMode downloader.SyncMode 123 124 // This can be set to list of enrtree:// URLs which will be queried for 125 // for nodes to connect to. 126 EthDiscoveryURLs []string 127 SnapDiscoveryURLs []string 128 129 NoPruning bool // Whether to disable pruning and flush everything to disk 130 NoPrefetch bool // Whether to disable prefetching and only load state on demand 131 132 TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. 133 134 // Whitelist of required block number -> hash values to accept 135 Whitelist map[uint64]common.Hash `toml:"-"` 136 137 // Light client options 138 LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests 139 LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers 140 LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers 141 LightPeers int `toml:",omitempty"` // Maximum number of LES client peers 142 LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning 143 LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing 144 SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint 145 146 // Ultra Light client options 147 UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers 148 UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement 149 UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them 150 151 // Database options 152 SkipBcVersionCheck bool `toml:"-"` 153 DatabaseHandles int `toml:"-"` 154 DatabaseCache int 155 DatabaseFreezer string 156 157 TrieCleanCache int 158 TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts 159 TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache 160 TrieDirtyCache int 161 TrieTimeout time.Duration 162 SnapshotCache int 163 Preimages bool 164 165 // Mining options 166 Miner miner.Config 167 168 // Ethash options 169 Ethash ethash.Config 170 171 // Transaction pool options 172 TxPool core.TxPoolConfig 173 174 // Gas Price Oracle options 175 GPO gasprice.Config 176 177 // Enables tracking of SHA3 preimages in the VM 178 EnablePreimageRecording bool 179 180 // Miscellaneous options 181 DocRoot string `toml:"-"` 182 183 // Type of the EWASM interpreter ("" for default) 184 EWASMInterpreter string 185 186 // Type of the EVM interpreter ("" for default) 187 EVMInterpreter string 188 189 // RPCGasCap is the global gas cap for eth-call variants. 190 RPCGasCap uint64 `toml:",omitempty"` 191 192 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 193 // send-transction variants. The unit is ether. 194 RPCTxFeeCap float64 `toml:",omitempty"` 195 196 // Checkpoint is a hardcoded checkpoint which can be nil. 197 Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` 198 199 // CheckpointOracle is the configuration for checkpoint oracle. 200 CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` 201 } 202 203 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 204 func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { 205 // If proof-of-authority is requested, set it up 206 if chainConfig.Clique != nil { 207 return clique.New(chainConfig.Clique, db) 208 } 209 // Otherwise assume proof-of-work 210 switch config.PowMode { 211 case ethash.ModeFake: 212 log.Warn("Ethash used in fake mode") 213 return ethash.NewFaker() 214 case ethash.ModeTest: 215 log.Warn("Ethash used in test mode") 216 return ethash.NewTester(nil, noverify) 217 case ethash.ModeShared: 218 log.Warn("Ethash used in shared mode") 219 return ethash.NewShared() 220 default: 221 engine := ethash.New(ethash.Config{ 222 CacheDir: stack.ResolvePath(config.CacheDir), 223 CachesInMem: config.CachesInMem, 224 CachesOnDisk: config.CachesOnDisk, 225 CachesLockMmap: config.CachesLockMmap, 226 DatasetDir: config.DatasetDir, 227 DatasetsInMem: config.DatasetsInMem, 228 DatasetsOnDisk: config.DatasetsOnDisk, 229 DatasetsLockMmap: config.DatasetsLockMmap, 230 }, notify, noverify) 231 engine.SetThreads(-1) // Disable CPU mining 232 return engine 233 } 234 }