github.com/ethw3/go-ethereuma@v0.0.0-20221013053120-c14602a4c23c/eth/ethconfig/config.go (about) 1 // Copyright 2021 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/ethw3/go-ethereuma/common" 29 "github.com/ethw3/go-ethereuma/consensus" 30 "github.com/ethw3/go-ethereuma/consensus/beacon" 31 "github.com/ethw3/go-ethereuma/consensus/clique" 32 "github.com/ethw3/go-ethereuma/consensus/ethash" 33 "github.com/ethw3/go-ethereuma/core" 34 "github.com/ethw3/go-ethereuma/eth/downloader" 35 "github.com/ethw3/go-ethereuma/eth/gasprice" 36 "github.com/ethw3/go-ethereuma/ethdb" 37 "github.com/ethw3/go-ethereuma/log" 38 "github.com/ethw3/go-ethereuma/miner" 39 "github.com/ethw3/go-ethereuma/node" 40 "github.com/ethw3/go-ethereuma/params" 41 ) 42 43 // FullNodeGPO contains default gasprice oracle settings for full node. 44 var FullNodeGPO = gasprice.Config{ 45 Blocks: 20, 46 Percentile: 60, 47 MaxHeaderHistory: 1024, 48 MaxBlockHistory: 1024, 49 MaxPrice: gasprice.DefaultMaxPrice, 50 IgnorePrice: gasprice.DefaultIgnorePrice, 51 } 52 53 // LightClientGPO contains default gasprice oracle settings for light client. 54 var LightClientGPO = gasprice.Config{ 55 Blocks: 2, 56 Percentile: 60, 57 MaxHeaderHistory: 300, 58 MaxBlockHistory: 5, 59 MaxPrice: gasprice.DefaultMaxPrice, 60 IgnorePrice: gasprice.DefaultIgnorePrice, 61 } 62 63 // Defaults contains default settings for use on the Ethereum main net. 64 var Defaults = Config{ 65 SyncMode: downloader.SnapSync, 66 Ethash: ethash.Config{ 67 CacheDir: "ethash", 68 CachesInMem: 2, 69 CachesOnDisk: 3, 70 CachesLockMmap: false, 71 DatasetsInMem: 1, 72 DatasetsOnDisk: 2, 73 DatasetsLockMmap: false, 74 }, 75 NetworkId: 1, 76 TxLookupLimit: 2350000, 77 LightPeers: 100, 78 UltraLightFraction: 75, 79 DatabaseCache: 512, 80 TrieCleanCache: 154, 81 TrieCleanCacheJournal: "triecache", 82 TrieCleanCacheRejournal: 60 * time.Minute, 83 TrieDirtyCache: 256, 84 TrieTimeout: 60 * time.Minute, 85 SnapshotCache: 102, 86 FilterLogCacheSize: 32, 87 Miner: miner.Config{ 88 GasCeil: 30000000, 89 GasPrice: big.NewInt(params.GWei), 90 Recommit: 3 * time.Second, 91 }, 92 TxPool: core.DefaultTxPoolConfig, 93 RPCGasCap: 50000000, 94 RPCEVMTimeout: 5 * time.Second, 95 GPO: FullNodeGPO, 96 RPCTxFeeCap: 1, // 1 ether 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 go run github.com/fjl/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 // RequiredBlocks is a set of block number -> hash mappings which must be in the 143 // canonical chain of all remote peers. Setting the option makes geth verify the 144 // presence of these blocks for every new peer connection. 145 RequiredBlocks map[uint64]common.Hash `toml:"-"` 146 147 // Light client options 148 LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests 149 LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers 150 LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers 151 LightPeers int `toml:",omitempty"` // Maximum number of LES client peers 152 LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning 153 LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing 154 SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint 155 156 // Ultra Light client options 157 UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers 158 UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement 159 UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them 160 161 // Database options 162 SkipBcVersionCheck bool `toml:"-"` 163 DatabaseHandles int `toml:"-"` 164 DatabaseCache int 165 DatabaseFreezer string 166 167 TrieCleanCache int 168 TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts 169 TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache 170 TrieDirtyCache int 171 TrieTimeout time.Duration 172 SnapshotCache int 173 Preimages bool 174 175 // This is the number of blocks for which logs will be cached in the filter system. 176 FilterLogCacheSize int 177 178 // Mining options 179 Miner miner.Config 180 181 // Ethash options 182 Ethash ethash.Config 183 184 // Transaction pool options 185 TxPool core.TxPoolConfig 186 187 // Gas Price Oracle options 188 GPO gasprice.Config 189 190 // Enables tracking of SHA3 preimages in the VM 191 EnablePreimageRecording bool 192 193 // Miscellaneous options 194 DocRoot string `toml:"-"` 195 196 // RPCGasCap is the global gas cap for eth-call variants. 197 RPCGasCap uint64 198 199 // RPCEVMTimeout is the global timeout for eth-call. 200 RPCEVMTimeout time.Duration 201 202 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 203 // send-transaction variants. The unit is ether. 204 RPCTxFeeCap float64 205 206 // Checkpoint is a hardcoded checkpoint which can be nil. 207 Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` 208 209 // CheckpointOracle is the configuration for checkpoint oracle. 210 CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` 211 212 // OverrideTerminalTotalDifficulty (TODO: remove after the fork) 213 OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"` 214 215 // OverrideTerminalTotalDifficultyPassed (TODO: remove after the fork) 216 OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"` 217 218 //is networkid set 219 IsNetworkIdSet bool 220 } 221 222 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 223 func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { 224 // If proof-of-authority is requested, set it up 225 var engine consensus.Engine 226 if chainConfig.Clique != nil { 227 engine = clique.New(chainConfig.Clique, db) 228 } else { 229 switch config.PowMode { 230 case ethash.ModeFake: 231 log.Warn("Ethash used in fake mode") 232 case ethash.ModeTest: 233 log.Warn("Ethash used in test mode") 234 case ethash.ModeShared: 235 log.Warn("Ethash used in shared mode") 236 } 237 engine = ethash.New(ethash.Config{ 238 PowMode: config.PowMode, 239 CacheDir: stack.ResolvePath(config.CacheDir), 240 CachesInMem: config.CachesInMem, 241 CachesOnDisk: config.CachesOnDisk, 242 CachesLockMmap: config.CachesLockMmap, 243 DatasetDir: config.DatasetDir, 244 DatasetsInMem: config.DatasetsInMem, 245 DatasetsOnDisk: config.DatasetsOnDisk, 246 DatasetsLockMmap: config.DatasetsLockMmap, 247 NotifyFull: config.NotifyFull, 248 }, notify, noverify) 249 engine.(*ethash.Ethash).SetThreads(-1) // Disable CPU mining 250 } 251 return beacon.New(engine) 252 }