github.com/tacshi/go-ethereum@v0.0.0-20230616113857-84a434e20921/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 "os" 22 "os/user" 23 "path/filepath" 24 "runtime" 25 "time" 26 27 "github.com/tacshi/go-ethereum/common" 28 "github.com/tacshi/go-ethereum/consensus" 29 "github.com/tacshi/go-ethereum/consensus/beacon" 30 "github.com/tacshi/go-ethereum/consensus/clique" 31 "github.com/tacshi/go-ethereum/consensus/ethash" 32 "github.com/tacshi/go-ethereum/core" 33 "github.com/tacshi/go-ethereum/core/txpool" 34 "github.com/tacshi/go-ethereum/eth/downloader" 35 "github.com/tacshi/go-ethereum/eth/gasprice" 36 "github.com/tacshi/go-ethereum/ethdb" 37 "github.com/tacshi/go-ethereum/log" 38 "github.com/tacshi/go-ethereum/miner" 39 "github.com/tacshi/go-ethereum/node" 40 "github.com/tacshi/go-ethereum/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.DefaultConfig, 88 TxPool: txpool.DefaultConfig, 89 RPCGasCap: 50000000, 90 RPCEVMTimeout: 5 * time.Second, 91 GPO: FullNodeGPO, 92 RPCTxFeeCap: 1, // 1 ether 93 } 94 95 func init() { 96 home := os.Getenv("HOME") 97 if home == "" { 98 if user, err := user.Current(); err == nil { 99 home = user.HomeDir 100 } 101 } 102 if runtime.GOOS == "darwin" { 103 Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") 104 } else if runtime.GOOS == "windows" { 105 localappdata := os.Getenv("LOCALAPPDATA") 106 if localappdata != "" { 107 Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") 108 } else { 109 Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") 110 } 111 } else { 112 Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash") 113 } 114 } 115 116 //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go 117 118 // Config contains configuration options for of the ETH and LES protocols. 119 type Config struct { 120 // The genesis block, which is inserted if the database is empty. 121 // If nil, the Ethereum main net block is used. 122 Genesis *core.Genesis `toml:",omitempty"` 123 124 // Protocol options 125 NetworkId uint64 // Network ID to use for selecting peers to connect to 126 SyncMode downloader.SyncMode 127 128 // This can be set to list of enrtree:// URLs which will be queried for 129 // for nodes to connect to. 130 EthDiscoveryURLs []string 131 SnapDiscoveryURLs []string 132 133 NoPruning bool // Whether to disable pruning and flush everything to disk 134 NoPrefetch bool // Whether to disable prefetching and only load state on demand 135 136 TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. 137 138 // RequiredBlocks is a set of block number -> hash mappings which must be in the 139 // canonical chain of all remote peers. Setting the option makes geth verify the 140 // presence of these blocks for every new peer connection. 141 RequiredBlocks map[uint64]common.Hash `toml:"-"` 142 143 // Light client options 144 LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests 145 LightIngress int `toml:",omitempty"` // Incoming bandwidth limit for light servers 146 LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers 147 LightPeers int `toml:",omitempty"` // Maximum number of LES client peers 148 LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning 149 LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing 150 SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint 151 152 // Ultra Light client options 153 UltraLightServers []string `toml:",omitempty"` // List of trusted ultra light servers 154 UltraLightFraction int `toml:",omitempty"` // Percentage of trusted servers to accept an announcement 155 UltraLightOnlyAnnounce bool `toml:",omitempty"` // Whether to only announce headers, or also serve them 156 157 // Database options 158 SkipBcVersionCheck bool `toml:"-"` 159 DatabaseHandles int `toml:"-"` 160 DatabaseCache int 161 DatabaseFreezer string 162 163 TrieCleanCache int 164 TrieCleanCacheJournal string `toml:",omitempty"` // Disk journal directory for trie cache to survive node restarts 165 TrieCleanCacheRejournal time.Duration `toml:",omitempty"` // Time interval to regenerate the journal for clean cache 166 TrieDirtyCache int 167 TrieTimeout time.Duration 168 SnapshotCache int 169 Preimages bool 170 171 // This is the number of blocks for which logs will be cached in the filter system. 172 FilterLogCacheSize int 173 174 // Mining options 175 Miner miner.Config 176 177 // Ethash options 178 Ethash ethash.Config 179 180 // Transaction pool options 181 TxPool txpool.Config 182 183 // Gas Price Oracle options 184 GPO gasprice.Config 185 186 // Enables tracking of SHA3 preimages in the VM 187 EnablePreimageRecording bool 188 189 // Miscellaneous options 190 DocRoot string `toml:"-"` 191 192 // RPCGasCap is the global gas cap for eth-call variants. 193 RPCGasCap uint64 194 195 // RPCEVMTimeout is the global timeout for eth-call. 196 RPCEVMTimeout time.Duration 197 198 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 199 // send-transaction variants. The unit is ether. 200 RPCTxFeeCap float64 201 202 // Checkpoint is a hardcoded checkpoint which can be nil. 203 Checkpoint *params.TrustedCheckpoint `toml:",omitempty"` 204 205 // CheckpointOracle is the configuration for checkpoint oracle. 206 CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` 207 208 // OverrideShanghai (TODO: remove after the fork) 209 OverrideShanghai *uint64 `toml:",omitempty"` 210 } 211 212 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 213 func CreateConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine { 214 // If proof-of-authority is requested, set it up 215 var engine consensus.Engine 216 if cliqueConfig != nil { 217 engine = clique.New(cliqueConfig, db) 218 } else { 219 switch ethashConfig.PowMode { 220 case ethash.ModeFake: 221 log.Warn("Ethash used in fake mode") 222 case ethash.ModeTest: 223 log.Warn("Ethash used in test mode") 224 case ethash.ModeShared: 225 log.Warn("Ethash used in shared mode") 226 } 227 engine = ethash.New(ethash.Config{ 228 PowMode: ethashConfig.PowMode, 229 CacheDir: stack.ResolvePath(ethashConfig.CacheDir), 230 CachesInMem: ethashConfig.CachesInMem, 231 CachesOnDisk: ethashConfig.CachesOnDisk, 232 CachesLockMmap: ethashConfig.CachesLockMmap, 233 DatasetDir: ethashConfig.DatasetDir, 234 DatasetsInMem: ethashConfig.DatasetsInMem, 235 DatasetsOnDisk: ethashConfig.DatasetsOnDisk, 236 DatasetsLockMmap: ethashConfig.DatasetsLockMmap, 237 NotifyFull: ethashConfig.NotifyFull, 238 }, notify, noverify) 239 engine.(*ethash.Ethash).SetThreads(-1) // Disable CPU mining 240 } 241 return beacon.New(engine) 242 }