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