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