gitee.com/liu-zhao234568/cntest@v1.0.0/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 "gitee.com/liu-zhao234568/cntest/common" 29 "gitee.com/liu-zhao234568/cntest/consensus" 30 "gitee.com/liu-zhao234568/cntest/consensus/clique" 31 "gitee.com/liu-zhao234568/cntest/consensus/ethash" 32 "gitee.com/liu-zhao234568/cntest/core" 33 "gitee.com/liu-zhao234568/cntest/eth/downloader" 34 "gitee.com/liu-zhao234568/cntest/eth/gasprice" 35 "gitee.com/liu-zhao234568/cntest/ethdb" 36 "gitee.com/liu-zhao234568/cntest/log" 37 "gitee.com/liu-zhao234568/cntest/miner" 38 "gitee.com/liu-zhao234568/cntest/node" 39 "gitee.com/liu-zhao234568/cntest/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 GasFloor: 8000000, 87 GasCeil: 8000000, 88 GasPrice: big.NewInt(params.GWei), 89 Recommit: 3 * time.Second, 90 }, 91 TxPool: core.DefaultTxPoolConfig, 92 RPCGasCap: 50000000, 93 GPO: FullNodeGPO, 94 RPCTxFeeCap: 1, // 1 ether 95 } 96 97 func init() { 98 home := os.Getenv("HOME") 99 if home == "" { 100 if user, err := user.Current(); err == nil { 101 home = user.HomeDir 102 } 103 } 104 if runtime.GOOS == "darwin" { 105 Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") 106 } else if runtime.GOOS == "windows" { 107 localappdata := os.Getenv("LOCALAPPDATA") 108 if localappdata != "" { 109 Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") 110 } else { 111 Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") 112 } 113 } else { 114 Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash") 115 } 116 } 117 118 //go:generate gencodec -type Config -formats toml -out gen_config.go 119 120 // Config contains configuration options for of the ETH and LES protocols. 121 type Config struct { 122 // The genesis block, which is inserted if the database is empty. 123 // If nil, the Ethereum main net block is used. 124 Genesis *core.Genesis `toml:",omitempty"` 125 126 // Protocol options 127 NetworkId uint64 // Network ID to use for selecting peers to connect to 128 SyncMode downloader.SyncMode 129 130 // This can be set to list of enrtree:// URLs which will be queried for 131 // for nodes to connect to. 132 EthDiscoveryURLs []string 133 SnapDiscoveryURLs []string 134 135 NoPruning bool // Whether to disable pruning and flush everything to disk 136 NoPrefetch bool // Whether to disable prefetching and only load state on demand 137 138 TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. 139 140 // Whitelist of required block number -> hash values to accept 141 Whitelist 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 // Mining options 172 Miner miner.Config 173 174 // Ethash options 175 Ethash ethash.Config 176 177 // Transaction pool options 178 TxPool core.TxPoolConfig 179 180 // Gas Price Oracle options 181 GPO gasprice.Config 182 183 // Enables tracking of SHA3 preimages in the VM 184 EnablePreimageRecording bool 185 186 // Miscellaneous options 187 DocRoot string `toml:"-"` 188 189 // RPCGasCap is the global gas cap for eth-call variants. 190 RPCGasCap uint64 191 192 // RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for 193 // send-transction variants. The unit is ether. 194 RPCTxFeeCap float64 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 // Berlin block override (TODO: remove after the fork) 203 OverrideLondon *big.Int `toml:",omitempty"` 204 } 205 206 // CreateConsensusEngine creates a consensus engine for the given chain configuration. 207 func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine { 208 // If proof-of-authority is requested, set it up 209 if chainConfig.Clique != nil { 210 return clique.New(chainConfig.Clique, db) 211 } 212 // Otherwise assume proof-of-work 213 switch config.PowMode { 214 case ethash.ModeFake: 215 log.Warn("Ethash used in fake mode") 216 case ethash.ModeTest: 217 log.Warn("Ethash used in test mode") 218 case ethash.ModeShared: 219 log.Warn("Ethash used in shared mode") 220 } 221 engine := ethash.New(ethash.Config{ 222 PowMode: config.PowMode, 223 CacheDir: stack.ResolvePath(config.CacheDir), 224 CachesInMem: config.CachesInMem, 225 CachesOnDisk: config.CachesOnDisk, 226 CachesLockMmap: config.CachesLockMmap, 227 DatasetDir: config.DatasetDir, 228 DatasetsInMem: config.DatasetsInMem, 229 DatasetsOnDisk: config.DatasetsOnDisk, 230 DatasetsLockMmap: config.DatasetsLockMmap, 231 NotifyFull: config.NotifyFull, 232 }, notify, noverify) 233 engine.SetThreads(-1) // Disable CPU mining 234 return engine 235 }